Skip to content

Commit 28ae8b6

Browse files
Adding documentation about how to use single-instance plugin with snap and flatpak packages.
1 parent 626ef59 commit 28ae8b6

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

src/content/docs/plugin/single-instance.mdx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,75 @@ pub fn run() {
122122
.expect("error while running tauri application");
123123
}
124124
```
125+
126+
## Working with Snap and Flatpak
127+
128+
The Single Instance plugin uses DBus to ensure it will be only one instance running. It does that by publishing a service to DBus when the first instance starts running.
129+
Then, the following instances will try to publish the same service and, if it is already published, they will send a request to the service to notify the first instance, and finish right away.
130+
131+
Despite this works pretty well when your app is bundled as a deb or rpm package, it won't work as intended for snap or flatpak packages because these packages run in a constrained sandboxed environment, where most of the communication to DBus services will be blocked if not explicitly declared on the packaging manifest.
132+
133+
Here's a guide to declare the needed permissions to enable the Single Instance for snap and flatpak packages:
134+
135+
### Getting your app ID
136+
137+
The Single Instance plugin will publish a service named `org.{id}.SingleInstance`.
138+
139+
`{id}` will be the key **identifier** from your **tauri.conf.json** file, but with with dots (.) and dashes (-) replaced by underline (_).
140+
141+
So, if your identifier is `net.mydomain.MyApp`:
142+
- `net_mydomain_MyApp` will be your app `{id}`
143+
- `org.net_mydomain_MyApp.SingleInstance` will be your app SingleInstance service name
144+
145+
You will need the service name to authorize your app to use the DBus service on snap and flatpak manifests, as seen below.
146+
147+
### Snap
148+
149+
On your snapcraft.yml file, declare a plug and a slot for the single instance service, and use both on your app declaration:
150+
```yaml title="snapcraft.yml"
151+
# ...
152+
slots:
153+
single-instance:
154+
interface: dbus
155+
bus: session
156+
name: org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
157+
158+
plugs:
159+
single-instance-plug:
160+
interface: dbus
161+
bus: session
162+
name: org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
163+
164+
# .....
165+
apps:
166+
my-app:
167+
# ...
168+
plugs:
169+
# ....
170+
- single-instance-plug
171+
slots:
172+
# ...
173+
- single-instance
174+
175+
# ....
176+
```
177+
178+
This will allow your app to listen and to send requests to the DBus service as expected by the Single Instance plugin.
179+
180+
### Flatpak
181+
182+
On your flatpak manifest file (your.app.id.yml or your.app.id.json), declare a `--talk-name` and a `--own-name` finish args with the service name:
183+
```yaml title="net.mydomain.MyApp.yml"
184+
# ...
185+
finish-args:
186+
- --socket=wayland
187+
- --socket=fallback-x11
188+
- --device=dri
189+
- --share=ipc
190+
# ....
191+
- --talk-name=org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
192+
- --own-name=org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
193+
# ...
194+
```
195+
196+
This will allow your app to listen and to send requests to the DBus service as expected by the Single Instance plugin.

0 commit comments

Comments
 (0)