Browse Source

Added closing protection when job is active

Nicole Portas 3 weeks ago
parent
commit
ea90214999
2 changed files with 14 additions and 0 deletions
  1. 10 0
      MainWindow.cpp
  2. 4 0
      MainWindow.hpp

+ 10 - 0
MainWindow.cpp

@@ -435,6 +435,16 @@ void MainWindow::on_button_restore_clicked() {
     std::thread(&MainWindow::run_restore_job, this, cfg, std::string(std::getenv("HOME"))).detach();
 }
 
+bool MainWindow::on_delete_event(GdkEventAny* any_event) {
+    if (m_WorkerRunning) {
+        Gtk::MessageDialog dialog(*this, "Job in Progress", false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_OK);
+        dialog.set_secondary_text("A backup or restore is currently running. Closing the app now will corrupt your vault. Wait until it's bloody finished.");
+        dialog.run();
+        return true; // Stop the window from closing
+    }
+    return false; // Allow the window to close
+}
+
 bool MainWindow::create_tar_archive(const std::string& s, const std::string& o, bool strip) {
     struct archive *a = archive_write_new();
     archive_write_add_filter_gzip(a);

+ 4 - 0
MainWindow.hpp

@@ -29,6 +29,10 @@ public:
     MainWindow();
     virtual ~MainWindow();
 
+protected:
+    // Intercept the window manager close signal
+    bool on_delete_event(GdkEventAny* any_event) override;
+
 private:
     Gtk::HeaderBar m_HeaderBar;
     Gtk::Box m_MainLayout;