Skip to content

Commit 7e616a3

Browse files
committed
Fix: Resolve Tauri Error 1412 (Chrome_WidgetWin_0) on Windows 11
- Add tauri-plugin-single-instance to prevent multiple WebView2 instances - Configure single-instance behavior to focus existing window - Add window label and skipTaskbar configuration for proper lifecycle - This fixes the window closing prematurely before connecting to backend Fixes #1147
1 parent d58083e commit 7e616a3

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

frontend/src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ tauri-plugin-process = "2.3.1"
3737
tauri-plugin-store = "2.4.1"
3838
tauri-plugin-updater = "2.9.0"
3939
tauri-plugin-opener = "2.5.2"
40+
tauri-plugin-single-instance = "2.3.1"
4041

4142
[features]
4243
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!

frontend/src-tauri/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ fn prod(_app: &tauri::AppHandle, _resource_path: &std::path::Path) -> Result<(),
190190

191191
fn main() {
192192
tauri::Builder::default()
193+
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
194+
// When a second instance is launched, focus the primary instance's window
195+
let windows = app.webview_windows();
196+
windows
197+
.values()
198+
.next()
199+
.expect("no window found")
200+
.set_focus()
201+
.expect("failed to set focus");
202+
}))
193203
.plugin(tauri_plugin_opener::init())
194204
.plugin(tauri_plugin_updater::Builder::new().build())
195205
.plugin(tauri_plugin_store::Builder::new().build())

frontend/src-tauri/tauri.conf.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"app": {
4747
"windows": [
4848
{
49+
"label": "main",
4950
"title": "PictoPy",
5051
"width": 800,
5152
"height": 600,
@@ -54,6 +55,7 @@
5455
"resizable": true,
5556
"fullscreen": false,
5657
"maximized": false,
58+
"skipTaskbar": false,
5759
"devtools": true
5860
}
5961
],

0 commit comments

Comments
 (0)