Skip to content

Commit 98b3f5e

Browse files
Adding documentation about using SingleInstance with snap and flatpak (#3350)
Co-authored-by: Fabian-Lars <[email protected]>
1 parent 5f71df1 commit 98b3f5e

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"starlight-blog": "^0.15.0",
4444
"starlight-links-validator": "^0.13.0"
4545
},
46-
"packageManager": "pnpm@10.11.0",
46+
"packageManager": "pnpm@10.12.1",
4747
"engines": {
4848
"pnpm": "^10.0.0"
4949
},

src/content/docs/distribute/snapcraft.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,24 @@ apps:
8484
# - network
8585
# Add whatever plugs you need here, see https://snapcraft.io/docs/snapcraft-interfaces for more info.
8686
# The gnome extension already includes [ desktop, desktop-legacy, gsettings, opengl, wayland, x11, mount-observe, calendar-service ]
87+
# - single-instance-plug # add this if you're using the single-instance plugin
88+
#slots:
89+
# Add the slots you need to expose to other snaps
90+
# - single-instance-plug # add this if you're using the single-instance plugin
91+
92+
# Add these lines only if you're using the single-instance plugin
93+
# Check https://v2.tauri.app/plugin/single-instance/ for details
94+
#slots:
95+
# single-instance:
96+
# interface: dbus
97+
# bus: session
98+
# name: org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID with "_" instead of "." and "-"
99+
#
100+
#plugs:
101+
# single-instance-plug:
102+
# interface: dbus
103+
# bus: session
104+
# name: org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID with "_" instead of "." and "-"
87105

88106
package-repositories:
89107
- type: apt

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

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,78 @@ pub fn run() {
122122
.expect("error while running tauri application");
123123
}
124124
```
125+
126+
## Usage in Snap and Flatpak
127+
128+
On Linux the Single Instance plugin uses DBus to ensure that there will be only one instance running. It does so 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 exit right away.
130+
131+
Despite this working pretty well when your app is bundled as a deb or rpm package or an AppImage, it won't work as intended for snap or flatpak packages by default 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 that shows how 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 `identifier` from your `tauri.conf.json` file, but with with dots (`.`) and dashes (`-`) replaced by underline (`_`).
140+
141+
For example, if your identifier is `net.mydomain.MyApp`:
142+
143+
- `net_mydomain_MyApp` will be your app `{id}`
144+
- `org.net_mydomain_MyApp.SingleInstance` will be your app SingleInstance service name
145+
146+
You will need the service name to authorize your app to use the DBus service on snap and flatpak manifests, as seen below.
147+
148+
### Snap
149+
150+
In your snapcraft.yml file, declare a plug and a slot for the single instance service, and use both on your app declaration:
151+
152+
```yaml title="snapcraft.yml"
153+
# ...
154+
slots:
155+
single-instance:
156+
interface: dbus
157+
bus: session
158+
name: org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
159+
160+
plugs:
161+
single-instance-plug:
162+
interface: dbus
163+
bus: session
164+
name: org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
165+
166+
# .....
167+
apps:
168+
my-app:
169+
# ...
170+
plugs:
171+
# ....
172+
- single-instance-plug
173+
slots:
174+
# ...
175+
- single-instance
176+
177+
# ....
178+
```
179+
180+
This will allow your app to send and receive requests from/to the DBus service as expected by the Single Instance plugin.
181+
182+
### Flatpak
183+
184+
In 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:
185+
186+
```yaml title="net.mydomain.MyApp.yml"
187+
# ...
188+
finish-args:
189+
- --socket=wayland
190+
- --socket=fallback-x11
191+
- --device=dri
192+
- --share=ipc
193+
# ....
194+
- --talk-name=org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
195+
- --own-name=org.net_mydomain_MyApp.SingleInstance # Remember to change net_mydomain_MyApp to your app ID
196+
# ...
197+
```
198+
199+
This will allow your app to send and receive requests from/to the DBus service as expected by the Single Instance plugin.

0 commit comments

Comments
 (0)