diff --git a/dangerzone/__init__.py b/dangerzone/__init__.py index 902d49a..fccc6b3 100644 --- a/dangerzone/__init__.py +++ b/dangerzone/__init__.py @@ -63,26 +63,50 @@ def main(filename): docker_installer.start() return - # Main window - main_window = MainWindow(common) + windows = [] + doc_opened = False - def select_document(filename): - # Validate filename - filename = os.path.abspath(os.path.expanduser(filename)) - try: - open(filename, "rb") - except FileNotFoundError: - print("File not found") - return False - except PermissionError: - print("Permission denied") - return False - common.set_document_filename(filename) - main_window.doc_selection_widget.document_selected.emit() + # Open a document in a window + def select_document(filename=None): + print(f"select_document, filename={filename}") + new_window = MainWindow(common) + + if filename: + # Validate filename + filename = os.path.abspath(os.path.expanduser(filename)) + try: + open(filename, "rb") + except FileNotFoundError: + print("File not found") + return False + except PermissionError: + print("Permission denied") + return False + common.set_document_filename(filename) + new_window.doc_selection_widget.document_selected.emit() + + windows.append(new_window) + doc_opened = True return True # If filename is passed as an argument, open it - if filename is not None: + if filename is None: + if platform.system() == "Darwin": + # Wait 0.5 seconds to see if we can an open document event, and if not open a new window without a document + def open_window_if_not_already_open(): + if not doc_opened: + select_document() + + timer = QtCore.QTimer() + timer.setSingleShot(True) + timer.setInterval(500) + timer.timeout.connect(open_window_if_not_already_open) + timer.start() + else: + # Open a new window without a document + select_document() + else: + # Try opening a window with the docoument selected if not select_document(filename): return False diff --git a/dangerzone/main_window.py b/dangerzone/main_window.py index 4d6e231..15440ef 100644 --- a/dangerzone/main_window.py +++ b/dangerzone/main_window.py @@ -79,4 +79,3 @@ class MainWindow(QtWidgets.QMainWindow): def closeEvent(self, e): e.accept() - self.common.app.quit()