Commit 0acb99f7 authored by Roman Alifanov's avatar Roman Alifanov

Added the whether to enable the service dialog

parent fa2346eb
......@@ -31,3 +31,15 @@ msgstr "Тёмная"
msgid "Dark Style"
msgstr "Тёмный Стиль"
msgid "Yes"
msgstr "Да"
msgid "No"
msgstr "Нет"
msgid "The user service is disabled."
msgstr "Юзер-сервис выключен."
msgid "Do you want to enable it?"
msgstr "Вы бы хотели включить его?"
import sys, os
import gi
from .utils import service_status, service_enable, _
gi.require_version('Gtk', '4.0')
gi.require_version('Adw', '1')
......@@ -28,6 +29,36 @@ class XimperUnifiedThemeSwitcherGuiGtk4Application(Adw.Application):
if not win:
win = XimperUnifiedThemeSwitcherGuiGtk4Window(application=self)
win.present()
if service_status("ximper-unified-theme-switcher.service") == False:
print("service not found")
# Create the dialog
dialog = Adw.AlertDialog(
heading=_("The user service is disabled."),
body=_("Do you want to enable it?")
)
# Add buttons for the user to respond
dialog.add_response("yes", _("Yes"))
dialog.add_response("no", _("No"))
# Connect the response handler
dialog.connect("response", self.srvs_d_on_response)
# Present the dialog
dialog.present(win)
def srvs_d_on_response(self, dialog, response):
print(f"response: {response}")
if response == "yes":
service_enable("ximper-unified-theme-switcher.service")
dialog.close()
elif response in ("no", "close"):
dialog.close()
self.props.active_window.close()
def on_about_action(self, widget, _):
"""Callback for the app.about action."""
......
......@@ -8,6 +8,10 @@ gi.require_version('Adw', '1')
from gi.repository import Gtk
import gettext
gettext.textdomain('ximper-unified-theme-switcher-gui')
_ = gettext.gettext
SYSTEM_CONFIG_DIR = "/etc/ximper-unified-theme-switcher"
SYSTEM_CONFIG_FILE = os.path.join(SYSTEM_CONFIG_DIR, "themes")
......@@ -161,7 +165,7 @@ def configure_cr_widgets(crs_configurations, selected_func):
def service_status(service_name):
try:
# Запускаем команду systemctl is-active <service_name>
result = subprocess.run(['systemctl', 'is-active', service_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
result = subprocess.run(['systemctl', '--user', 'is-active', service_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# Проверяем статус
if result.stdout.decode('utf-8').strip() == 'active':
return True
......@@ -170,3 +174,10 @@ def service_status(service_name):
except Exception as e:
print(f"An error occurred: {e}")
return False
def service_enable(service_name):
try:
subprocess.run(['systemctl', '--user', '--now', 'enable', service_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except Exception as e:
print(f"An error occurred: {e}")
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