plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

[window-state] Only saving window position and not size (v2)

Open jaydevelopsstuff opened this issue 1 year ago • 7 comments

The window-state plugin (v2 off of crates.io) fails to save/restore window size (at least on MacOS, I haven't tested on any other operating systems).

MRE Repo (Just run the app, resize, close, relaunch, and observe the size not being restored)

I've seen some similarish looking issues but they've been closed and don't seem to be addressing the same problem. If this has already been fixed and is just finding its way to release let me know.

jaydevelopsstuff avatar Feb 02 '24 04:02 jaydevelopsstuff

Couldn't reproduce on Windows, can't really investigate macos

amrbashir avatar Feb 06 '24 02:02 amrbashir

I confirm. This error also occurs on my macOS

bartekc7 avatar Feb 29 '24 20:02 bartekc7

I find that this issue is caused by tauri::window::Window::inner_size() function. It always returns the width and height defined in tauri.conf.json but not the actual number of the current window size. image In the picture above, you'll find that the inner size is always 1024x768 which is the same as what in tauri.conf.json, but the outer size changes very differently. So, it seems to be a bug of tauri v2.0-beta... But it can be a simple workaround by changing it into self.outer_size(). https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/window-state/src/lib.rs#L269

legends-killer avatar Mar 14 '24 09:03 legends-killer

Hey guys, I found some PR related to this bug. https://github.com/tauri-apps/tauri/pull/8280/files#diff-9fff33774bba86e0056dc083e3ec624f275b9d05427031c76dc1b313ade17a82R736 In this PR, Tauri 2.0 beta supported multiple webviews in a single window, but some functions about get_webview were marked as unstable causing the get_size function to return an unexpected value without unstable feature. So, you just need to enable the unstable feature in Tauri's dependency and this plugin could work normally.

// enable unstable features
tauri = { version = "2.0.0-beta", features = ["unstable"] }

Finally, I'm not sure if the unstable flag should be removed in Tauri, so I just created a PR to this repo to update docs in v2 README to workaround it. https://github.com/tauri-apps/plugins-workspace/pull/1086

legends-killer avatar Mar 18 '24 05:03 legends-killer

I can confirm that this bug exists (MacOS). Maybe because the WindowEvent::Resized is missing from the code?

https://github.com/tauri-apps/plugins-workspace/blob/c013fa52cd66885cf457a64e75373cb2066bc849/plugins/window-state/src/lib.rs#L369-L388

roniemartinez avatar Apr 01 '24 12:04 roniemartinez

Can someone confirm whether this is still an issue in the rc version?

FabianLars avatar Aug 07 '24 15:08 FabianLars

I reproduced this issue in the plugin-workspace example. The window size state is saved in rc3. However, I found that the outer size height is being stored in the inner size.

1.

1

2.

2

3.

스크린샷 2024-10-03 오후 11 53 58

In my opinion, since the inner size =/= the total window size, the total window size should be stored when saving the window-state value.

        if flags.contains(StateFlags::SIZE) && !is_maximized && !is_minimized {
            let size = self.inner_size()?;
            let outer_size = self.outer_size().unwrap();
            println!("inner_size: {:?}", size);
            println!("outer_size: {:?}", self.outer_size()?);
            // It doesn't make sense to save a window with 0 height or width
            if size.width > 0 && size.height > 0 {
                state.width = outer_size.width; // inner -> outer
                state.height = outer_size.height; // inner -> outer
            }
        }

Zamoca42 avatar Oct 03 '24 14:10 Zamoca42

@amrbashir @FabianLars Hey👋, I used the plugin in tauri v2.0.2 and the terminal keeps outputting😱

.plugin(
    tauri_plugin_window_state::Builder::default()
        .with_state_flags(StateFlags::all() & !StateFlags::VISIBLE)
        .build(),
)

https://github.com/user-attachments/assets/405a2918-531e-488c-89dd-fbeb0bf39d0b

ayangweb avatar Oct 10 '24 05:10 ayangweb

On windows, when setting decorations to false, the window size is not preserved

ItsLhuis avatar Nov 28 '24 11:11 ItsLhuis

the project clash verge rev uses the window-state v2.2.0,but it can't save position and size on windows 10 and 11 https://github.com/clash-verge-rev/clash-verge-rev

loveuall3 avatar Dec 15 '24 03:12 loveuall3

It's confirmed that this issue can be reproduced in the Readest project on Windows but not on macOS. Btw, the window has no decorations on Windows but has decorations on macOS.

➜  readest-app git:(main) pnpm tauri info

> @readest/[email protected] tauri /Users/chrox/dev/readest/apps/readest-app
> tauri "info"

[✔] Environment
    - OS: Mac OS 14.3.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.82.0 (f6e511eec 2024-10-15)
    ✔ cargo: 1.82.0 (8f40fc59f 2024-08-21)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.9.0
    - pnpm: 9.15.0
    - yarn: 1.22.22
    - npm: 10.9.1

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.2
    - tao 🦀: 0.30.8
    - @tauri-apps/api : 2.1.1
    - @tauri-apps/cli : 2.1.0

[-] Plugins
    - tauri-plugin-os 🦀: 2.0.1
    - @tauri-apps/plugin-os : 2.0.0 (outdated, latest: 2.2.0)
    - tauri-plugin-dialog 🦀: 2.0.4
    - @tauri-apps/plugin-dialog : 2.0.1 (outdated, latest: 2.2.0)
    - tauri-plugin-log 🦀: 2.0.3
    - @tauri-apps/plugin-log : 2.0.1 (outdated, latest: 2.2.0)
    - tauri-plugin-cli 🦀: 2.0.1
    - @tauri-apps/plugin-cli : 2.0.0 (outdated, latest: 2.2.0)
    - tauri-plugin-http 🦀: 2.0.4
    - @tauri-apps/plugin-http : 2.0.1 (outdated, latest: 2.2.0)
    - tauri-plugin-shell 🦀: 2.0.2
    - @tauri-apps/plugin-shell : 2.0.1 (outdated, latest: 2.2.0)
    - tauri-plugin-fs 🦀: 2.1.0
    - @tauri-apps/plugin-fs : 2.0.3 (outdated, latest: 2.2.0)
    - tauri-plugin-process 🦀: 2.0.1
    - @tauri-apps/plugin-process : 2.0.0 (outdated, latest: 2.2.0)
    - tauri-plugin-updater 🦀: 2.1.0
    - @tauri-apps/plugin-updater : 2.0.0 (outdated, latest: 2.3.0)

[-] App
    - build-type: bundle
    - CSP: frame-src 'self' blob: asset: http://asset.localhost; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: asset: http://asset.localhost https://*.sentry.io https://*.posthog.com; default-src 'self' 'unsafe-inline' blob: customprotocol: asset: http://asset.localhost ipc: http://ipc.localhost https://fonts.gstatic.com https://db.onlinewebfonts.com; connect-src 'self' blob: asset: http://asset.localhost ipc: http://ipc.localhost https://*.sentry.io https://*.posthog.com https://*.deepl.com https://*.wikipedia.org https://*.wiktionary.org https://*.supabase.co; img-src 'self' blob: data: asset: http://asset.localhost https://*; style-src 'self' 'unsafe-inline' blob: asset: http://asset.localhost
    - frontendDist: ../out
    - devUrl: http://localhost:3000/
    - framework: React (Next.js)
    - bundler: Webpack

chrox avatar Dec 18 '24 15:12 chrox

I find it's not saving anything about the position at all (macos).

ekwoka avatar Feb 04 '25 17:02 ekwoka