Skip to content

Commit

Permalink
Use portal for background and autostart (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryonakano committed Jun 27, 2023
1 parent 16427fc commit 6aee690
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 275 deletions.
16 changes: 11 additions & 5 deletions com.github.sgpthomas.hourglass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@ finish-args:
- '--socket=wayland'
- '--socket=fallback-x11'
- '--device=dri'

# DBus access
- '--own-name=com.github.sgpthomas.client'
- '--own-name=com.github.sgpthomas.hourglass'

- '--metadata=X-DConf=migrate-path=/com/github/sgpthomas/hourglass/'
modules:
- name: libportal
buildsystem: meson
config-opts:
- '-Dbackends=gtk4'
- '-Ddocs=false'
- '-Dtests=false'
sources:
- type: archive
url: https://github.com/flatpak/libportal/releases/download/0.6/libportal-0.6.tar.xz
sha256: 88a12c3ba71bc31acff7238c280de697d609cebc50830c3766776ec35abc6566

- name: hourglass
buildsystem: meson
sources:
Expand Down
7 changes: 0 additions & 7 deletions data/com.github.sgpthomas.hourglass-daemon.desktop.in.in

This file was deleted.

15 changes: 0 additions & 15 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,3 @@ i18n.merge_file(
install: true,
install_dir: get_option('datadir') / 'applications'
)

daemon_desktop_in = configure_file(
input: meson.project_name() + '-daemon.desktop.in.in',
output: meson.project_name() + '-daemon.desktop.in',
configuration: conf_data
)

i18n.merge_file(
input: daemon_desktop_in,
output: meson.project_name() + '-daemon.desktop',
po_dir: meson.project_source_root() / 'po' / 'extra',
type: 'desktop',
install: true,
install_dir: get_option('sysconfdir') / 'xdg' / 'autostart'
)
10 changes: 6 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ add_project_arguments(

conf_data = configuration_data()
conf_data.set('EXEC_NAME', meson.project_name())
conf_data.set('DAEMON_EXEC_NAME', meson.project_name() + '-daemon')
conf_data.set_quoted('LOCALEDIR', get_option('prefix') / get_option('localedir'))
conf_data.set_quoted('GETTEXT_PACKAGE', meson.project_name())
config_file = configure_file(
Expand All @@ -34,7 +33,6 @@ sources = files(
'src' / 'Dialogs' / 'MultiSelectPopover.vala',
'src' / 'Dialogs' / 'NewAlarmDialog.vala',
'src' / 'Objects' / 'Counter.vala',
'src' / 'Services' / 'DBusManager.vala',
'src' / 'Views' / 'AbstractView.vala',
'src' / 'Views' / 'AlarmView.vala',
'src' / 'Views' / 'StopwatchView.vala',
Expand All @@ -45,15 +43,20 @@ sources = files(
'src' / 'Utils.vala'
)

subdir ('src' / 'Daemon')

executable(
meson.project_name(),
config_file,
asresources,
sources,
daemon_files,
dependencies: [
dependency('gtk4'),
dependency('gee-0.8'),
dependency('granite-7', version: '>= 7.1.0')
dependency('granite-7', version: '>= 7.1.0'),
dependency('libportal'),
dependency('libportal-gtk4'),
],
install: true,
)
Expand All @@ -65,7 +68,6 @@ install_data(

subdir ('data')
subdir ('po')
subdir ('src' / 'Daemon')

gnome.post_install(
glib_compile_schemas: true,
Expand Down
1 change: 0 additions & 1 deletion po/extra/POTFILES
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
data/com.github.sgpthomas.hourglass.desktop.in.in
data/com.github.sgpthomas.hourglass.metainfo.xml.in
data/com.github.sgpthomas.hourglass-daemon.desktop.in.in
21 changes: 14 additions & 7 deletions src/Daemon/AlarmManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
* 2020-2023 Ryo Nakano
*/

namespace HourglassDaemon {
public class AlarmManager {
namespace Daemon {
public class AlarmManager : GLib.Object {
public signal void refresh_client ();

public HourglassDaemon daemon { private get; construct; }
public Gee.ArrayList<string> alarm_list { get; private set; }

public AlarmManager () {
public AlarmManager (HourglassDaemon daemon) {
Object (daemon: daemon);
}

construct {
debug ("Initiating Alarm Manager");
alarm_list = new Gee.ArrayList<string> ();

Expand All @@ -22,11 +29,11 @@ namespace HourglassDaemon {
foreach (string alarm in alarm_list) {
//if alarm is now and is on, set it off and then disable it
if (is_alarm_string_now (alarm) && get_alarm_state (alarm)) {
notification.show (get_alarm_name (alarm), get_alarm_time (alarm), "alarm");
daemon.send_notification (get_alarm_name (alarm), get_alarm_time (alarm), "alarm");

if (!get_alarm_repeat (alarm)) {
toggle_alarm (alarm);
server.server.should_refresh_client ();
refresh_client ();
}
}
}
Expand Down Expand Up @@ -59,7 +66,7 @@ namespace HourglassDaemon {

public void load_alarm_list () {
alarm_list = new Gee.ArrayList<string> (); //empty alarm list
foreach (string s in HourglassDaemon.saved_alarms.get_strv ("alarms")) { //loop through all entries in schema
foreach (string s in Hourglass.saved.get_strv ("alarms")) { //loop through all entries in schema
if (Hourglass.Utils.is_valid_alarm_string (s)) { //check for validity
alarm_list.add (s); //add to alarm list
}
Expand All @@ -72,7 +79,7 @@ namespace HourglassDaemon {
new_alarm_list += s;
}

HourglassDaemon.saved_alarms.set_strv ("alarms", new_alarm_list); //update alarms gsettings entry
Hourglass.saved.set_strv ("alarms", new_alarm_list); //update alarms gsettings entry
}

public string get_alarm_name (string alarm_string) {
Expand Down
68 changes: 21 additions & 47 deletions src/Daemon/HourglassDaemon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,71 +4,45 @@
* 2020-2023 Ryo Nakano
*/

namespace HourglassDaemon {
namespace Daemon {
public class HourglassDaemon : GLib.Object {
public AlarmManager alarm_manager;

public HourglassServer server;
public static GLib.Settings saved_alarms;
public NotificationManager notification;
public AlarmManager manager;
public static HourglassDaemon get_default () {
if (instance == null) {
instance = new HourglassDaemon ();
}

public class HourglassAlarmDaemon : GLib.Application {

public HourglassAlarmDaemon () {
Object (application_id: "com.github.sgpthomas.hourglass", flags: ApplicationFlags.NON_UNIQUE);
set_inactivity_timeout (1000);
return instance;
}
private static HourglassDaemon instance = null;

static construct {
saved_alarms = new GLib.Settings ("com.github.sgpthomas.hourglass.saved");
private HourglassDaemon () {
}

~HourglassAlarmDaemon () {
release ();
construct {
alarm_manager = new AlarmManager (this);
}

public override void startup () {
debug ("Hourglass-Daemon started");
base.startup ();

server = new HourglassServer ();
manager = new AlarmManager ();
notification = new NotificationManager (this);

manager.load_alarm_list ();

hold ();
public void start () {
debug ("Starting Hourglass Daemon…");

Timeout.add (1000, () => {
// Check timer every 0 second
if (new DateTime.now_local ().get_second () == 0) {
manager.check_alarm ();
alarm_manager.check_alarm ();
}

return true;
return GLib.Source.CONTINUE;
});
}

public override void activate () {
debug ("Daemon Activated");
}

public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
return true;
}
}
public void send_notification (string summary, string body, string id) {
var notification = new GLib.Notification (summary);
notification.set_body (body);
notification.set_priority (NotificationPriority.HIGH);

//start the daemon
public static int main (string[] args) {
var app = new HourglassAlarmDaemon (); //create instance of hourglass daemon

//try to register app
try {
app.register ();
} catch (Error e) {
error ("Couldn't register application.");
GLib.Application.get_default ().send_notification ("%s-%s".printf (EXEC_NAME, id), notification);
}

//run
return app.run (args);
}
}
74 changes: 0 additions & 74 deletions src/Daemon/HourglassServer.vala

This file was deleted.

21 changes: 0 additions & 21 deletions src/Daemon/NotificationManager.vala

This file was deleted.

15 changes: 0 additions & 15 deletions src/Daemon/meson.build
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
daemon_files = files(
meson.project_source_root() / 'src' / 'Utils.vala',
'AlarmManager.vala',
'HourglassDaemon.vala',
'HourglassServer.vala',
'NotificationManager.vala'
)

executable(
meson.project_name() + '-daemon',
config_file,
daemon_files,
dependencies: [
dependency('glib-2.0'),
dependency('gio-2.0'),
dependency('granite'),
],
install: true,
)
Loading

0 comments on commit 6aee690

Please sign in to comment.