Skip to content

Commit 0a74de4

Browse files
committed
Make app dbus-activatable
1 parent 33a4708 commit 0a74de4

File tree

10 files changed

+44
-32
lines changed

10 files changed

+44
-32
lines changed

build-aux/com.ranfdev.Notify.Devel.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "com.ranfdev.Notify.Devel",
33
"runtime": "org.gnome.Platform",
4-
"runtime-version": "47",
4+
"runtime-version": "48beta",
55
"sdk": "org.gnome.Sdk",
66
"sdk-extensions": [
77
"org.freedesktop.Sdk.Extension.rust-stable",
@@ -45,8 +45,8 @@
4545
{
4646
"type": "git",
4747
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
48-
"tag": "v0.14.0",
49-
"commit": "8e10fcf8692108b9d4ab78f41086c5d7773ef864"
48+
"tag": "v0.16.0",
49+
"commit": "04ef0944db56ab01307a29aaa7303df6067cb3c0"
5050
}
5151
]
5252
},

data/com.ranfdev.Notify.desktop.in.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Comment=ntfy.sh client application to receive everyday's notifications
44
Type=Application
55
Exec=notify
66
Terminal=false
7+
DBusActivatable=true
78
Categories=GNOME;GTK;Network;Utility;
89
# Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon!
910
Keywords=Gnome;GTK;ntfy;

data/com.ranfdev.Notify.service.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[D-BUS Service]
2+
Name=@app-id@
3+
Exec=@bindir@/notify --gapplication-service

data/meson.build

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,15 @@ if glib_compile_schemas.found()
4848
],
4949
)
5050
endif
51+
52+
# DBus services
53+
service_conf = configuration_data()
54+
service_conf.set('bindir', bindir)
55+
service_conf.set('app-id', application_id)
56+
configure_file(
57+
input: '@[email protected]'.format(base_id),
58+
output: '@[email protected]'.format(application_id),
59+
configuration: service_conf,
60+
install: true,
61+
install_dir: dbusdir
62+
)

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pkgdatadir = datadir / meson.project_name()
3333
iconsdir = datadir / 'icons'
3434
podir = meson.project_source_root() / 'po'
3535
gettext_package = meson.project_name()
36+
dbusdir = datadir / 'dbus-1' / 'services'
3637

3738
if get_option('profile') == 'development'
3839
profile = 'Devel'

ntfy-daemon/src/listener.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ impl ListenerActor {
109109
let span = tracing::info_span!("listener_loop", topic = %self.config.topic);
110110
async {
111111
let mut commands_rx = self.commands_rx.take().unwrap();
112+
// TODO: Fix
113+
// Each time a ListenerCommand is received, the supervised loop will be dropped and a new one will be started.
112114
loop {
113115
select! {
114116
_ = self.run_supervised_loop() => {
@@ -191,6 +193,7 @@ impl ListenerActor {
191193
}
192194

193195
async fn recv_and_forward_loop(&mut self) -> anyhow::Result<()> {
196+
debug!("starting receive loop");
194197
let span = tracing::info_span!("receive_loop",
195198
endpoint = %self.config.endpoint,
196199
topic = %self.config.topic,

ntfy-daemon/src/ntfy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::models::NullNotifier;
44
use anyhow::{anyhow, Context};
55
use futures::future::join_all;
66
use futures::StreamExt;
7+
use tracing::debug;
78
use std::{collections::HashMap, future::Future, sync::Arc};
89
use tokio::select;
910
use tokio::{
@@ -225,6 +226,7 @@ impl NtfyActor {
225226
}
226227

227228
async fn handle_watch_subscribed(&mut self) -> anyhow::Result<()> {
229+
debug!("Watching previously subscribed topics, restoring all connections");
228230
let f: Vec<_> = self
229231
.env
230232
.db

ntfy-daemon/src/subscription.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl SubscriptionActor {
262262
actions: msg.actions.clone(),
263263
};
264264

265-
info!(topic=?self.model.topic, "showing notification");
265+
debug!(topic=?self.model.topic, "sending notification through proxy");
266266
notifier.send(n).unwrap();
267267
} else {
268268
debug!(topic=?self.model.topic, "notification muted, skipping");

src/application.rs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,7 @@ mod imp {
5555
app.setup_css();
5656
app.setup_gactions();
5757
app.setup_accels();
58-
}
59-
fn command_line(&self, command_line: &gio::ApplicationCommandLine) -> glib::ExitCode {
60-
debug!("AdwApplication<NotifyApplication>::command_line");
61-
let arguments = command_line.arguments();
62-
let is_daemon = arguments.get(1).map(|x| x.to_str()) == Some(Some("--daemon"));
63-
let app = self.obj();
58+
6459

6560
if self.hold_guard.get().is_none() {
6661
app.ensure_rpc_running();
@@ -71,14 +66,6 @@ mod imp {
7166
warn!(error = %e, "couldn't request running in background from portal");
7267
}
7368
});
74-
75-
if is_daemon {
76-
return glib::ExitCode::SUCCESS;
77-
}
78-
79-
app.ensure_window_present();
80-
81-
glib::ExitCode::SUCCESS
8269
}
8370
}
8471

@@ -93,7 +80,13 @@ glib::wrapper! {
9380
}
9481

9582
impl NotifyApplication {
96-
fn ensure_window_present(&self) {
83+
pub fn new() -> Self {
84+
glib::Object::builder()
85+
.property("application-id", APP_ID)
86+
.property("resource-base-path", "/com/ranfdev/Notify/")
87+
.build()
88+
}
89+
pub fn ensure_window_present(&self) {
9790
if let Some(window) = { self.imp().window.borrow().upgrade() } {
9891
if window.is_visible() {
9992
window.present();
@@ -234,8 +227,8 @@ impl NotifyApplication {
234227
let response = ashpd::desktop::background::Background::request()
235228
.reason("Listen for coming notifications")
236229
.auto_start(true)
237-
.command(&["notify", "--daemon"])
238-
.dbus_activatable(false)
230+
.command(&["notify", "--gapplication-service"])
231+
.dbus_activatable(true)
239232
.send()
240233
.await?
241234
.response()?;
@@ -279,6 +272,7 @@ impl NotifyApplication {
279272
}
280273
}
281274

275+
info!(title = %n.title, "showing notification");
282276
app.send_notification(None, &gio_notif);
283277
}
284278
});
@@ -325,13 +319,3 @@ impl NotifyApplication {
325319
*self.imp().window.borrow_mut() = window.downgrade();
326320
}
327321
}
328-
329-
impl Default for NotifyApplication {
330-
fn default() -> Self {
331-
glib::Object::builder()
332-
.property("application-id", APP_ID)
333-
.property("flags", gio::ApplicationFlags::HANDLES_COMMAND_LINE)
334-
.property("resource-base-path", "/com/ranfdev/Notify/")
335-
.build()
336-
}
337-
}

src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub mod widgets;
88

99
use gettextrs::{gettext, LocaleCategory};
1010
use gtk::{gio, glib};
11+
use adw::prelude::*;
12+
use tracing::debug;
1113

1214
use self::application::NotifyApplication;
1315
use self::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
@@ -26,6 +28,10 @@ fn main() -> glib::ExitCode {
2628
let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file");
2729
gio::resources_register(&res);
2830

29-
let app = NotifyApplication::default();
31+
let app = NotifyApplication::new();
32+
app.register(gio::Cancellable::NONE).expect("Failed to register application");
33+
if !app.is_remote() {
34+
debug!("primary instance");
35+
};
3036
app.run()
3137
}

0 commit comments

Comments
 (0)