Skip to content

Commit 31a8583

Browse files
committed
Make app dbus-activatable
1 parent 33a4708 commit 31a8583

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
@@ -10,6 +10,7 @@ use tokio::{
1010
sync::{broadcast, mpsc, oneshot, RwLock},
1111
task::{spawn_local, LocalSet},
1212
};
13+
use tracing::debug;
1314
use tracing::{error, info};
1415

1516
use crate::{
@@ -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: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ 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();
6458

6559
if self.hold_guard.get().is_none() {
6660
app.ensure_rpc_running();
@@ -71,14 +65,6 @@ mod imp {
7165
warn!(error = %e, "couldn't request running in background from portal");
7266
}
7367
});
74-
75-
if is_daemon {
76-
return glib::ExitCode::SUCCESS;
77-
}
78-
79-
app.ensure_window_present();
80-
81-
glib::ExitCode::SUCCESS
8268
}
8369
}
8470

@@ -93,7 +79,13 @@ glib::wrapper! {
9379
}
9480

9581
impl NotifyApplication {
96-
fn ensure_window_present(&self) {
82+
pub fn new() -> Self {
83+
glib::Object::builder()
84+
.property("application-id", APP_ID)
85+
.property("resource-base-path", "/com/ranfdev/Notify/")
86+
.build()
87+
}
88+
pub fn ensure_window_present(&self) {
9789
if let Some(window) = { self.imp().window.borrow().upgrade() } {
9890
if window.is_visible() {
9991
window.present();
@@ -234,8 +226,8 @@ impl NotifyApplication {
234226
let response = ashpd::desktop::background::Background::request()
235227
.reason("Listen for coming notifications")
236228
.auto_start(true)
237-
.command(&["notify", "--daemon"])
238-
.dbus_activatable(false)
229+
.command(&["notify", "--gapplication-service"])
230+
.dbus_activatable(true)
239231
.send()
240232
.await?
241233
.response()?;
@@ -279,6 +271,7 @@ impl NotifyApplication {
279271
}
280272
}
281273

274+
info!(title = %n.title, "showing notification");
282275
app.send_notification(None, &gio_notif);
283276
}
284277
});
@@ -325,13 +318,3 @@ impl NotifyApplication {
325318
*self.imp().window.borrow_mut() = window.downgrade();
326319
}
327320
}
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: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ pub mod error;
66
mod subscription;
77
pub mod widgets;
88

9+
use adw::prelude::*;
910
use gettextrs::{gettext, LocaleCategory};
1011
use gtk::{gio, glib};
12+
use tracing::debug;
1113

1214
use self::application::NotifyApplication;
1315
use self::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
@@ -26,6 +28,11 @@ 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)
33+
.expect("Failed to register application");
34+
if !app.is_remote() {
35+
debug!("primary instance");
36+
};
3037
app.run()
3138
}

0 commit comments

Comments
 (0)