Skip to content

Commit

Permalink
add setting for controlling autostart
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed May 11, 2024
1 parent 1e97d89 commit 1a9a2c8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
3 changes: 3 additions & 0 deletions data/io.github.mrvladus.List.gschema.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<key name="task-list-new-task-position-top" type="b">
<default>true</default>
</key>
<key name="launch-on-startup" type="b">
<default>true</default>
</key>
<key name="run-in-background" type="b">
<default>true</default>
</key>
Expand Down
1 change: 1 addition & 0 deletions data/io.github.mrvladus.List.metainfo.xml.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
<li>Better sync errors</li>
<li>Red accent color for date button of overdue tasks</li>
<li>Logs are now written in log.txt file</li>
<li>Setting for disabling autostart</li>
</ul>
<p>Translations:</p>
<ul>
Expand Down
33 changes: 24 additions & 9 deletions errands/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def __inner_check() -> bool:
return True

while True:
if not GSettings.get("launch-on-startup"):
break
sleep(TIMEOUT_SECONDS)
if not __inner_check():
break
Expand All @@ -112,15 +114,28 @@ def run_in_background(self):
portal: Xdp.Portal = Xdp.Portal()

# Request background
portal.request_background(
None,
_("Errands need to run in the background for notifications"),
["errands", "--gapplication-service"],
Xdp.BackgroundFlags.AUTOSTART,
None,
None,
None,
)
if GSettings.get("launch-on-startup"):
portal.request_background(
None,
_("Errands need to run in the background for notifications"),
["errands", "--gapplication-service"],
Xdp.BackgroundFlags.AUTOSTART,
None,
None,
None,
)
else:
try:
os.remove(
os.path.join(
GLib.get_home_dir(),
".config",
"autostart",
State.APP_ID + ".desktop",
)
)
except Exception:
pass

def do_startup(self) -> None:
Adw.Application.do_startup(self)
Expand Down
13 changes: 13 additions & 0 deletions errands/widgets/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from errands.lib.sync.sync import Sync
from caldav.lib import error
from requests import exceptions
from errands.state import State
from errands.widgets.shared.components.buttons import ErrandsButton, ErrandsInfoButton


Expand Down Expand Up @@ -96,11 +97,23 @@ def _build_ui(self) -> None:
)
GSettings.bind("run-in-background", background, "active")

# Background
launch_on_startup = Adw.SwitchRow(
title=_("Launch on Startup"),
subtitle=_("Launch application when user logs in"),
icon_name="errands-progressbar-symbolic",
)
GSettings.bind("launch-on-startup", launch_on_startup, "active")
launch_on_startup.connect(
"notify::active", lambda *_: State.application.run_in_background()
)

notifications_and_bg_group = Adw.PreferencesGroup(
title=_("Notifications and Background")
)
notifications_and_bg_group.add(notifications)
notifications_and_bg_group.add(background)
notifications_and_bg_group.add(launch_on_startup)

# Sync group
sync_group = Adw.PreferencesGroup(
Expand Down
3 changes: 2 additions & 1 deletion io.github.mrvladus.List.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"--share=network",
"--talk-name=org.freedesktop.secrets",
"--talk-name=org.freedesktop.Flatpak",
"--talk-name=org.gnome.OnlineAccounts"
"--talk-name=org.gnome.OnlineAccounts",
"--filesystem=xdg-config/autostart"
],
"cleanup": [
"/lib/debug",
Expand Down

0 comments on commit 1a9a2c8

Please sign in to comment.