Skip to content

fix(gui-client): don't panic during setup hook - #9112

Merged
thomaseizinger merged 2 commits into
mainfrom
fix/gui-no-panic-setup
May 13, 2025
Merged

thomaseizinger merged 2 commits into
mainfrom
fix/gui-no-panic-setup

Conversation

@thomaseizinger

@thomaseizinger thomaseizinger commented May 13, 2025 •

Copy link
Copy Markdown
Member

As part of launching the Tauri GUI client, we need to observe a specific initialisation order. In particular, we need to wait until Tauri sends us a RunEvent::Ready before we can initialise things like the tray menu.

To make this more convenient, Tauri offers a so-called "setup hook" that can be set on the app builder. Unfortunately, Tauri internally panics if this provided setup-hook returns an Err. Removing this is tracked upstream: tauri-apps/tauri#12815.

Until this is fixed, we stop using this "setup hook" and instead spawn our own task that performs this work. This task needs to wait until Tauri is ready. To achieve that, we introduce an additional mpsc channel that sends a notification every time we receive a RunEvent::Ready. That should only happen once. We only read from the receiver once, which is why we ignore the error on the sending side in case the receiver has already been dropped.

Resolves: #9101

@thomaseizinger
thomaseizinger requested review from Copilot and jamilbk May 13, 2025 02:34
@vercel

vercel Bot commented May 13, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
firezone ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 2:37am

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the use of Tauri’s built-in setup hook (which panics on errors) and instead spawns a custom async task that waits for RunEvent::Ready before performing initialization steps like tray setup, update checks, and smoke tests.

  • Replace .setup hook with a setup_task that awaits a RunEvent::Ready via a new mpsc channel.
  • Move update-checker and smoke-test spawns, tray initialization, and controller startup inside the custom setup task.
  • Adjust the app.run_return loop to send the ready signal and handle exit prevention.
Comments suppressed due to low confidence (2)

rust/gui-client/src-tauri/src/gui.rs:146

  • [nitpick] Consider renaming ready_tx and ready_rx to more descriptive names like ready_event_tx and ready_event_rx to clarify their purpose.
let (ready_tx, mut ready_rx) = mpsc::channel::<tauri::AppHandle>(1);

rust/gui-client/src-tauri/src/gui.rs:188

  • Since this change introduces a new channel-based readiness mechanism, consider adding a test that simulates RunEvent::Ready to ensure the setup task proceeds as expected.
// Block until Tauri is ready.


// Spawn the setup task.
// Everything we need to do once Tauri is fully initialised goes in here.
let setup_task = rt.spawn(async move {

Copilot AI May 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The setup logic inside this spawned async block is sizable—consider extracting it into a dedicated async function (e.g., run_app_setup) to improve readability and testability.

Copilot uses AI. Check for mistakes.
Comment thread rust/gui-client/src-tauri/src/gui.rs Resolved
@thomaseizinger

Copy link
Copy Markdown
Member Author

@jamilbk jamilbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and LGTM.

@thomaseizinger
thomaseizinger added this pull request to the merge queue May 13, 2025
Merged via the queue into main with commit c93a3d7 May 13, 2025
@thomaseizinger
thomaseizinger deleted the fix/gui-no-panic-setup branch May 13, 2025 04:16

This branch was successfully deployed

1 active deployment
Preview — e5cde903 Deployed May 13, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic: Failed to setup app: error encountered during setup hook: Cannot build Tauri tray icon

3 participants