Skip to content

Make app dbus-activatable #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ jobs:
with:
bundle: notify.flatpak
manifest-path: build-aux/com.ranfdev.Notify.Devel.json
repository-name: "flathub"
repository-name: "flathub-beta"
run-tests: true
cache-key: flatpak-builder-${{ github.sha }}
6 changes: 3 additions & 3 deletions build-aux/com.ranfdev.Notify.Devel.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "com.ranfdev.Notify.Devel",
"runtime": "org.gnome.Platform",
"runtime-version": "47",
"runtime-version": "48beta",
"sdk": "org.gnome.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.rust-stable",
Expand Down Expand Up @@ -45,8 +45,8 @@
{
"type": "git",
"url": "https://gitlab.gnome.org/jwestman/blueprint-compiler",
"tag": "v0.14.0",
"commit": "8e10fcf8692108b9d4ab78f41086c5d7773ef864"
"tag": "v0.16.0",
"commit": "04ef0944db56ab01307a29aaa7303df6067cb3c0"
}
]
},
Expand Down
1 change: 1 addition & 0 deletions data/com.ranfdev.Notify.desktop.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Comment=ntfy.sh client application to receive everyday's notifications
Type=Application
Exec=notify
Terminal=false
DBusActivatable=true
Categories=GNOME;GTK;Network;Utility;
# Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon!
Keywords=Gnome;GTK;ntfy;
Expand Down
3 changes: 3 additions & 0 deletions data/com.ranfdev.Notify.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D-BUS Service]
Name=@app-id@
Exec=@bindir@/notify --gapplication-service
12 changes: 12 additions & 0 deletions data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,15 @@ if glib_compile_schemas.found()
],
)
endif

# DBus services
service_conf = configuration_data()
service_conf.set('bindir', bindir)
service_conf.set('app-id', application_id)
configure_file(
input: '@0@.service.in'.format(base_id),
output: '@0@.service'.format(application_id),
configuration: service_conf,
install: true,
install_dir: dbusdir
)
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pkgdatadir = datadir / meson.project_name()
iconsdir = datadir / 'icons'
podir = meson.project_source_root() / 'po'
gettext_package = meson.project_name()
dbusdir = datadir / 'dbus-1' / 'services'

if get_option('profile') == 'development'
profile = 'Devel'
Expand Down
3 changes: 3 additions & 0 deletions ntfy-daemon/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ impl ListenerActor {
let span = tracing::info_span!("listener_loop", topic = %self.config.topic);
async {
let mut commands_rx = self.commands_rx.take().unwrap();
// TODO: Fix
// Each time a ListenerCommand is received, the supervised loop will be dropped and a new one will be started.
loop {
select! {
_ = self.run_supervised_loop() => {
Expand Down Expand Up @@ -191,6 +193,7 @@ impl ListenerActor {
}

async fn recv_and_forward_loop(&mut self) -> anyhow::Result<()> {
debug!("starting receive loop");
let span = tracing::info_span!("receive_loop",
endpoint = %self.config.endpoint,
topic = %self.config.topic,
Expand Down
2 changes: 2 additions & 0 deletions ntfy-daemon/src/ntfy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use tokio::{
sync::{broadcast, mpsc, oneshot, RwLock},
task::{spawn_local, LocalSet},
};
use tracing::debug;
use tracing::{error, info};

use crate::{
Expand Down Expand Up @@ -225,6 +226,7 @@ impl NtfyActor {
}

async fn handle_watch_subscribed(&mut self) -> anyhow::Result<()> {
debug!("Watching previously subscribed topics, restoring all connections");
let f: Vec<_> = self
.env
.db
Expand Down
2 changes: 1 addition & 1 deletion ntfy-daemon/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl SubscriptionActor {
actions: msg.actions.clone(),
};

info!(topic=?self.model.topic, "showing notification");
debug!(topic=?self.model.topic, "sending notification through proxy");
notifier.send(n).unwrap();
} else {
debug!(topic=?self.model.topic, "notification muted, skipping");
Expand Down
37 changes: 10 additions & 27 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ mod imp {
app.setup_css();
app.setup_gactions();
app.setup_accels();
}
fn command_line(&self, command_line: &gio::ApplicationCommandLine) -> glib::ExitCode {
debug!("AdwApplication<NotifyApplication>::command_line");
let arguments = command_line.arguments();
let is_daemon = arguments.get(1).map(|x| x.to_str()) == Some(Some("--daemon"));
let app = self.obj();

if self.hold_guard.get().is_none() {
app.ensure_rpc_running();
Expand All @@ -71,14 +65,6 @@ mod imp {
warn!(error = %e, "couldn't request running in background from portal");
}
});

if is_daemon {
return glib::ExitCode::SUCCESS;
}

app.ensure_window_present();

glib::ExitCode::SUCCESS
}
}

Expand All @@ -93,7 +79,13 @@ glib::wrapper! {
}

impl NotifyApplication {
fn ensure_window_present(&self) {
pub fn new() -> Self {
glib::Object::builder()
.property("application-id", APP_ID)
.property("resource-base-path", "/com/ranfdev/Notify/")
.build()
}
pub fn ensure_window_present(&self) {
if let Some(window) = { self.imp().window.borrow().upgrade() } {
if window.is_visible() {
window.present();
Expand Down Expand Up @@ -234,8 +226,8 @@ impl NotifyApplication {
let response = ashpd::desktop::background::Background::request()
.reason("Listen for coming notifications")
.auto_start(true)
.command(&["notify", "--daemon"])
.dbus_activatable(false)
.command(&["notify", "--gapplication-service"])
.dbus_activatable(true)
.send()
.await?
.response()?;
Expand Down Expand Up @@ -279,6 +271,7 @@ impl NotifyApplication {
}
}

info!(title = %n.title, "showing notification");
app.send_notification(None, &gio_notif);
}
});
Expand Down Expand Up @@ -325,13 +318,3 @@ impl NotifyApplication {
*self.imp().window.borrow_mut() = window.downgrade();
}
}

impl Default for NotifyApplication {
fn default() -> Self {
glib::Object::builder()
.property("application-id", APP_ID)
.property("flags", gio::ApplicationFlags::HANDLES_COMMAND_LINE)
.property("resource-base-path", "/com/ranfdev/Notify/")
.build()
}
}
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ pub mod error;
mod subscription;
pub mod widgets;

use adw::prelude::*;
use gettextrs::{gettext, LocaleCategory};
use gtk::{gio, glib};
use tracing::debug;

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

let app = NotifyApplication::default();
let app = NotifyApplication::new();
app.register(gio::Cancellable::NONE)
.expect("Failed to register application");
if !app.is_remote() {
debug!("primary instance");
};
app.run()
}
Loading