Skip to content

Commit

Permalink
- Remove unneeded import logic
Browse files Browse the repository at this point in the history
- Ran a formatter
- Remove reconnect warning limiting logic
  • Loading branch information
trigg committed Feb 13, 2024
1 parent 8cd376d commit 213d686
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 46 deletions.
18 changes: 11 additions & 7 deletions discover_overlay/autostart.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

log = logging.getLogger(__name__)


class Autostart:
"""A class to assist auto-start"""

Expand All @@ -35,7 +36,7 @@ def __init__(self, app_name):
self.auto = self.find_auto()
self.desktop = self.find_desktop()
log.info("Autostart info : desktop %s auto %s",
self.desktop, self.auto)
self.desktop, self.auto)

def find_auto(self):
"""Check all known locations for auto-started apps"""
Expand Down Expand Up @@ -69,17 +70,19 @@ 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
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)
self.auto)

def set_autostart(self, enable):
"""Set or Unset auto-start state"""
Expand All @@ -88,15 +91,16 @@ def set_autostart(self, enable):
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:
newcontent.append(
"AUTO_LAUNCH_DISCOVER_OVERLAY=%s\n" % value)
elif len(line) < 2:
pass
else:
newcontent.append(line)
Expand All @@ -105,4 +109,4 @@ def change_file(self, value):

def is_auto(self):
"""Check if it's already set to auto-start"""
return self.auto
return self.auto
27 changes: 12 additions & 15 deletions discover_overlay/discord_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import requests

import gi
gi.require_version("Gtk", "3.0")
# pylint: disable=wrong-import-position,wrong-import-order
from gi.repository import GLib # nopep8
from gi.repository import GLib

log = logging.getLogger(__name__)

Expand All @@ -47,10 +45,10 @@ class DiscordConnector:
def __init__(self, discover):
self.discover = discover
self.websocket = None
self.access_token = discover.config().get("cache", "access_token", fallback= None)
self.access_token = discover.config().get(
"cache", "access_token", fallback=None)
self.oauth_token = "207646673902501888"
self.access_delay = 0
self.warn_connection = True

self.guilds = {}
self.channels = {}
Expand Down Expand Up @@ -175,7 +173,7 @@ def add_text(self, message):

