Discover the magic of +whole-archive to avoid relying on hacks to load the objective-C++ code in webview native

This commit is contained in:
PJB3005
2026-01-04 04:07:00 +01:00
parent 89b6bcd8e2
commit d9740e3a4f
3 changed files with 5 additions and 19 deletions

View File

@@ -10,6 +10,8 @@ fn main() {
.cpp(true)
.flag("--std=c++17")
.file("src/mac_application.mm")
.link_lib_modifier("+whole-archive")
.warnings(false)
.compile("mac_application");
println!("cargo::rerun-if-changed=src/mac_application.mm");

View File

@@ -1,10 +1 @@
#[cfg(target_os = "macos")]
unsafe extern "C" {
fn get_swizzled_idiot();
}
// Not actually called but I need a chain of reference so that the objc code is compiled in.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn rt_native_webview_init() {
unsafe { get_swizzled_idiot() };
}

View File

@@ -1,7 +1,7 @@
#import <Cocoa/Cocoa.h>
#include <objc/runtime.h>
#include <cstdio>
// #include <cstdio>
#include "include/cef_application_mac.h"
@@ -32,21 +32,14 @@ bool g_handling_send_event = false;
}
- (void)setHandlingSendEvent:(BOOL)handlingSendEvent {
printf("setHandlingSendEvent: %i\n", (int) handlingSendEvent);
// printf("setHandlingSendEvent: %i\n", (int) handlingSendEvent);
g_handling_send_event = handlingSendEvent;
}
- (void)_swizzled_sendEvent:(NSEvent*)event {
printf("send it");
// printf("send it\n");
CefScopedSendingEvent sendingEventScoper;
[self _swizzled_sendEvent:event];
}
@end
extern "C" {
void get_swizzled_idiot() {
NSApplication* app = [NSApplication sharedApplication];
[app isHandlingSendEvent];
}
}