fix(windows): resolve file association and single-instance file opening (closes #248) - #250
Open
Enotkiller wants to merge 1 commit into
Open
fix(windows): resolve file association and single-instance file opening (closes #248)#250Enotkiller wants to merge 1 commit into
Enotkiller wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The root cause of the Windows file association bug was a combination of missing platform-specific handling and a frontend race condition. By default, Tauri's file open event only works on macOS. On Windows, double-clicking an associated file passes the path as a standard CLI argument, but we weren't capturing it during the app's setup phase, so cold starts just dropped the file. Furthermore, if the app was already running, Windows would try to launch a whole new instance because we lacked single-instance handling. Even if the paths did make it through, Windows formats them with quotes and backslashes, which broke the frontend's file validation regex. To make matters worse, the frontend hook was trying to fetch and load these pending files immediately on mount, before the Python backend had actually finished starting up, resulting in a silent failure.
To fix all this, I added manual CLI argument parsing in the Tauri setup phase to catch files on cold starts, and integrated tauri-plugin-single-instance to intercept hot starts, route the file to the already running app, and bring the window into focus. I also wrote a path normalization helper in Rust (along with unit tests) to clean up quotes and convert backslashes to forward slashes before sending anything over IPC. On the frontend side, I updated useFileIO to wait until the backend status is explicitly marked as ready before trying to fetch and open the files. Finally, I tweaked the dev scripts to correctly forward CLI arguments so we can easily test this behavior locally. Resolves #248.