Skip to content

Commit

Permalink
separate GtkApp and WindowServer
Browse files Browse the repository at this point in the history
  • Loading branch information
ederag committed Feb 3, 2020
1 parent 72a8e31 commit f9d2a84
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 20 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ autom4te.cache
m4
gnome-doc-utils.make
hamster-time-tracker-*.tar.gz
org.gnome.hamster.service
.lock-wscript
.lock-waf*
build
Expand Down
2 changes: 1 addition & 1 deletion data/hamster.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</ul>
</description>

<launchable type="desktop-id">hamster.desktop</launchable>
<launchable type="desktop-id">org.gnome.Hamster.GtkApp.desktop</launchable>

<screenshots>
<screenshot type="default">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@ Terminal=false
Name=Hamster
Comment=Your personal time keeping tool
Icon=hamster
DBusActivatable=true
Exec=@BINDIR@/hamster
Categories=GNOME;GTK;Utility;
Actions=overview;add;

[Desktop Action overview]
Exec= @BINDIR@/hamster overview
Name=overview

[Desktop Action add]
Exec= @BINDIR@/hamster add
Name=add
2 changes: 1 addition & 1 deletion data/wscript_build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bld.install_files('${DATADIR}/icons/hicolor/scalable/apps','art/scalable/hamster

bld.install_files('${DATADIR}/metainfo', 'hamster.metainfo.xml')

for filename in ["hamster.desktop"]:
for filename in ["org.gnome.Hamster.GtkApp.desktop"]:
bld(features = "subst",
source= "%s.in" % filename,
target= "%s" % filename,
Expand Down
3 changes: 3 additions & 0 deletions org.gnome.Hamster.GtkApp.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D-BUS Service]
Name=org.gnome.Hamster.GtkApp
Exec=@BINDIR@/hamster --gapplication-service
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
data/date_range.ui
data/edit_activity.ui
data/preferences.ui
data/hamster.desktop.in
data/org.gnome.Hamster.GtkApp.desktop.in
data/org.gnome.hamster.gschema.xml
src/hamster-cli.py
src/hamster/about.py
Expand Down
1 change: 0 additions & 1 deletion po/POTFILES.skip
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
data/hamster.desktop.in
build/
12 changes: 9 additions & 3 deletions src/hamster-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ def fact_dict(fact_data, with_date):


class Hamster(gtk.Application):
"""Hamster gui.
Can be accessed across D-Bus with the 'org.gnome.Hamster.GtkApp' id.
"""

def __init__(self):
# inactivity_timeout: How long (ms) the service should stay alive
# after all windows have been closed.
gtk.Application.__init__(self,
application_id="org.gnome.Hamster.WindowServer",
application_id="org.gnome.Hamster.GtkApp",
#inactivity_timeout=10000,
register_session=True)

Expand Down Expand Up @@ -443,8 +448,9 @@ def version(self):
else:
app.register()
app.activate_action(action)
logger.debug("run")
status = app.run([sys.argv[0]] + unknown_args)
run_args = [sys.argv[0]] + unknown_args
logger.debug("run {}".format(run_args))
status = app.run(run_args)
logger.debug("app exited")
sys.exit(status)
elif hasattr(hamster_client, action):
Expand Down
27 changes: 19 additions & 8 deletions src/hamster-windows-service.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env python3
# nicked off hamster-service

from gi.repository import GLib as glib
import dbus, dbus.service
import dbus
import dbus.service
import subprocess

from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GLib as glib

DBusGMainLoop(set_as_default=True)
loop = glib.MainLoop()
Expand All @@ -13,7 +16,12 @@
quit()


# maintain just one instance. this code feels hackish again
# Legacy server. Still used by the shell-extension.
# new code should proabably access the GtkApp actions directly
# http://lazka.github.io/pgi-docs/Gio-2.0/classes/Application.html#Gio.Application
# > The actions are also exported on the session bus,
# and GIO provides the Gio.DBusActionGroup wrapper
# to conveniently access them remotely.
class WindowServer(dbus.service.Object):
__dbus_object_path__ = "/org/gnome/Hamster/WindowServer"

Expand All @@ -29,24 +37,27 @@ def Quit(self):
"""Shutdown the service"""
self.mainloop.quit()

def _open_window(self, name):
subprocess.run("hamster {} &".format(name),
shell=True)

# Shell extension is not using it, so probably no-one is.
# To be removed.
@dbus.service.method("org.gnome.Hamster.WindowServer")
def edit(self, id=None):
dialogs.edit.show(self.app, fact_id = id)

@dbus.service.method("org.gnome.Hamster.WindowServer")
def overview(self):
dialogs.overview.show(self.app)
self._open_window("overview")

@dbus.service.method("org.gnome.Hamster.WindowServer")
def about(self):
dialogs.about.show(self.app)
self._open_window("about")

@dbus.service.method("org.gnome.Hamster.WindowServer")
def preferences(self):
dialogs.prefs.show(self.app)


self._open_window("prefs")


if __name__ == '__main__':
Expand Down
14 changes: 10 additions & 4 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,20 @@ def build(bld):
)

bld(features="subst",
source= "org.gnome.hamster.service.in",
target= "org.gnome.hamster.service",
source= "org.gnome.Hamster.service.in",
target= "org.gnome.Hamster.service",
install_path="${DATADIR}/dbus-1/services",
)

bld(features="subst",
source= "org.gnome.hamster.Windows.service.in",
target= "org.gnome.hamster.Windows.service",
source= "org.gnome.Hamster.GtkApp.service.in",
target= "org.gnome.Hamster.GtkApp.service.service",
install_path="${DATADIR}/dbus-1/services",
)

bld(features="subst",
source= "org.gnome.Hamster.WindowServer.service.in",
target= "org.gnome.Hamster.WindowServer.service",
install_path="${DATADIR}/dbus-1/services",
)

Expand Down

0 comments on commit f9d2a84

Please sign in to comment.