Skip to content

Commit

Permalink
revert to libportal
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvladus committed Feb 15, 2024
1 parent c826837 commit caa28ba
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 48 deletions.
20 changes: 17 additions & 3 deletions build-aux/flathub/io.github.mrvladus.List.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,27 @@
}
]
},
"python3-modules.json",
{
"name": "errands",
"name": "libportal",
"buildsystem": "meson",
"config-opts": [
"-Dflatpak=true"
"-Dbackend-gtk4=enabled",
"-Dvapi=false",
"-Ddocs=false",
"-Dtests=false"
],
"sources": [
{
"type": "git",
"url": "https://github.com/flatpak/libportal.git",
"tag": "0.7.1"
}
]
},
"python3-modules.json",
{
"name": "errands",
"buildsystem": "meson",
"sources": [
{
"type": "git",
Expand Down
58 changes: 22 additions & 36 deletions errands/application.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __main__ import APP_ID, PROFILE, IS_FLATPAK
import os
from gi.repository import Adw, Gio, GLib # type:ignore
from __main__ import APP_ID, PROFILE
from gi.repository import Adw, Gio, Xdp # type:ignore
from errands.lib.gsettings import GSettings
from errands.widgets.window import Window
from errands.lib.plugins import PluginsLoader
Expand All @@ -17,7 +16,7 @@ class ErrandsApplication(Adw.Application):
def __init__(self) -> None:
super().__init__(
application_id=APP_ID,
flags=Gio.ApplicationFlags.DEFAULT_FLAGS,
flags=Gio.ApplicationFlags.IS_SERVICE,
)
self.set_resource_base_path("/io/github/mrvladus/Errands/")

Expand All @@ -26,32 +25,16 @@ def run_in_background(self):

Log.debug("Application: Checking autostart")

# 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)

# Check if running in flatpak
if IS_FLATPAK:
autostart_file_content = f"""[Desktop Entry]
Type=Application
Name={APP_ID}
Exec=flatpak run --command=errands {APP_ID} --gapplication-service
X-Flatpak={APP_ID}"""
else:
autostart_file_content = f"""[Desktop Entry]
Type=Application
Name={APP_ID}
Exec=errands --gapplication-service"""

# Create or remove autostart file
file_path: str = os.path.join(autostart_dir, f"{APP_ID}.desktop")
if GSettings.get("run-in-background") and not os.path.exists(file_path):
with open(file_path, "w") as f:
f.write(autostart_file_content)
else:
if os.path.exists(file_path):
os.remove(file_path)
portal: Xdp.Portal = Xdp.Portal()
portal.request_background(
None,
_("Errands need to run in the background for notifications"),
["errands", "--gapplication-service"],
Xdp.BackgroundFlags.AUTOSTART,
None,
None,
None,
)

def run_tests_suite(self):
if PROFILE == "development":
Expand All @@ -60,6 +43,8 @@ def run_tests_suite(self):
run_tests()

def do_startup(self) -> None:
Adw.Application.do_startup(self)

# Logging
Log.init()
Log.debug("Application: Startup")
Expand All @@ -73,13 +58,14 @@ def do_startup(self) -> None:
# Background
self.run_in_background()

# Startup
Adw.Application.do_startup(self)

def do_activate(self) -> None:
Log.debug("Application: Activate")
# Plugins
self.plugins_loader = PluginsLoader(self)

# Main window
self.window = Window(application=self)
self.add_window(self.window)
self.run_tests_suite()

def do_activate(self) -> None:
Log.debug("Application: Activate")
self.window.present()
self.run_tests_suite()
6 changes: 2 additions & 4 deletions errands/errands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@
gi.require_version("Adw", "1")
gi.require_version("Secret", "1")
gi.require_version("GtkSource", "5")
gi.require_version("Xdp", "1.0")


APP_ID = "@APP_ID@"
VERSION = "@VERSION@"
PREFIX = "@PREFIX@"
PROFILE = "@PROFILE@"
IS_FLATPAK = bool("@IS_FLATPAK@")
pkgdatadir = "@pkgdatadir@"
localedir = "@localedir@"


def setup_gettext():
import signal
import locale
import gettext
import signal, locale, gettext

sys.path.insert(1, pkgdatadir)
signal.signal(signal.SIGINT, signal.SIG_DFL)
Expand Down
20 changes: 18 additions & 2 deletions io.github.mrvladus.List.Devel.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,29 @@
}
]
},
{
"name": "libportal",
"buildsystem": "meson",
"config-opts": [
"-Dbackend-gtk4=enabled",
"-Dvapi=false",
"-Ddocs=false",
"-Dtests=false"
],
"sources": [
{
"type": "git",
"url": "https://github.com/flatpak/libportal.git",
"tag": "0.7.1"
}
]
},
"build-aux/python3-modules.json",
{
"name": "errands",
"buildsystem": "meson",
"config-opts": [
"-Dprofile=development",
"-Dflatpak=true"
"-Dprofile=development"
],
"sources": [
{
Expand Down
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ conf.set('APP_ID', app_id)
conf.set('PREFIX', prefix)
conf.set('VERSION', meson.project_version())
conf.set('PROFILE', profile)
conf.set('IS_FLATPAK', get_option('flatpak'))
conf.set('localedir', join_paths(get_option('prefix'), get_option('localedir')))
conf.set('pkgdatadir', pkgdatadir)
conf.set('bindir', get_option('prefix') / get_option('bindir'))
Expand Down
3 changes: 1 addition & 2 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ option(
'development',
],
value: 'release'
)
option('flatpak', type : 'boolean', value : false)
)

0 comments on commit caa28ba

Please sign in to comment.