Commit c404280a authored by Roman Alifanov's avatar Roman Alifanov

an attempt to fix random crashes from calling dialogs

(seems to be successful)
parent f6690070
import time
import traceback
from .module import Module
from .page import Page
......@@ -47,11 +48,17 @@ def init_settings_stack(stack, listbox, split_view):
f"{deps_message}\n{conflicts_message}"
)
response = dialog.user_question(listbox.get_root())
while True:
w = listbox.get_root()
if w.get_visible() and w.get_mapped():
response = dialog.user_question(w)
break
time.sleep(0.1)
print(f"RESPONSE: {response}")
if response == "skip":
break
modules_dict[module.name] = module
for section_data in module_data.get('sections', []):
......
......@@ -8,7 +8,7 @@ from ..tools.gvariant import convert_by_gvariant
from ..widgets.service_dialog import ServiceNotStartedDialog
from gi.repository import GLib
dialog_presented = False
service_stopped = False
class Setting:
......@@ -43,6 +43,7 @@ class Setting:
self.search_target = setting_data.get('search_target', None)
self.map = setting_data.get('map')
if self.map is None:
if self.search_target is not None:
self.map = SearcherFactory.create(self.search_target).search()
......@@ -109,16 +110,29 @@ class Setting:
if dclient is not None:
self.widget = WidgetFactory.create_widget(self)
return self.widget.create_row() if self.widget else None
else:
global dialog_presented
if dialog_presented is False:
global service_stopped
if service_stopped is False:
from ...main import get_main_window
dialog = ServiceNotStartedDialog()
dialog.present(get_main_window())
dialog_presented = True
return None
while True:
w = get_main_window()
if w.get_visible() and w.get_mapped():
dialog = ServiceNotStartedDialog()
response = dialog.user_question(get_main_window())
break
time.sleep(0.1)
if response == "yes":
dialog.service_enable_with_restart()
elif response in ("no", "close"):
dialog.close()
service_stopped = True
return None
self.widget = WidgetFactory.create_widget(self)
return self.widget.create_row() if self.widget else None
......
from gi.repository import GObject, Adw, Gtk
from gi.repository import GLib, Adw, Gtk
from time import sleep
@Gtk.Template(resource_path='/ru.ximperlinux.TuneIt/settings/widgets/deps_alert_dialog.ui')
......@@ -10,7 +10,7 @@ class TuneItDepsAlertDialog(Adw.AlertDialog):
response = ""
def user_question(self, window):
self.present(window)
GLib.idle_add(self.present, window)
def on_response(dialog, response):
self.response = response
......
import os
import subprocess
import sys
from time import sleep
from gi.repository import Adw
from gi.repository import GLib, Adw
class ServiceNotStartedDialog(Adw.AlertDialog):
response = ""
def __init__(self):
super().__init__()
......@@ -15,17 +19,23 @@ class ServiceNotStartedDialog(Adw.AlertDialog):
self.add_response("yes", _("Yes"))
self.add_response("no", _("No"))
def user_question(self, window):
GLib.idle_add(self.present, window)
def on_response(dialog, response):
self.response = response
self.connect("response", self.on_response)
def on_response(self, dialog, response):
if response == "yes":
self.service_enable()
dialog.close()
os.execv(sys.argv[0], sys.argv)
elif response in ("no", "close"):
dialog.close()
self.connect('response', on_response)
while True:
if self.response != "":
return self.response
else:
sleep(0.1)
continue
def service_status(self):
try:
......@@ -52,3 +62,8 @@ class ServiceNotStartedDialog(Adw.AlertDialog):
except Exception as e:
print(f"An error occurred: {e}")
def service_enable_with_restart(self):
self.service_enable()
self.close()
os.execv(sys.argv[0], sys.argv)
......@@ -64,5 +64,6 @@ class TuneitWindow(Adw.ApplicationWindow):
def error(self, error):
print(error)
self.error_dialog.textbuffer.set_text(str(error))
self.error_dialog.present(self)
GLib.idle_add(self.error_dialog.present, self)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment