Skip to content

Conversation

pentamassiv
Copy link
Collaborator

Xcode provides a tool called the “Main Thread Checker” which verifies that UI APIs are being used from the correct thread. More information can be found here: https://developer.apple.com/documentation/xcode/diagnosing-memory-thread-and-crash-issues-early#Detect-improper-UI-updates-on-background-threads

Tauri crashes when enigo is not used on the main thread. With this tool, we can make sure everything runs on the correct thread

@pentamassiv pentamassiv force-pushed the ci_macos_main_thread branch from 274306f to f3fa6a3 Compare March 26, 2025 00:58
@pentamassiv pentamassiv marked this pull request as draft March 26, 2025 11:05
@pentamassiv
Copy link
Collaborator Author

pentamassiv commented Mar 26, 2025

I think there should be warnings. I thought that the tests run in individual threads. It might be a good idea to add a Tauri example and make sure it doesn't crash even if enigo is used in a new thread (see tauri-apps/tauri#6421 (comment))

…ect thread

Xcode provides a tool called the “Main Thread Checker” which verifies that UI APIs are being used from the correct thread
@pentamassiv pentamassiv force-pushed the ci_macos_main_thread branch 3 times, most recently from 689ecef to 0cfe2be Compare August 23, 2025 21:34
@pentamassiv
Copy link
Collaborator Author

I just cannot get it to work. The MainThreadChecker runs and throws an error as expected if the integration_browser test gets replaced with (source):

//! Run [NSView new] on a separate thread, which should get caught by the
//! main thread checker.
use objc2::rc::Id;
use objc2::runtime::AnyObject;
use objc2::{class, msg_send_id};

#[link(name = "AppKit", kind = "framework")]
unsafe extern "C" {}

#[test]
fn integration_browser_events() {
    std::thread::scope(|s| {
        s.spawn(|| {
            // Note: Usually you'd use `icrate::NSView::new`, this is to
            // avoid the heavy dependency.
            let _: Id<AnyObject> = unsafe { msg_send_id![class!(NSView), new] };
        });
    });
}

But it does not fail when I try to run enigo functions in another thread. I would expect it to fail then too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant