tauri-apps / tauri-apps/plugins-workspace

Flatpak autostart breaks with Tauri autostart plugin (Exec should use flatpak app id)

Open
#3,166 5 comments 0 reactions 0 assignees View on GitHub
platform: linux plugin: autostart type: bug type: documentation
Dominant language
Rust
Stars
1.8k
Forks
602
Avg merge
4d 14h
Merged PRs (30d)
9

Description

### Describe the bug

When using the Tauri autostart functionality in **Flatpak-distributed apps**, the generated autostart entry is incorrect and causes the app to fail on login.

Tauri currently assumes a **native desktop binary**, but Flatpak apps must be launched via `flatpak run `. As a result, the autostart entry generated by Tauri does not work for Flatpak builds.

This issue affects any Tauri app distributed via **Flathub** that enables autostart.

---

### Actual Behavior

Tauri generates an autostart entry similar to:

```ini
Exec=/app/bin/my-app --tray
```

This command **cannot be executed outside the Flatpak sandbox**, so the app does not start on login.

---

### Why This Happens

Flatpak apps are containerized and **must be launched via Flatpak itself**.
Unlike native binaries, the app binary inside `/app/bin` is not directly executable by the host session manager at login.

---

### Workaround

I implemented a manual Flatpak-specific autostart handler to bypass Tauri’s autostart module when the `flatpak` feature is enabled.

Example workaround code:

```rust
#[cfg(feature = "flatpak")]
pub fn manage_flatpak_autostart(enable: bool) -> Result<(), String> {
use std::fs;
use std::path::PathBuf;

let home = std::env::var("HOME")
.map_err(|_| "Could not find HOME environment variable")?;
let autostart_dir = PathBuf::from(home).join(".config/autostart");
let desktop_file_path =
autostart_dir.join("io.github.zarestia_dev.rclone-manager.desktop");

if enable {
fs::create_dir_all(&autostart_dir)
.map_err(|e| format!("Failed to create autostart directory: {e}"))?;

let content = r#"[Desktop Entry]
Type=Application
Name=RClone Manager
Comment=RClone Manager flatpak autostart entry (Not handled by tauri)
Exec=/usr/bin/flatpak run io.github.zarestia_dev.rclone-manager --tray
X-Flatpak=io.github.zarestia_dev.rclone-manager
Terminal=false
"#;

fs::write(&desktop_file_path, content)
.map_err(|e| format!("Failed to write autostart file: {e}"))?;
} else if desktop_file_path.exists() {
fs::remove_file(&desktop_file_path)
.map_err(|e| format!("Failed to remove autostart file: {e}"))?;
}

Ok(())
}
```

While this works, it feels like something the Tauri autostart plugin (or docs) should handle or at least document.

---

### Documentation Gap

There is currently **no mention** in the Tauri docs that:

* Autostart behaves differently for Flatpak
* The default autostart plugin is **not compatible** with Flatpak packaging

---

### Additional Suggested Solution: Flatpak App ID Override

Allow developers to provide a **static Flatpak App ID** at build time, which Tauri can use when generating autostart entries for Flatpak bundles.

For example, Tauri could read an environment variable such as:

```text
TAURI_FLATPAK_ID
```

When this variable is set, the autostart plugin would generate:

```ini
Exec=/usr/bin/flatpak run
```

instead of pointing to a native binary path.

This approach works well with Flathub’s build system, where environment variables are commonly defined in the manifest:

```yaml
- name: rclone-manager
buildsystem: simple
build-options:
append-path: /usr/lib/sdk/node20/bin:/usr/lib/sdk/rust-stable/bin
env:
CARGO_HOME: /run/build/rclone-manager/cargo
NPM_CONFIG_LOGLEVEL: info
npm_config_cache: /run/build/rclone-manager/flatpak-node/npm-cache
npm_config_nodedir: /usr/lib/sdk/node20
npm_config_offline: 'true'
TAURI_FLATPAK_ID: "io.github.zarestia_dev.rclone-manager"
sources:
- type: git
url: https://github.com/Zarestia-Dev/rclone-manager.git
tag: v0.1.8
- npm-sources.json
- cargo-sources.json
```

### Reproduction

## Reproduction Steps (Flatpak + Autostart)

### Steps

1. Install the Flatpak application from Flathub:

```bash
flatpak install io.github.zarestia_dev.rclone-manager
```

> Not gonna work after v0.1.9

2. Launch the application.

3. Inside the app open preferences, **enable Autostart** using the built-in Tauri autostart feature.

4. Inspect the generated autostart entry:

```bash
cat ~/.config/autostart/*.desktop
```

5. Observe the generated `.desktop` file for the app (for example):

```ini
Exec=/app/bin/rclone-manager --tray
```

7. Reboot the system or log out and log back in.

---

### Expected Result

The application should start automatically on login using Flatpak:

```ini
Exec=/usr/bin/flatpak run io.github.zarestia_dev.rclone-manager --tray
```

---

### Actual Result

The autostart entry points to a **non-existent native binary path**:

```ini
Exec=/app/bin/rclone-manager --tray
```

As a result:

* The app does **not** start on login
* Autostart silently fails
* Users must manually fix or recreate the autostart entry

### Expected behavior

For Flatpak builds, the autostart entry should be compatible with Flatpak, e.g.:

```ini
Exec=/usr/bin/flatpak run io.github.example.app --tray
```

### Full `tauri info` output

```text
[✔] Environment
- OS: Arch Linux Rolling Release x86_64 (X64) (gnome on wayland)
✔ webkit2gtk-4.1: 2.50.3
✔ rsvg2: 2.61.3
✔ rustc: 1.91.1 (ed61e7d7e 2025-11-07)
✔ cargo: 1.91.1 (ea2d97820 2025-10-10)
✔ rustup: 1.28.2 (2025-07-07)
✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
- node: 25.2.1
- npm: 11.6.4

[-] Packages
- tauri 🦀: 2.9.4, (outdated, latest: 2.9.5)
- tauri-build 🦀: 2.5.3
- wry 🦀: 0.53.5
- tao 🦀: 0.34.5
- @tauri-apps/api ⱼₛ: 2.9.1
- @tauri-apps/cli ⱼₛ: 2.9.5 (outdated, latest: 2.9.6)

[-] Plugins
- tauri-plugin-notification 🦀: 2.3.3
- @tauri-apps/plugin-notification ⱼₛ: 2.3.3
- tauri-plugin-store 🦀: 2.4.1
- @tauri-apps/plugin-store ⱼₛ: 2.4.1
- tauri-plugin-os 🦀: 2.3.2
- @tauri-apps/plugin-os ⱼₛ: 2.3.2
- tauri-plugin-updater 🦀: 2.9.0
- @tauri-apps/plugin-updater ⱼₛ: 2.9.0
- tauri-plugin-fs 🦀: 2.4.4
- @tauri-apps/plugin-fs ⱼₛ: not installed!
- tauri-plugin-shell 🦀: 2.3.3
- @tauri-apps/plugin-shell ⱼₛ: 2.3.3
- tauri-plugin-global-shortcut 🦀: 2.3.1
- @tauri-apps/plugin-global-shortcut ⱼₛ: not installed!
- tauri-plugin-dialog 🦀: 2.4.2
- @tauri-apps/plugin-dialog ⱼₛ: 2.4.2
- tauri-plugin-autostart 🦀: 2.5.1
- @tauri-apps/plugin-autostart ⱼₛ: 2.5.1
- tauri-plugin-http 🦀: 2.5.4
- @tauri-apps/plugin-http ⱼₛ: 2.5.4
- tauri-plugin-single-instance 🦀: 2.3.6
- @tauri-apps/plugin-single-instance ⱼₛ: not installed!
- tauri-plugin-opener 🦀: 2.5.2
- @tauri-apps/plugin-opener ⱼₛ: 2.5.2

[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist/rclone-manager/browser
- devUrl: http://localhost:1420/
- framework: Angular
- bundler: Webpack
```

### Stack trace

```text

```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.