You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/plugin/single-instance.mdx
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,3 +122,78 @@ pub fn run() {
122
122
.expect("error while running tauri application");
123
123
}
124
124
```
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