Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/tray.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import sys
import subprocess
from loguru import logger as log
import globals as gl
from src.backend.trayicon import DBusTrayIcon, DBusMenu
Expand All @@ -19,6 +21,7 @@ def __init__(self):
self.menu.add_menu_item(5, "About", callback=self.on_about)
self.menu.add_menu_item(6, menu_type="separator")
self.menu.add_menu_item(7, "Quit", callback=self.on_quit)
self.menu.add_menu_item(8, "Quit and Restart", callback=self.on_restart)
super().__init__(self.menu, self.MenuPath, self.IndicatorPath, self.AppId, "StreamController")
icon_theme_path = os.path.join(gl.MAIN_PATH, "Assets", "icons")
self.set_icon("com.core447.StreamController", path=icon_theme_path)
Expand Down Expand Up @@ -73,6 +76,38 @@ def on_about(self):
def on_quit(self):
self.quit_app_action.activate()

@log.catch
def on_restart(self):
pid = str(os.getpid())
restart_cmd = [sys.executable, *sys.argv]

restart_script = """
pid="$1"
shift

sleep 0.5

if kill -0 "$pid" 2>/dev/null; then
kill -TERM "$pid" 2>/dev/null
fi

while kill -0 "$pid" 2>/dev/null; do
sleep 0.2
done

exec "$@"
"""

subprocess.Popen(
["/bin/sh", "-c", restart_script, "streamcontroller-restart", pid, *restart_cmd],
cwd=gl.MAIN_PATH,
start_new_session=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)

self.quit_app_action.activate()



# import os
Expand Down
13 changes: 3 additions & 10 deletions src/windows/Settings/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,9 @@ def on_data_path_changed(self, *args):
gl.settings_manager.save_static_settings(static_settings)

def on_open_data_path_button_clicked(self, *args):
command = ""
if is_flatpak():
command += "flatpak-spawn --host "

command += f"xdg-open {self.data_path.get_text()}"

try:
subprocess.check_output(command, shell=True)
except subprocess.CalledProcessError:
pass
path = self.data_path.get_text().strip()
uri = Gio.File.new_for_path(path).get_uri()
Gio.AppInfo.launch_default_for_uri(uri, None)


class GeneralPage(Adw.PreferencesPage):
Expand Down