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] Refresh the page WebviewWindow.getByLabel returns inaccurate results. #5380
Comments
This is probably related to #5191 and being fixed in #5456 but using const existedWindow = WebviewWindow.getByLabelUnchecked('google-window')
if (await existedWindow.isValid()) return |
try this: // creat a webviewWindow without check
new TauriWindow.WebviewWindow(label, options);
// close it by windowManager and create it again
new TauriWindow.WindowManager(label).close().then(() => {
new TauriWindow.WebviewWindow(label, options);
}); |
I have a problem with closing created windows after refresh. I use WebviewWindow.getByLabel to get the window and then try to close it but function doesn't return it - it doesn't exist. Is there solution to this? |
Here is what I use now: #[tauri::command]
async fn create_window(app_handle: tauri::AppHandle, label: String, mut option: WindowConfig) {
let window_old = app_handle.get_window(&label);
option.label = label.clone();
if window_old.is_some() {
dbg!("window exists");
window_old.unwrap().close().unwrap();
return;
}
let window_new =
Some(WindowBuilder::from_config(&app_handle, option).build().expect("failed to create window"));
window_new.unwrap();
} export function createTGWindow(
url: string,
label: string,
title: string,
width: number,
height: number,
resizable: boolean,
visible: boolean = true,
): void {
// 计算窗口位置
const left = (window.screen.width - width) / 2;
const top = (window.screen.height - height) / 2;
const option: WindowOptions = {
height,
width,
resizable,
url,
title,
visible,
x: left,
y: top,
};
const isGet = TauriWindow.WebviewWindow.getByLabel(label);
if (isGet === null) {
invoke("create_window", { label, option })
.then(() => {
createTGWindow(url, label, title, width, height, resizable, visible);
})
.catch((err) => {
console.error(err);
});
} else {
isGet
.close()
.then(() => {
invoke("create_window", { label, option })
.then(() => {
console.log(`[createTGWindow][${label}] ${title} created.`);
})
.catch((err) => {
console.error(err);
});
})
.catch((err) => {
console.error(err);
});
}
} |
This problem still exist at the name = "tauri" |
is there any fix or hack aroud the issue already |
The hack is that you create a hidden window on app init through config and then when needed you show it. That way you are not losing its handler. |
Thanks mate! I've been fighting it for some time. I'm going to try this out |
Describe the bug
10.10.mp4
Create a window through the
new WebviewWindow
method, After refreshing the page, the result returned byWebviewWindow.getByLabel
is inaccurate.Reproduction
Expected behavior
No response
Platform and versions
Stack trace
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: