Open mantou132 opened 2 years ago
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.
Describe the bug
After exiting the fullscreen, below to the code print
true
Similarly, JS API does not meet expectations:
Reproduction
Expected behavior
print:
Platform and versions
Stack trace
No response
Additional context
No response