tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
797 stars 222 forks source link

`tauri-window-save-state` causes runtime panic when using `tauri-nspanel` #1546

Open Hacksore opened 1 month ago

Hacksore commented 1 month ago

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

ahkohd commented 1 month ago

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.

ahkohd commented 1 month ago

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

ahkohd commented 1 month ago

one more thing,

@Hacksore when calling saveWindowState, you will have to exclude MAXIMIZED

image
ahkohd commented 1 month ago

Here is the patch PR: https://github.com/tauri-apps/plugins-workspace/pull/1547

Hacksore commented 1 month ago

@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

ahkohd commented 1 month ago

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

@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.

Hacksore commented 1 month ago

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

ahkohd commented 1 month ago

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

@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 (#1547) updates the implementation to call window.is_maximised only if maximized is set in the state flags.

I need to open same PR for the v2 plugin as well.