Skip to content
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

An attempt to fix the "double click" bug on MacOS #448

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,7 @@
native::ios::run(conf, f);
}
}

pub fn prevent_double_click_bug_on_macos() {
crate::native::apple::apple_util::prevent_double_click_bug_on_macos();

Check failure on line 393 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-pc-windows-gnu)

failed to resolve: could not find `apple` in `native`

Check failure on line 393 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, wasm32-unknown-unknown)

failed to resolve: could not find `apple` in `native`

Check failure on line 393 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu)

failed to resolve: could not find `apple` in `native`

Check failure on line 393 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, armv7-unknown-linux-gnueabihf)

failed to resolve: could not find `apple` in `native`

Check failure on line 393 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest, aarch64-unknown-linux-gnu)

failed to resolve: could not find `apple` in `native`

Check failure on line 393 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)

failed to resolve: could not find `apple` in `native`
}
36 changes: 36 additions & 0 deletions src/native/apple/apple_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,39 @@ pub extern "C" fn yes(_: &Object, _: Sel) -> BOOL {
pub extern "C" fn yes1(_: &Object, _: Sel, _: ObjcId) -> BOOL {
YES
}

static mut HACKED: bool = false;

pub fn define_app_delegate_class() -> *const Class {
let superclass = class!(NSObject);
let mut decl = ClassDecl::new("MyAppDelegate", superclass).unwrap();

unsafe {
decl.add_method(
sel!(applicationDidUpdate:),
application_did_update as extern "C" fn(&Object, Sel, ObjcId),
);
}

extern "C" fn application_did_update(_this: &Object, _: Sel, _: ObjcId) {
unsafe {
if !HACKED {
HACKED = true;
let current_application: ObjcId =
msg_send![class!(NSRunningApplication), currentApplication];
let _: BOOL = msg_send![current_application, activateWithOptions: nil];
}
}
}

return decl.register();
}

pub fn prevent_double_click_bug_on_macos() {
unsafe {
let app_delegate_class = define_app_delegate_class();
let app_delegate_instance: ObjcId = msg_send![app_delegate_class, new];
let ns_app: ObjcId = msg_send![class!(NSApplication), sharedApplication];
let () = msg_send![ns_app, setDelegate: app_delegate_instance];
}
}
Loading