Skip to content

Commit 828c847

Browse files
authored
fix: set up hotkey on main thread or Windows will complain (#879)
Coco panicked on Windows when I was testing the applications-rs crate on Windows, the error message seemingly indicates that we should run hotkey setup on the main thread, and doing that indeed fixes the issue, so let's do it.
1 parent 5dae5d1 commit 828c847

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

docs/content.en/docs/release-notes/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Information about release notes of Coco App is provided here.
2525

2626
- fix: fix issue with update check failure #833
2727
- fix: web component login state #857
28+
- fix: set up hotkey on main thread or Windows will complain #879
29+
2830

2931
### ✈️ Improvements
3032

src-tauri/src/setup/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ pub(crate) async fn backend_setup(tauri_app_handle: AppHandle, app_lang: String)
7777
// This has to be called before initializing extensions as doing that
7878
// requires access to the shortcut store, which will be set by this
7979
// function.
80-
crate::shortcut::enable_shortcut(&tauri_app_handle);
80+
//
81+
//
82+
// Windows requires that hotkey setup has to be done on the main thread, or
83+
// we will get error "ERROR_WINDOW_OF_OTHER_THREAD 1408 (0x580)"
84+
let tauri_app_handle_clone = tauri_app_handle.clone();
85+
tauri_app_handle
86+
.run_on_main_thread(move || {
87+
crate::shortcut::enable_shortcut(&tauri_app_handle_clone);
88+
})
89+
.expect("failed to run this closure on the main thread");
8190

8291
crate::init(&tauri_app_handle).await;
8392

0 commit comments

Comments
 (0)