|
|
@ -26,6 +26,7 @@ |
|
|
|
import signal |
|
|
|
import sys |
|
|
|
import traceback |
|
|
|
import threading |
|
|
|
|
|
|
|
|
|
|
|
try: |
|
|
@ -105,6 +106,8 @@ class ElectrumGui(PrintError): |
|
|
|
self.timer = Timer() |
|
|
|
self.nd = None |
|
|
|
self.network_updated_signal_obj = QNetworkUpdatedSignalObject() |
|
|
|
self._num_wizards_in_progress = 0 |
|
|
|
self._num_wizards_lock = threading.Lock() |
|
|
|
# init tray |
|
|
|
self.dark_icon = self.config.get("dark_icon", False) |
|
|
|
self.tray = QSystemTrayIcon(self.tray_icon(), None) |
|
|
@ -195,6 +198,18 @@ class ElectrumGui(PrintError): |
|
|
|
run_hook('on_new_window', w) |
|
|
|
return w |
|
|
|
|
|
|
|
def count_wizards_in_progress(func): |
|
|
|
def wrapper(self: 'ElectrumGui', *args, **kwargs): |
|
|
|
with self._num_wizards_lock: |
|
|
|
self._num_wizards_in_progress += 1 |
|
|
|
try: |
|
|
|
return func(self, *args, **kwargs) |
|
|
|
finally: |
|
|
|
with self._num_wizards_lock: |
|
|
|
self._num_wizards_in_progress -= 1 |
|
|
|
return wrapper |
|
|
|
|
|
|
|
@count_wizards_in_progress |
|
|
|
def start_new_window(self, path, uri, app_is_starting=False): |
|
|
|
'''Raises the window for the wallet if it is open. Otherwise |
|
|
|
opens the wallet and creates a new window for it''' |
|
|
@ -291,10 +306,15 @@ class ElectrumGui(PrintError): |
|
|
|
signal.signal(signal.SIGINT, lambda *args: self.app.quit()) |
|
|
|
|
|
|
|
def quit_after_last_window(): |
|
|
|
# on some platforms, not only does exec_ not return but not even |
|
|
|
# aboutToQuit is emitted (but following this, it should be emitted) |
|
|
|
if self.app.quitOnLastWindowClosed(): |
|
|
|
self.app.quit() |
|
|
|
# keep daemon running after close |
|
|
|
if self.config.get('daemon'): |
|
|
|
return |
|
|
|
# check if a wizard is in progress |
|
|
|
with self._num_wizards_lock: |
|
|
|
if self._num_wizards_in_progress > 0 or len(self.windows) > 0: |
|
|
|
return |
|
|
|
self.app.quit() |
|
|
|
self.app.setQuitOnLastWindowClosed(False) # so _we_ can decide whether to quit |
|
|
|
self.app.lastWindowClosed.connect(quit_after_last_window) |
|
|
|
|
|
|
|
def clean_up(): |
|
|
@ -306,10 +326,6 @@ class ElectrumGui(PrintError): |
|
|
|
self.tray.hide() |
|
|
|
self.app.aboutToQuit.connect(clean_up) |
|
|
|
|
|
|
|
# keep daemon running after close |
|
|
|
if self.config.get('daemon'): |
|
|
|
self.app.setQuitOnLastWindowClosed(False) |
|
|
|
|
|
|
|
# main loop |
|
|
|
self.app.exec_() |
|
|
|
# on some platforms the exec_ call may not return, so use clean_up() |
|
|
|