Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] isMaximized seems to trigger resize event #5812

Open
ottosson opened this issue Dec 11, 2022 · 2 comments
Open

[bug] isMaximized seems to trigger resize event #5812

ottosson opened this issue Dec 11, 2022 · 2 comments
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@ottosson
Copy link

ottosson commented Dec 11, 2022

Describe the bug

I'm checking isMaximized with the resize event. This seems to trigger an infinite loop of sorts since I can see thousands of console.logs instead of one per pixel (or whatever). I have window decorations set to false in tauri.conf.

  useEffect(() => {
    let unlisten: UnlistenFn;
    const window = getCurrent();

    listen("tauri://resize", async () => {
      console.log("resize");
      const _isWindowMaximized = await window.isMaximized();
      //...
    }).then((data) => {
      unlisten = data;
    });

    return () => {
      if (unlisten != null) {
        unlisten();
      }
    };
  }, []);

Removing the isMaximized or trying with some other functions on window does not result in the same behaviour.

I've tested on Macos and Windows and it seems it works just fine on Windows.

Reproduction

use window.isMaximized() in listen("tauri://resize")

Expected behavior

No response

Platform and versions

Environment
› OS: Mac OS 13.0.0 X64
› Node.js: 18.5.0
› npm: 8.12.1
› pnpm: Not installed!
› yarn: 1.22.19
› rustup: 1.25.1
› rustc: 1.64.0
› cargo: 1.64.0
› Rust toolchain: stable-x86_64-apple-darwin

Packages
› @tauri-apps/cli [NPM]: 1.2.2
› @tauri-apps/api [NPM]: 1.2.0
› tauri [RUST]: 1.2.2,
› tauri-build [RUST]: 1.1.1,
› tao [RUST]: 0.15.7,
› wry [RUST]: 0.23.3,

App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:5173/
› framework: React
› bundler: Vite

App directory structure
├─ dist
├─ node_modules
├─ src-tauri
├─ .git
├─ .vscode
└─ src

Stack trace

No response

Additional context

No response

@ottosson ottosson added status: needs triage This issue needs to triage, applied to new issues type: bug labels Dec 11, 2022
@letrungdo
Copy link

I also have the same issue

@keadex
Copy link

keadex commented Nov 9, 2023

Same issue here. I also noticed, in my case, that this happens only in dev mode (tauri dev) and not in production (tauri build).

This issue makes it impossible to use isMaximized() in combination with onResized() (https://tauri.app/it/v1/api/js/window#onresized) on MacOS.

The only workaround I found is to use a flag to temporarily disable the onResized() callback during the isMaximized() execution:

const isOnResizedDisabled = useRef(true)

function isMaximizedWorkaround(){
 isOnResizedDisabled.current = true
 appWindow.isMaximized().then((isMaximized) => {
   isOnResizedDisabled.current = false
   // your stuff
 })
}

useEffect(() => {
 unlisten = appWindow.listen(TauriEvent.WINDOW_RESIZED, () => {
   if (!isOnResizedDisabled.current) {
     isMaximizedWorkaround()
   }
 })
 return () => {
   if (unlisten) unlisten.then((f) => f())
 }
}, [])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
Status: 📬Proposal
Development

No branches or pull requests

3 participants