Commit 3eb64bff authored by Roman Alifanov's avatar Roman Alifanov

ServiceNotStartedDialog and threading

parent 33157810
...@@ -26,6 +26,8 @@ gi.require_version('Adw', '1') ...@@ -26,6 +26,8 @@ gi.require_version('Adw', '1')
from gi.repository import Gtk, Gio, Adw from gi.repository import Gtk, Gio, Adw
from .window import TuneitWindow from .window import TuneitWindow
def get_main_window():
return _application.props.active_window
class TuneitApplication(Adw.Application): class TuneitApplication(Adw.Application):
"""The main application singleton class.""" """The main application singleton class."""
...@@ -33,10 +35,13 @@ class TuneitApplication(Adw.Application): ...@@ -33,10 +35,13 @@ class TuneitApplication(Adw.Application):
def __init__(self): def __init__(self):
super().__init__(application_id='ru.ximperlinux.TuneIt', super().__init__(application_id='ru.ximperlinux.TuneIt',
flags=Gio.ApplicationFlags.DEFAULT_FLAGS) flags=Gio.ApplicationFlags.DEFAULT_FLAGS)
global _application
self.create_action('quit', lambda *_: self.quit(), ['<primary>q']) self.create_action('quit', lambda *_: self.quit(), ['<primary>q'])
self.create_action('about', self.on_about_action) self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action) self.create_action('preferences', self.on_preferences_action)
_application = self
def do_activate(self): def do_activate(self):
"""Called when the application is activated. """Called when the application is activated.
......
...@@ -7,6 +7,9 @@ from .tools.yml_tools import load_modules, merge_categories_by_name ...@@ -7,6 +7,9 @@ from .tools.yml_tools import load_modules, merge_categories_by_name
from .tools.gvariant import convert_by_gvariant from .tools.gvariant import convert_by_gvariant
from .widgets import WidgetFactory from .widgets import WidgetFactory
from .widgets.service_dialog import ServiceNotStartedDialog
dialog_presented = False
class Setting: class Setting:
def __init__(self, setting_data): def __init__(self, setting_data):
...@@ -69,8 +72,14 @@ class Setting: ...@@ -69,8 +72,14 @@ class Setting:
widget = WidgetFactory.create_widget(self) widget = WidgetFactory.create_widget(self)
return widget.create_row() if widget else None return widget.create_row() if widget else None
else: else:
# TODO: Окно с предложением включить сервис global dialog_presented
print("The service is unavailable, please enable dbus service") if dialog_presented is False:
from ..main import get_main_window
dialog = ServiceNotStartedDialog()
dialog.present(get_main_window())
dialog_presented = True
return None return None
......
import os
import subprocess
import sys
from gi.repository import Adw
class ServiceNotStartedDialog(Adw.AlertDialog):
def __init__(self):
super().__init__()
self.sname = 'tuneit-daemon'
self.set_heading("The dbus service is disabled.")
self.set_body("Do you want to enable it?")
self.add_response("yes", "Yes")
self.add_response("no", "No")
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()
def service_status(self):
try:
# Запускаем команду systemctl is-active <service_name>
result = subprocess.run(
['systemctl', 'is-active', self.sname],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
# Проверяем статус
if result.stdout.decode('utf-8').strip() == 'active':
return True
else:
return False
except Exception as e:
print(f"An error occurred: {e}")
return False
def service_enable(self):
try:
subprocess.run(
['pkexec', 'systemctl', '--now', 'enable', self.sname],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
except Exception as e:
print(f"An error occurred: {e}")
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from gi.repository import GObject, Adw, Gtk import threading
from gi.repository import GObject, Adw, Gtk, GLib
from .settings.main import init_settings_stack from .settings.main import init_settings_stack
...@@ -38,10 +39,18 @@ class TuneitWindow(Adw.ApplicationWindow): ...@@ -38,10 +39,18 @@ class TuneitWindow(Adw.ApplicationWindow):
self.connect('settings_page_update', self.update_settings_page) self.connect('settings_page_update', self.update_settings_page)
self.update_settings_page() self.update_settings_page()
def update_settings_page(self, *args): def update_settings_page(self):
thread = threading.Thread(target=self._update_settings_page)
thread.daemon = True
thread.start()
def _update_settings_page(self, *args):
""" """
Можно вызвать вот так, благодаря сигналу: Можно вызвать вот так, благодаря сигналу:
self.settings_pagestack.get_root().emit("settings_page_update") self.settings_pagestack.get_root().emit("settings_page_update")
""" """
init_settings_stack(self.settings_pagestack, self.settings_listbox, self.settings_split_view) init_settings_stack(
print("Stack cleared and initialized!") self.settings_pagestack,
self.settings_listbox,
self.settings_split_view,
)
\ No newline at end of file
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