Skip to content

Commit 90180af

Browse files
committed
Fix behavior of Cancel button
1 parent 392b14e commit 90180af

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/gui/window.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -568,15 +568,23 @@ def _identify_file_type(self):
568568
self.archive_name = self.import_file
569569

570570
def _call_archive_command(self):
571-
try:
572-
cmd = subprocess.run([sys.executable, "-m", "savedesktop.core.archive", self.archive_mode, self.archive_name], check=True, capture_output=True, text=True, env={**os.environ, "PYTHONPATH": f"{app_prefix}"})
573-
print(cmd.stdout)
574-
except subprocess.CalledProcessError as err:
575-
e = err.stderr
576-
GLib.idle_add(self.show_err_msg, e)
577-
self._set_default_widgets_state()
578-
finally:
571+
self.archive_proc = subprocess.Popen(
572+
[sys.executable, "-m", "savedesktop.core.archive", self.archive_mode, self.archive_name],
573+
stdout=subprocess.PIPE,
574+
stderr=subprocess.PIPE,
575+
text=True,
576+
env={**os.environ, "PYTHONPATH": f"{app_prefix}"}
577+
)
578+
out, err = self.archive_proc.communicate()
579+
print(out)
580+
581+
if self.archive_proc.returncode == 0:
579582
GLib.idle_add(self.done)
583+
elif self.archive_proc.returncode < 0:
584+
print("Cancelled by user.")
585+
else:
586+
GLib.idle_add(self.show_err_msg, err)
587+
self._set_default_widgets_state()
580588

581589
# "Please wait" information page
582590
def please_wait(self):
@@ -616,13 +624,16 @@ def please_wait(self):
616624

617625
# Stop Saving/Importing Configuration
618626
def _cancel(self, w):
619-
os.popen('pkill -f "savedesktop.core.config"')
620-
os.popen('pkill -9 7z')
621-
os.popen('pkill -9 tar')
627+
self._kill_processes()
622628
self._set_default_widgets_state()
623629
for widget in [self.spinner, self.cancel_button, self.status_page]:
624630
self.status_box.remove(widget)
625631

632+
# Kill 7z, tar and savedesktop.core.config after clicking on the Cancel button
633+
def _kill_processes(self):
634+
if hasattr(self, "archive_proc") and self.archive_proc.poll() is None:
635+
self.archive_proc.kill()
636+
626637
# config has been saved action
627638
def done(self):
628639
self._send_notification()
@@ -734,6 +745,8 @@ def show_special_toast(self):
734745
# action after closing the main window
735746
def on_close(self, w):
736747
self.close()
748+
self._kill_processes()
749+
737750
# Save window size, state, and filename
738751
settings["window-size"] = self.get_default_size()
739752
settings["maximized"] = self.is_maximized()

0 commit comments

Comments
 (0)