From 02f60e70b278394a1ddea13955d262e977e18903 Mon Sep 17 00:00:00 2001 From: trigg Date: Thu, 28 Sep 2023 12:07:27 +0100 Subject: [PATCH] - Add desktop actions for some RPC commands - Add detection and special handling of bazzite autostart - Detect running in a container and disable the autostart buttons --- discover_overlay/autostart.py | 38 +++++++++++++++++++++++++++++ discover_overlay/settings_window.py | 16 ++++++++++-- discover_overlay_configure.desktop | 31 +++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/discover_overlay/autostart.py b/discover_overlay/autostart.py index fa61519..50b653e 100644 --- a/discover_overlay/autostart.py +++ b/discover_overlay/autostart.py @@ -68,3 +68,41 @@ class Autostart: def is_auto(self): """Check if it's already set to auto-start""" return True if self.auto else False + +class BazziteAutostart: + """A class to assist auto-start""" + def __init__(self): + self.auto= False + with open("/etc/default/discover-overlay") as f: + content = f.readlines() + for line in content: + if line.startswith("AUTO_LAUNCH_DISCOVER_OVERLAY="): + self.auto = int(line.split("=")[1]) > 0 + log.info("Bazzite Autostart info : %s", + self.auto) + + def set_autostart(self, enable): + """Set or Unset auto-start state""" + if enable and not self.auto: + self.change_file("1") + elif not enable and self.auto: + self.change_file("0") + self.auto = enable + + def change_file(self, value): + newcontent = [] + with open("/etc/default/discover-overlay") as f: + content = f.readlines() + for line in content: + if line.startswith("AUTO_LAUNCH_DISCOVER_OVERLAY="): + newcontent.append( "AUTO_LAUNCH_DISCOVER_OVERLAY=%s\n" % value) + elif len(line)<2: + pass + else: + newcontent.append(line) + with open("/etc/default/discover-overlay", 'w') as f: + f.writelines(newcontent) + + def is_auto(self): + """Check if it's already set to auto-start""" + return self.auto \ No newline at end of file diff --git a/discover_overlay/settings_window.py b/discover_overlay/settings_window.py index 7d72fdc..c08a2ef 100644 --- a/discover_overlay/settings_window.py +++ b/discover_overlay/settings_window.py @@ -18,7 +18,7 @@ import pkg_resources import sys import os import json -from .autostart import Autostart +from .autostart import Autostart, BazziteAutostart from .draggable_window import DraggableWindow from .draggable_window_wayland import DraggableWindowWayland @@ -38,13 +38,21 @@ class MainSettingsWindow(): def __init__(self, config_file, rpc_file, channel_file, args): self.args = args + # Detect Bazzite autostart + self.alternative_autostart = os.path.exists("/etc/default/discover-overlay") + # Detect flatpak en + self.disable_autostart = 'container' in os.environ self.steamos = False self.voice_placement_window = None self.text_placement_window = None self.voice_advanced = False self.tray = None # Systemtray as fallback self.ind = None # AppIndicator - self.autostart_helper = Autostart("discover_overlay") + if self.alternative_autostart: + self.autostart_helper = BazziteAutostart() + else: + self.autostart_helper = Autostart("discover_overlay") + self.autostart_helper_conf = Autostart("discover_overlay_configure") self.ind = None self.guild_ids = [] @@ -515,6 +523,10 @@ class MainSettingsWindow(): self.widget['core_run_conf_on_startup'].set_active( self.autostart_helper_conf.is_auto()) + if self.disable_autostart: + self.widget['core_run_on_startup'].set_sensitive(False) + self.widget['core_run_conf_on_startup'].set_sensitive(False) + self.widget['core_force_xshape'].set_active( config.getboolean("general", "xshape", fallback=False)) diff --git a/discover_overlay_configure.desktop b/discover_overlay_configure.desktop index 9e5c399..260c0a6 100644 --- a/discover_overlay_configure.desktop +++ b/discover_overlay_configure.desktop @@ -7,3 +7,34 @@ Terminal=false Type=Application Categories=Utility;TelephonyTools Keywords=Discord +Actions=Show;Hide;Mute;Unmute;Deaf;Undeaf + +[Destkop Action Mute] +Exec=discover-overlay --rpc --mute +Name=Mute Self +StartupNotify=false + +[Desktop Action Unmute] +Exec=discover-overlay --rpc --unmute +Name=Unmute Self +StartupNotify=false + +[Desktop Action Hide] +Exec=discover-overlay --rpc --hide +Name=Hide Overlay +StartupNotify=false + +[Desktop Action Show] +Exec=discover-overlay --rpc --show +Name=Show Overlay +StartupNotify=false + +[Desktop Action Deaf] +Exec=discover-overlay --rpc --deaf +Name=Deafen Self +StartupNotify=false + +[Desktop Action Undeaf] +Exec=discover-overlay --rpc --undeaf +Name=Undeafen Self +StartupNotify=false