plugins-workspace
plugins-workspace copied to clipboard
`tauri-window-save-state` causes runtime panic when using `tauri-nspanel`
So I setup this repro but tl;dr if you leave the window save state plugin enabled this repro will crash when you go to access the NSPanel.
https://github.com/Hacksore/tauri-window-save-state-bug
I've removed everything to be super straight to the issue so follow the readme and you can reproduce.
Unsure of what the issue is but here is the short stacktrace and you can find the full one in the repro.
Finished `dev` profile [unoptimized + debuginfo] target(s) in 9.16s
thread 'main' panicked at /Users/hacksore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cocoa-0.24.1/src/appkit.rs:1183:9:
Uncaught exception <NSException: 0x6000016f6940>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
libc++abi: terminating due to uncaught foreign exception
This happens in dev and release modes so not sure what's going on. cc @ahkohd (creator of the tauri-nspanel).
related issues: https://github.com/overlayeddev/overlayed/issues/152 https://github.com/Hacksore/tauri-window-save-state-bug/issues/1
Since the NSWindow has been converted to NSPanel, you can no longer call the window.is_maximised or maximise the window anymore.
You can't maximise a panel.
https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L236
this line calls maximise on the window(panel), hence why it crashed.
https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L235
this line needs to be refactored.
such that self.is_maximized is only called if and only if the state flag includes MAXIMIZED
one more thing,
@Hacksore when calling saveWindowState, you will have to exclude MAXIMIZED
Here is the patch PR: https://github.com/tauri-apps/plugins-workspace/pull/1547
@ahkohd I just pushed this which unblocks the app from crashing immediately on startup. https://github.com/Hacksore/tauri-window-save-state-bug/commit/79ca7f4e2d4fb01af2feb98f0215f296e4e9f634
However, hitting the in app close button will still cause a panic. I thought only selecting flags POSITION and SIZE would work?
https://github.com/Hacksore/tauri-window-save-state-bug/blob/79ca7f4e2d4fb01af2feb98f0215f296e4e9f634/src/App.tsx#L12-L13
https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L235
this line needs to be refactored.
such that
self.is_maximizedis only called if and only if the state flag includesMAXIMIZED
@Hacksore please read this comment.
In the window state plugin, as it is currently, if you set size or maximized flag, window.is_maximised() is called, and this will crash the panel.
This PR (https://github.com/tauri-apps/plugins-workspace/pull/1547) updates the implementation to call window.is_maximised only if maximized is set in the state flags.
Yep, we are blocked here until they can review/merge your open PR.
In the meantime I just forked the repo and made the same you did. https://github.com/overlayeddev/overlayed/commit/f3359fdcf24d5d73b1f4f66f988b4c9b7d0c09e9
https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L235
this line needs to be refactored. such that
self.is_maximizedis only called if and only if the state flag includesMAXIMIZED@Hacksore please read this comment.
In the window state plugin, as it is currently, if you set
sizeormaximizedflag,window.is_maximised()is called, and this will crash thepanel.This PR (#1547) updates the implementation to call
window.is_maximisedonly if maximized is set in the state flags.
I need to open same PR for the v2 plugin as well.
@ahkohd I saw you closed that PR, was there issues getting it merged upstream?
Seems there were some challenges getting this patched in https://github.com/tauri-apps/plugins-workspace/pull/1568 and instead fixing in tao.
I don't have that PR/issue for it but if it can be linked here that would be great.