tauri
tauri copied to clipboard
[bug][macOS] After exiting the fullscreen, read window still is fullscreen
Describe the bug
After exiting the fullscreen, below to the code print true
tauri::WindowEvent::Resized(_) => {
println!("is_fullscreen {:?}", event.window().is_fullscreen());
}

Similarly, JS API does not meet expectations:
await window.__TAURI__?.window.getCurrent().isFullscreen()
Reproduction
- clone https://github.com/mantou132/tauri-app-test
- cargo tauri dev
- enter fullscreen and exiting fullscreen
- view console
Expected behavior
print:
is_fullscreen Ok(true)
is_fullscreen Ok(false)
Platform and versions
Environment
› OS: Mac OS 12.4.0 X64
› Node.js: 18.3.0
› npm: 8.11.0
› pnpm: 6.11.0
› yarn: 1.22.15
› rustup: 1.24.3
› rustc: 1.63.0-nightly
› cargo: 1.63.0-nightly
› Rust toolchain: nightly-x86_64-apple-darwin
Packages
› @tauri-apps/cli [NPM]: 1.0.0
› @tauri-apps/api [NPM]: 1.0.0-rc.7
Stack trace
No response
Additional context
No response
tauri::WindowEvent::Resized(size) => {
let monitor = event.window().current_monitor().unwrap().unwrap();
let screen = monitor.size();
println!("{:?}, {:?}", size, screen);
if size == screen {
println!("{}", true);
} else {
println!("{}", false);
}
}
This code result meets expectations
This happens because the resized event is emitted before macOS notifies tao that the window has been changed to fullscreen. Maybe we could immediately set the new fullscreen state in tao @amrbashir @wusyong
tauri::WindowEvent::Resized(size) => { let monitor = event.window().current_monitor().unwrap().unwrap(); let screen = monitor.size(); println!("{:?}, {:?}", size, screen); if size == screen { println!("{}", true); } else { println!("{}", false); } }
This code result meets expectations
@mantou132 Doesn't work on new MBP with notch :(
This code works, but it's really not a good solution.
// main.rs
tauri::Builder::default()
.on_window_event(|event| match event.event() {
tauri::WindowEvent::Resized(_) => {
event.window().emit_all("resize", "").unwrap();
}
_ => {}
})
// .setup
import { appWindow } from '@tauri-apps/api/window'
let isFullscreen = false
let resizeTimeout = 0
appWindow.listen('resize', async () => {
await new Promise((resolve) => {
window.clearTimeout(resizeTimeout)
resizeTimeout = window.setTimeout(resolve, 6e2)
})
// set the value
isFullscreen = await appWindow.isFullscreen()
})
@mvrlin now need listen WindowEvent::Moved(_)
https://github.com/mantou132/nesbox/blob/dev/packages/tauriapp/src/main.rs#L48
@lucasfernog can you fix the delay?
Which delay @mvrlin ? We need to fix this issue directly :)
@lucasfernog By delay I meant update fullscreen state before the resize event 😀
I was able to resolve this in my own Vue app by storing the previous value of isFullscreen
and simply setting my local value to false
if the previous value was true
, indicating that fullscreen was exited:
import { appWindow } from '@tauri-apps/api/window';
import { onMounted, ref } from "@nuxtjs/composition-api";
export default {
setup() {
const isFullscreen = ref(false);
const previousIsFullscreen = ref(false);
const updateFullscreen = async () => {
previousIsFullscreen.value = isFullscreen.value;
previousIsFullscreen.value === true
? (isFullscreen.value = false)
: (isFullscreen.value = await appWindow.isFullscreen());
};
appWindow.onResized(_.debounce(updateFullscreen, 500));
onMounted(updateFullscreen);
return { appWindow, isFullscreen };
},
};
@stevebauman you are doing the same thing as me, you are calling a function after 500ms. The goal was to make Tauri resolve the Promise when the system event actually happened.