epoch_time = calendar.timegm(utc_time)
username = message["author"]["username"]
if("nick" in message and message['nick'] and len(message["nick"]) > 1
if ("nick" in message and message['nick'] and len(message["nick"]) > 1
and 'object Object' not in json.dumps(message["nick"])):
username = message["nick"]
colour = "#ffffff"
Expand Down Expand Up @@ -359,7 +357,8 @@ def on_message(self, message):
self.get_access_token_stage1()
return
else:
self.discover.config_set("cache","access_token",self.access_token)
self.discover.config_set(
"cache", "access_token", self.access_token)
self.req_guilds()
self.user = j["data"]["user"]
log.info(
Expand Down Expand Up @@ -723,7 +722,7 @@ def update_overlays_from_data(self):

if self.authed and len(self.rate_limited_channels) > 0:
now = time.time()
if self.last_rate_limit_send < now - 60:
if self.last_rate_limit_send < now - 60:
guild = self.rate_limited_channels.pop()

cmd = {
Expand Down Expand Up @@ -756,7 +755,7 @@ def request_text_rooms_for_guild(self, guild_id):
This will be mixed in with 'None' in the list where a voice channel is
"""
if(guild_id == 0):
if (guild_id == 0):
return
self.rate_limited_channels.append(guild_id)

Expand Down Expand Up @@ -786,14 +785,11 @@ def connect(self):
origin="http://localhost:3000",
timeout=0.1
)
self.warn_connection=True # Warn on next disconnect
if self.socket_watch:
GLib.source_remove(self.socket_watch)
self.socket_watch = GLib.io_add_watch(self.websocket.sock, GLib.IOCondition.HUP | GLib.IOCondition.IN | GLib.IOCondition.ERR, self.socket_glib)
self.socket_watch = GLib.io_add_watch(
self.websocket.sock, GLib.IOCondition.HUP | GLib.IOCondition.IN | GLib.IOCondition.ERR, self.socket_glib)
except ConnectionError as error:
if self.warn_connection:
log.error(error)
self.warn_connection=False
self.schedule_reconnect()

def socket_glib(self, a=None, b=None):
Expand All @@ -807,7 +803,8 @@ def socket_glib(self, a=None, b=None):
if not self.websocket:
# Connection was closed in the meantime
break
recv, _w, _e = select.select((self.websocket.sock,), (), (), 0)
recv, _w, _e = select.select(
(self.websocket.sock,), (), (), 0)
except (websocket.WebSocketConnectionClosedException, json.decoder.JSONDecodeError):
self.on_close()
break
Expand Down
3 changes: 2 additions & 1 deletion discover_overlay/discover_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def config_changed(self, _a=None, _b=None, _c=None, _d=None):
config.getint("main", "border_width", fallback=2))
self.voice_overlay.set_icon_transparency(config.getfloat(
"main", "icon_transparency", fallback=1.0))
self.voice_overlay.set_show_avatar(config.getboolean("main", "show_avatar", fallback=True))
self.voice_overlay.set_show_avatar(
config.getboolean("main", "show_avatar", fallback=True))
self.voice_overlay.set_fancy_border(config.getboolean("main",
"fancy_border", fallback=True))
self.voice_overlay.set_show_dummy(config.getboolean("main",
Expand Down
3 changes: 2 additions & 1 deletion discover_overlay/draggable_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

log = logging.getLogger(__name__)


class DraggableWindow(Gtk.Window):
"""An X11 window which can be moved and resized"""

Expand Down Expand Up @@ -56,7 +57,7 @@ def __init__(self, pos_x=0, pos_y=0, width=300, height=300, message="Message", s
self.drag_y = 0
self.force_location()
self.show_all()

def force_location(self):
"""
Move the window to previously given co-ords.
Expand Down
6 changes: 3 additions & 3 deletions discover_overlay/notification_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def has_content(self):
if self.testing:
return self.test_content
return self.content

def overlay_draw(self, _w, context, data=None):
"""
Draw the overlay
Expand Down Expand Up @@ -388,8 +388,8 @@ def draw_text(self, pos_y, text, icon):
# self.context.rectangle(0, self.border_radius,
# shape_width, shape_height - (self.border_radius * 2))

#self.context.arc(0.7, 0.3, 0.035, 1.25 * math.pi, 2.25 * math.pi)
#self.context.arc(0.3, 0.7, 0.035, .25 * math.pi, 1.25 * math.pi)
# self.context.arc(0.7, 0.3, 0.035, 1.25 * math.pi, 2.25 * math.pi)
# self.context.arc(0.3, 0.7, 0.035, .25 * math.pi, 1.25 * math.pi)
if self.border_radius == 0:

self.context.move_to(0.0, 0.0)
Expand Down
8 changes: 3 additions & 5 deletions discover_overlay/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, discover, piggyback=None):
self.force_xshape = False
self.context = None
self.autohide = False

self.redraw_id = None

self.timer_after_draw = None
Expand All @@ -109,7 +109,6 @@ def __init__(self, discover, piggyback=None):
self.get_screen().connect("monitors-changed", self.screen_changed)
self.get_screen().connect("size-changed", self.screen_changed)


def set_gamescope_xatom(self, enabled):
if self.piggyback_parent:
return
Expand Down Expand Up @@ -256,7 +255,7 @@ def force_location(self):
self.width = width
self.height = height
self.set_needs_redraw()

def set_needs_redraw(self):
if not self.hidden and self.enabled:
if self.piggyback_parent:
Expand Down Expand Up @@ -311,7 +310,7 @@ def set_monitor(self, idx=None):
Set the monitor this overlay should display on.
"""
if type(idx) is str:
idx=0
idx = 0
self.monitor = idx
if self.is_wayland:
display = Gdk.Display.get_default()
Expand Down Expand Up @@ -391,4 +390,3 @@ def check_composite(self, _a=None, _b=None):

def screen_changed(self, screen=None):
self.set_monitor(self.monitor)

21 changes: 9 additions & 12 deletions discover_overlay/settings_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ 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")
self.alternative_autostart = os.path.exists(
"/etc/default/discover-overlay")
# Detect flatpak en
self.disable_autostart = 'container' in os.environ
self.steamos = False
Expand Down Expand Up @@ -288,8 +289,6 @@ def read_config(self):
self.widget['voice_align_2'].set_active(
config.getint("main", "topalign", fallback=1))



monitor = 0
try:
config.getint("main", "monitor", fallback=0)
Expand All @@ -298,7 +297,6 @@ def read_config(self):

self.widget['voice_monitor'].set_active(monitor)


font = config.get("main", "font", fallback=None)
if font:
self.widget['voice_font'].set_font(font)
Expand Down Expand Up @@ -425,7 +423,7 @@ def read_config(self):
config.getboolean("text", "popup_style", fallback=False))

self.widget['text_popup_time'].set_value(
config.getint("text","text_time", fallback=30)
config.getint("text", "text_time", fallback=30)
)

self.current_guild = config.get("text", "guild", fallback="0")
Expand All @@ -442,7 +440,6 @@ def read_config(self):
self.widget['text_background_colour'].set_rgba(self.make_colour(config.get(
"text", "bg_col", fallback="[0.0,0.0,0.0,0.5]")))


monitor = 0
try:
config.getint("text", "monitor", fallback=0)
Expand Down Expand Up @@ -479,7 +476,6 @@ def read_config(self):
self.widget['notification_background_colour'].set_rgba(self.make_colour(config.get(
"notification", "bg_col", fallback="[0.0,0.0,0.0,0.5]")))


monitor = 0
try:
config.getint("notification", "monitor", fallback=0)
Expand Down Expand Up @@ -547,7 +543,6 @@ def read_config(self):

self.loading_config = False


def make_colour(self, col):
col = json.loads(col)
return Gdk.RGBA(col[0], col[1], col[2], col[3])
Expand Down Expand Up @@ -854,7 +849,8 @@ def voice_display_speakers_only(self, button):
self.config_set("main", "only_speaking", "%s" % (button.get_active()))

def voice_display_speakers_grace_period(self, button):
self.config_set("main", "only_speaking_grace", "%s" % (int(button.get_value())))
self.config_set("main", "only_speaking_grace", "%s" %
(int(button.get_value())))

def voice_toggle_test_content(self, button):
self.config_set("main", "show_dummy", "%s" % (button.get_active()))
Expand Down Expand Up @@ -1062,7 +1058,8 @@ def notification_background_colour_changed(self, button):
self.config_set("notification", "bg_col", json.dumps(colour))

def notification_monitor_changed(self, button):
self.config_set("notification", "monitor", "%s" % (button.get_active()))
self.config_set("notification", "monitor", "%s" %
(button.get_active()))

def notification_align_1_changed(self, button):
self.config_set("notification", "rightalign", "%s" %
Expand Down Expand Up @@ -1123,7 +1120,7 @@ def core_settings_min_changed(self, button):
def core_reset_all(self, button):
self.config_remove_section("general")
self.read_config()

def voice_reset_all(self, button):
self.config_remove_section("main")
self.read_config()
Expand All @@ -1134,4 +1131,4 @@ def text_reset_all(self, button):

def notification_reset_all(self, button):
self.config_remove_section("notification")
self.read_config()
self.read_config()
3 changes: 1 addition & 2 deletions discover_overlay/voice_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,6 @@ def overlay_draw(self, w, context, data=None):
offset_x_mult = -1
current_x = self.width - avatar_size - self.horz_edge_padding


# Choose where to start drawing
current_y = 0 + self.vert_edge_padding
if self.align_vert == 1:
Expand Down Expand Up @@ -749,7 +748,7 @@ def draw_avatar(self, context, user, pos_x, pos_y, avatar_size, line_height):
Draw avatar at given Y position. Includes both text and image based on settings
"""
# Ensure pixbuf for avatar
if user["id"] not in self.avatars and user["avatar"] and avatar_size>0:
if user["id"] not in self.avatars and user["avatar"] and avatar_size > 0:
url = "https://cdn.discordapp.com/avatars/%s/%s.png" % (
user['id'], user['avatar'])
get_surface(self.recv_avatar, url, user["id"],
Expand Down

0 comments on commit 213d686

Please sign in to comment.