Skip to content

Commit

Permalink
Merge pull request #358 from City-busz/autostart
Browse files Browse the repository at this point in the history
Don't use portal if not running under Flatpak
  • Loading branch information
mrvladus authored Dec 2, 2024
2 parents 6c2afaa + 0bdaaab commit 14d3f99
Showing 1 changed file with 46 additions and 20 deletions.
66 changes: 46 additions & 20 deletions errands/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,56 @@ def run_in_background(self):
Log.debug("Application: Checking autostart")

portal: Xdp.Portal = Xdp.Portal()
is_flatpak: bool = portal.running_under_flatpak()

# Request background
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,
)
if is_flatpak:
# Request background
portal.request_background(
None,
_("Errands need to run in the background for notifications"),
["errands", "--gapplication-service"],
Xdp.BackgroundFlags.AUTOSTART,
None,
None,
None,
)
else:
# Get or create autostart dir
autostart_dir: str = os.path.join(GLib.get_home_dir(), ".config", "autostart")
if not os.path.exists(autostart_dir):
os.mkdir(autostart_dir)
autostart_file_content = f"""[Desktop Entry]
Type=Application
Name={State.APP_ID}
Exec=errands --gapplication-service"""
# Create autostart file
file_path: str = os.path.join(autostart_dir, f"{State.APP_ID}.desktop")
with open(file_path, "w") as f:
f.write(autostart_file_content)
else:
try:
os.remove(
os.path.join(
GLib.get_home_dir(),
".config",
"autostart",
State.APP_ID + ".desktop",
)
if is_flatpak:
portal.request_background(
None,
None,
None,
Xdp.BackgroundFlags.NONE,
None,
None,
None,
)
except Exception:
pass
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

0 comments on commit 14d3f99

Please sign in to comment.