Implemented some amount of masking

The main list and properites window now show when a flatpak is masked and the properties window offers to unmask it
This commit is contained in:
heliguy
2023-10-20 00:42:03 -04:00
parent 3c701806ba
commit 66700a1137
4 changed files with 55 additions and 4 deletions

View File

@@ -125,6 +125,27 @@ class myUtils:
sorted_array = sorted(data, key=lambda item: item[0].lower())
return sorted_array
def getHostMasks(self, user_or_system):
output = subprocess.run(["flatpak-spawn", "--host", "flatpak", "mask", f"--{user_or_system}"], capture_output=True, text=True, env=self.new_env).stdout
lines = output.strip().split("\n")
for i in range(len(lines)):
lines[i] = lines[i].strip()
return(lines)
def maskFlatpak(self, app_id, user_or_system, remove=False):
command = ["flatpak-spawn", "--host", "flatpak", "mask", f"--{user_or_system}", app_id]
if remove:
command.append("--remove")
response = ""
try:
response = subprocess.run(command, capture_output=True, text=True, env=self.new_env)
except subprocess.CalledProcessError as e:
print(f"Error setting mask for {app_id}:\n", e)
return(1)
if len(response.stderr) > 0:
return(1)
return(0)
def uninstallFlatpak(self, ref_arr, type_arr, should_trash):
self.uninstall_success = True

View File

@@ -63,7 +63,7 @@ class DowngradeWindow(Adw.Window):
self.should_pulse = False
for i in range(len(self.versions)):
version = self.versions[i]
row = Adw.ActionRow(title=version[2], subtitle=version[1])
row = Adw.ActionRow(title=version[2], subtitle=GLib.markup_escape_text(version[1]))
select = Gtk.CheckButton()
select.connect("toggled", self.selectionHandler, i)
@@ -79,6 +79,11 @@ class DowngradeWindow(Adw.Window):
task = Gio.Task.new(None, None, lambda *_: self.commitsResponse())
task.run_in_thread(lambda *_: self.getCommits())
def onApply(self):
if self.mask_row.get_active():
self.my_utils.maskFlatpak(self.app_id, self.install_type)
self.close()
def __init__(self, parent_window, flatpak_row_item, **kwargs):
super().__init__(**kwargs)
@@ -97,6 +102,7 @@ class DowngradeWindow(Adw.Window):
# Connections
event_controller.connect("key-pressed", self.key_handler)
self.cancel_button.connect("clicked", lambda *_: self.close())
self.apply_button.connect("clicked", lambda *_: self.onApply())
# Apply
self.pulser()

View File

@@ -18,8 +18,10 @@ def show_properties_window(widget, index, window):
properties_clamp = Adw.Clamp()
eol_app_banner = Adw.Banner(title=_("This Flatpak has reached its End of Life and will not receive any security updates"))
eol_runtime_banner = Adw.Banner(title=_("The runtime used by this app has reached its End of Life and will not receive any security updates"))
mask_banner = Adw.Banner(title=_("This Flatpak has been masked and will not be updated"))
outer_box.append(eol_app_banner)
outer_box.append(eol_runtime_banner)
outer_box.append(mask_banner)
outer_box.append(properties_scroll)
properties_scroll.set_child(properties_clamp)
properties_clamp.set_child(properties_box)
@@ -34,6 +36,9 @@ def show_properties_window(widget, index, window):
my_utils = myUtils(window)
system_mask_list = my_utils.getHostMasks("system")
user_mask_list = my_utils.getHostMasks("user")
def viewAppsHandler(button):
window.should_open_filter_window = False
window.filter_button.set_active(True)
@@ -59,6 +64,7 @@ def show_properties_window(widget, index, window):
app_name = window.host_flatpaks[index][0]
app_id = window.host_flatpaks[index][2]
install_type = window.host_flatpaks[index][7]
data_folder = window.user_data_path + app_id
def on_response(_a, response_id, _b):
@@ -166,5 +172,16 @@ def show_properties_window(widget, index, window):
if "eol" in window.host_flatpaks[index][12]:
eol_app_banner.set_revealed(True)
def maskHandler():
x = my_utils.maskFlatpak(app_id, install_type, True)
if x == 0:
mask_banner.set_revealed(False)
window.flatpak_rows[index][7].set_visible(False) # Sets the mask label invisble
if app_id in system_mask_list or app_id in user_mask_list:
mask_banner.set_revealed(True)
mask_banner.set_button_label(_("Unmask"))
mask_banner.connect("button-clicked", lambda *_: maskHandler())
properties_window.set_content(properties_title_bar)
properties_window.present()

View File

@@ -68,7 +68,7 @@ class WarehouseWindow(Adw.ApplicationWindow):
currently_uninstalling = False
selected_rows = []
flatpak_rows = []
# ^ {Row visibility, Row selected, the row itself, properties, row menu, select, the flatpak row from `flatpak list`}
# ^ {Row visibility, Row selected, the row itself, properties, row menu, select, the flatpak row from `flatpak list`, mask label}
def mainPulser(self):
if self.should_pulse:
@@ -280,6 +280,8 @@ class WarehouseWindow(Adw.ApplicationWindow):
self.main_stack.set_visible_child(self.main_box)
self.batch_select_all_button.set_active(False)
self.eol_list = []
self.system_mask_list = self.my_utils.getHostMasks("system")
self.user_mask_list = self.my_utils.getHostMasks("user")
for index in range(len(self.host_flatpaks)):
if "eol" in self.host_flatpaks[index][12]:
@@ -296,13 +298,18 @@ class WarehouseWindow(Adw.ApplicationWindow):
if "eol" in self.host_flatpaks[index][12]:
eol_app_label = Gtk.Label(label=_("EOL"), valign=Gtk.Align.CENTER, tooltip_text=_("This Flatpak has reached its End of Life and will not receive any security updates"))
eol_app_label.add_css_class("error")
flatpak_row.add_suffix(eol_app_label)
if self.host_flatpaks[index][13] in self.eol_list:
eol_runtime_label = Gtk.Label(label=_("EOL"), valign=Gtk.Align.CENTER, tooltip_text=_("The runtime used by this app has reached its End of Life and will not receive any security updates"))
eol_runtime_label.add_css_class("error")
flatpak_row.add_suffix(eol_runtime_label)
mask_label = Gtk.Label(label=_("Masked"), valign=Gtk.Align.CENTER, tooltip_text=_("This Flatpak is masked and will not be updated"))
# ^ This is up here as we need to add this to flatpak_rows regardless of if its visible or not
if app_id in self.system_mask_list or app_id in self.user_mask_list:
mask_label.set_visible(True)
flatpak_row.add_suffix(mask_label)
properties_button = Gtk.Button(icon_name="info-symbolic", valign=Gtk.Align.CENTER, tooltip_text=_("View Properties"))
properties_button.add_css_class("flat")
properties_button.connect("clicked", show_properties_window, index, self)
@@ -369,7 +376,7 @@ class WarehouseWindow(Adw.ApplicationWindow):
self.flatpaks_list_box.append(flatpak_row)
# {Row visibility, Row selected, the row itself, properties, menu button, select, the flatpak row from `flatpak list`}
self.flatpak_rows.append([True, False, flatpak_row, properties_button, row_menu, select_flatpak_tickbox, self.host_flatpaks[index]])
self.flatpak_rows.append([True, False, flatpak_row, properties_button, row_menu, select_flatpak_tickbox, self.host_flatpaks[index], mask_label])
self.windowSetEmpty(not self.flatpaks_list_box.get_row_at_index(0))
self.applyFilter(self.filter_list)