From debad09705968d090fd9df65b9359903e56f7501 Mon Sep 17 00:00:00 2001 From: trigg Date: Tue, 9 Jul 2024 02:15:10 +0100 Subject: [PATCH] - Switch to signal-exit for most exits --- discover_overlay/discord_connector.py | 5 ++--- discover_overlay/discover_overlay.py | 5 ++++- discover_overlay/overlay.py | 7 +++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/discover_overlay/discord_connector.py b/discover_overlay/discord_connector.py index b398a1e..3d59df3 100644 --- a/discover_overlay/discord_connector.py +++ b/discover_overlay/discord_connector.py @@ -23,7 +23,6 @@ CHANNEL - Often called 'Rooms'. Both voice and text channels are types of channe import select import time import json -import sys import logging import calendar import websocket @@ -110,7 +109,7 @@ class DiscordConnector: log.error("No access token in json response") log.error(response.text) log.error("The user most likely denied permission for this app") - sys.exit(1) + self.discover.exit() def set_channel(self, channel, guild, need_req=True): """ @@ -280,7 +279,7 @@ class DiscordConnector: self.get_access_token_stage2(j["data"]["code"]) else: log.error("Authorization rejected") - sys.exit(0) + self.discover.exit() return elif j["cmd"] == "DISPATCH": if j["evt"] == "READY": diff --git a/discover_overlay/discover_overlay.py b/discover_overlay/discover_overlay.py index 421f1fd..60d88d0 100755 --- a/discover_overlay/discover_overlay.py +++ b/discover_overlay/discover_overlay.py @@ -125,7 +125,7 @@ class Discover: if normal_close: sys.exit(0) if "--close" in data or "-x" in data: - os.kill(os.getpid(), signal.SIGTERM) + self.exit() if "--steamos" in data or "-s" in data: self.steamos = True if "--hide" in data: @@ -156,6 +156,9 @@ class Discover: if self.connection: self.connection.request_text_rooms_for_guild(match.group(1)) + def exit(self): + os.kill(os.getpid(), signal.SIGTERM) + def config_set(self, context, key, value): """Set a config value and save to disk""" config = self.config() diff --git a/discover_overlay/overlay.py b/discover_overlay/overlay.py index bbb20e7..2a71f15 100644 --- a/discover_overlay/overlay.py +++ b/discover_overlay/overlay.py @@ -15,7 +15,6 @@ Overlay parent class. Helpful if we need more overlay types without copy-and-pasting too much code """ import os -import sys import logging import gi import cairo @@ -75,7 +74,7 @@ class OverlayWindow(Gtk.Window): if not self.get_display().supports_input_shapes(): log.info( "Input shapes not available. Quitting") - sys.exit(1) + self.discover.exit() if visual: # Set the visual even if we can't use it right now self.set_visual(visual) @@ -125,7 +124,7 @@ class OverlayWindow(Gtk.Window): def window_exited(self, _window=None): """Window closed. Exit app""" - sys.exit(1) + self.discover.exit() def set_gamescope_xatom(self, enabled): """Set Gamescope XAtom to identify self as an overlay candidate""" @@ -160,7 +159,7 @@ class OverlayWindow(Gtk.Window): log.info( "GTK Layer Shell is not supported on this wayland compositor") log.info("Currently not possible: Gnome, Weston") - sys.exit(0) + self.discover.exit() if not GtkLayerShell.is_layer_window(self): GtkLayerShell.init_for_window(self) GtkLayerShell.set_layer(self, GtkLayerShell.Layer.OVERLAY)