Skip to content

Commit

Permalink
Autostart check and update
Browse files Browse the repository at this point in the history
  • Loading branch information
kyvaith authored Dec 6, 2024
1 parent ed5b1f5 commit 4cd564a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def __init__(self, sample_rate=44100, channels=2, buffer_size=1024):
self.encoder.set_channels(self.channels)
self.encoder.set_quality(2)

# Autostart check and update
if self.is_autostart_enabled():
logging.info("Autostart is enabled and verified.")
else:
logging.info("Autostart is not enabled.")

def get_icon_path(self):
"""
Get the path to the `icon.ico` file.
Expand All @@ -90,7 +96,7 @@ def update_tray_title(self):

def is_autostart_enabled(self):
"""
Check if the application is set to autostart with Windows.
Check if the application is set to autostart with Windows and update the entry if necessary.
"""
try:
key = winreg.OpenKey(
Expand All @@ -101,9 +107,19 @@ def is_autostart_enabled(self):
)
value, regtype = winreg.QueryValueEx(key, "TeamsHelper")
winreg.CloseKey(key)
return value == sys.executable

current_executable_path = f'"{os.path.abspath(sys.argv[0])}"'
if value != current_executable_path:
# Update the autostart entry with the new path
self.enable_autostart()
logging.info("Updated autostart path to: %s", current_executable_path)

return value == current_executable_path
except FileNotFoundError:
return False
except Exception as e:
logging.error(f"Error checking autostart status: {e}")
return False

def enable_autostart(self):
"""
Expand Down

0 comments on commit 4cd564a

Please sign in to comment.