Skip to content

Commit

Permalink
Adding new remotes now happens in a thread
Browse files Browse the repository at this point in the history
  • Loading branch information
heliguy4599 committed Oct 4, 2023
1 parent a0cecb7 commit 6e7ee32
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/orphans_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ def generateList(self):

# Create row element
dir_row = Adw.ActionRow(title=dir_name)
task = Gio.Task.new(None, None, None)
path = self.user_data_path + dir_name
task = Gio.Task.new(None, None, None)
task.run_in_thread(lambda _task, _obj, _data, _cancellable: self.sizeThread(dir_row, path))

select_button = Gtk.CheckButton()
Expand Down
18 changes: 12 additions & 6 deletions src/popular_remotes_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ def key_handler(self, _a, event, _c, _d):
if event == Gdk.KEY_Escape:
self.close()

def addRemoteCallback(self, _a, _b):
self.parent_window.generate_list()

def addRemoteThread(self, command):
try:
subprocess.run(command, capture_output=True, check=True, env=self.new_env)
except Exception as e:
self.toast_overlay.add_toast(Adw.Toast.new(_("Could not add {}").format(self.name_to_add)))
print(e)

def on_add_response(self, _dialog, response_id, _function):
if response_id == "cancel":
return
Expand All @@ -38,12 +48,8 @@ def on_add_response(self, _dialog, response_id, _function):
self.url_to_add = self.url_to_add.strip()

command = ['flatpak-spawn', '--host', 'flatpak', 'remote-add', '--if-not-exists', self.name_to_add, self.url_to_add, install_type]
try:
subprocess.run(command, capture_output=True, check=True, env=self.new_env)
except Exception as e:
self.toast_overlay.add_toast(Adw.Toast.new(_("Could not add {}").format(self.name_to_add)))
print(e)
self.parent_window.generate_list()
task = Gio.Task.new(None, None, self.addRemoteCallback)
task.run_in_thread(lambda _task, _obj, _data, _cancellable: self.addRemoteThread(command))
self.close()

def add_handler(self, _widget, name="", link=""):
Expand Down

0 comments on commit 6e7ee32

Please sign in to comment.