Skip to content

Commit

Permalink
fix GUI remembering trigger setting on launch
Browse files Browse the repository at this point in the history
 * #14 (comment)

This commit fixes a bug where both the CLI and GUI version of this app would startup with the 'lock-screen' trigger, even if the config file was set to use the 'soft-shutdown' trigger.

I added some logic to the buskill class to figure out what the setting was set-to in the config file, rather than just hard-coding it to lock-screen -- since we now have a config file
  • Loading branch information
maltfield committed Jun 13, 2023
1 parent 35b6126 commit 1f4216a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/buskill_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def BusKillCLI( buskill_object ):
help="Choose trigger to execute. See --list-triggers for all possible values.",
metavar='',
choices=['l','lock-screen','s','soft-shutdown'],
default='lock-screen'
)

parser.add_argument(
Expand Down Expand Up @@ -154,7 +153,8 @@ def BusKillCLI( buskill_object ):

# attempt to set the trigger
try:
bk.set_trigger( args.trigger )
if args.trigger != None:
bk.set_trigger( args.trigger )
except RuntimeWarning as e:
msg = "ERROR: Unable to set the trigger to '" +str(args.trigger)+ "'\n\t" +str(e)
print( msg ); logger.error( msg )
Expand Down
8 changes: 6 additions & 2 deletions src/packages/buskill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
################################################################################

import platform, multiprocessing, traceback, subprocess
import urllib.request, re, json, certifi, sys, os, math, shutil, tempfile, random, gnupg
import urllib.request, re, json, certifi, sys, os, math, shutil, tempfile, random, gnupg, configparser
import os.path
from buskill_version import BUSKILL_VERSION
from distutils.version import LooseVersion
Expand Down Expand Up @@ -242,7 +242,6 @@ def __init__(self):
self.upgrade_result = None

self.SUPPORTED_TRIGGERS = ['lock-screen', 'soft-shutdown']
self.trigger = 'lock-screen'
self.trigger_softshutdown_lin_shutdown_path = None
self.trigger_softshutdown_lin_poweroff_path = None
self.trigger_softshutdown_lin_systemctl_path = None
Expand Down Expand Up @@ -421,6 +420,11 @@ def __init__(self):
msg = "DEBUG: CONF_FILE:|" +str(self.CONF_FILE)+ "|\n"
print( msg ); logger.debug( msg )

# set the default trigger to what's defined in the config file
self.config = configparser.ConfigParser()
self.config.read( self.CONF_FILE )
self.trigger = self.config.get('buskill', 'trigger')

# handle conditions where this version was already upgraded by a newer
# version or if this is a version that upgraded an older version
self.handle_upgrades()
Expand Down

0 comments on commit 1f4216a

Please sign in to comment.