ErikReider / SwayNotificationCenter

A simple GTK based notification daemon for SwayWM
GNU General Public License v3.0
1.3k stars 62 forks source link

Systemd unit file #47

Closed nightly-brew closed 2 years ago

nightly-brew commented 2 years ago

Would it be possible to have swaync shipped by default with a systemd unit file? I wrote a simple one based on the file that comes with mako, if it may help.

[Unit]
Description=Swaync notification daemon
Documentation=https://github.com/ErikReider/SwayNotificationCenter
PartOf=graphical-session.target
After=graphical-session.target
Requisite=graphical-session.target
# ConditionEnvironment requires systemd v247 to work correctly
ConditionEnvironment=WAYLAND_DISPLAY

[Service]
Type=dbus
BusName=org.freedesktop.Notifications
ExecStart=/usr/bin/swaync
ExecReload=/usr/bin/swaync-client --reload-config --reload-css
Restart=on-failure

[Install]
WantedBy=graphical-session.target
ErikReider commented 2 years ago

To start the daemon automatically when receiving a notification, we'll need the .service file that you provided above and a small service file that'll need to be copied into /usr/share/dbus-1/services/

nightly-brew commented 2 years ago

Let me search the one mako uses, if it could be of help.

ErikReider commented 2 years ago

Here it is https://github.com/emersion/mako/blob/ddc1849804c8703ec749140e3a55febb5250e934/fr.emersion.mako.service.in

nightly-brew commented 2 years ago

Alright, let me finish my lunch and I'll take a look at it, and see if d-feet reports swaync as activable after that.

nightly-brew commented 2 years ago

Ok, got it working!

Quick note, the systemd service is called swaync.service.

The dbus service file instead is "/usr/share/dbus-1/org.erikreider.swaync.service", with the following content:

[D-BUS Service]
Name=org.freedesktop.Notifications
Exec=/usr/bin/swaync
SystemdService=swaync.service

With this, dbus happily starts the service when a notification pops up!

ErikReider commented 2 years ago

Cool! Now it just needs some meson work and we'll be done :)

nightly-brew commented 2 years ago

First time using meson, but I think I almost got it right. https://github.com/nightly-brew/SwayNotificationCenter/commit/8e8cf9384beae0b42e9a51317c2358e4db668b2a

Though, I would definitely be happy to hear other's opinions on always including the SystemdService key in the dbus activation file.

The specification says dbus should try invoking the systemd service only if the dbus instance itself was started with "--systemd-activation", falling back to Exec when that parameter is not used. Would you leave it be or would you prefer meson to generate a different file?

I also couldn't decide where to put said files in the project tree, so let me know if services is good or not.

edit: almost forgot. On arch, to get meson to put files in the right location I had to explicity set --prefix /usr, otherwise files going into /usr/share would've been placed into /usr/local/share. Still, you don't seem to use the prefix in the README. Do I need to change something?

nightly-brew commented 2 years ago

I was also thinking, should the systemd service be enabled on install or should it be left to the user to decide? In the latter case, we could provide a preset file.

ErikReider commented 2 years ago

Could you create a pull request so that we can continue the conversation there?

nightly-brew commented 2 years ago

Sure!

nightly-brew commented 2 years ago

Closing since the pull request was accepted.