Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Command line option to toggle theme mode #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion automathemely/autoth_tools/argmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
options.add_argument('-r', '--restart',
help='(re)start the scheduler script if it were to not start or stop unexpectedly',
action='store_true', default=False)

options.add_argument('-L', '--light', help='apply light theme', action='store_true', default=False)
options.add_argument('-D', '--dark', help='apply dark theme', action='store_true', default=False)

# For --list arg
def print_list(d, indent=0):
Expand Down Expand Up @@ -119,3 +120,10 @@ def main(us_se):
Popen(['pkill', '-f', 'autothscheduler.py']).wait()
Popen(['python3', get_bin('autothscheduler.py')], start_new_session=True, stdout=DEVNULL, stderr=DEVNULL)
logger.info('Restarted the scheduler')

# MANUAL theme mode
elif args.light:
return 'light'
elif args.dark:
return 'dark'

2 changes: 1 addition & 1 deletion automathemely/autoth_tools/extratools.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def get_installed_extra_themes(extra):

# All possible paths that I know of that can contain VSCode extensions
vscode_extensions_paths = ['/snap/vscode/current/usr/share/code/resources/app/extensions',
'/usr/share/code/resources/app/extensions',
str(Path.home().joinpath('.vscode', 'extensions')),
'/usr/lib/extensions',
'/usr/share/code/resources/app/extensions',
'/opt/visual-studio-code/resources/app/extensions']
vscode_themes = []
for p in vscode_extensions_paths:
Expand Down
13 changes: 8 additions & 5 deletions automathemely/autoth_tools/updsuntimes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env python3
import logging
from datetime import timedelta
from datetime import date
from time import sleep

import pytz
import tzlocal
from astral import Location
from astral import LocationInfo
from astral.sun import sun

from automathemely.autoth_tools.utils import get_local, verify_desktop_session

Expand Down Expand Up @@ -63,7 +65,7 @@ def main(us_se):
loc = us_se['location']['manual']

try:
location = Location()
location = LocationInfo()
location.name = loc['city']
location.region = loc['region']
location.latitude = loc['latitude']
Expand All @@ -72,9 +74,10 @@ def main(us_se):
except ValueError as e:
logger.error(str(e))
return

sunrise = location.sun()['sunrise'].replace(second=0) + timedelta(minutes=us_se['offset']['sunrise'])
sunset = location.sun()['sunset'].replace(second=0) + timedelta(minutes=us_se['offset']['sunset'])

s = sun(location.observer, date=date.today(), tzinfo=pytz.timezone(location.timezone))
sunrise = s['sunrise'].replace(second=0) + timedelta(minutes=us_se['offset']['sunrise'])
sunset = s['sunset'].replace(second=0) + timedelta(minutes=us_se['offset']['sunset'])

# Convert to UTC for storage
return sunrise.astimezone(pytz.utc), sunset.astimezone(pytz.utc)
Expand Down
21 changes: 16 additions & 5 deletions automathemely/bin/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,17 @@ def main():
# Add the notification handler to the root logger
logging.getLogger().addHandler(automathemely.notifier_handler)

theme = 'auto'
# If any argument is given, pass it/them to the arg manager module
if len(sys.argv) > 1:
automathemely.autoth_tools.argmanager.main(user_settings)
return
mode = automathemely.autoth_tools.argmanager.main(user_settings)
# check if manual theme mode returned
if mode is None:
# auto theme mode; continue
return
else:
# set manual mode
theme = mode

# We don't want to proceed until we have given the user the chance to review its settings
if first_time_run:
Expand All @@ -106,10 +113,14 @@ def main():
now = datetime.now(pytz.utc).astimezone(local_tz).time()
sunrise, sunset = sunrise.astimezone(local_tz).time(), sunset.astimezone(local_tz).time()

if sunrise < now < sunset:
t_color = 'light'
if theme == 'auto':
if sunrise < now < sunset:
t_color = 'light'
else:
t_color = 'dark'
else:
t_color = 'dark'
# set manual theme mode
t_color = theme

logger.info('Switching to {} themes...'.format(t_color))

Expand Down