CI/CD / preconditions (pull_request) Successful in 1s
Native JavaScript checks / Native launcher and release tests (pull_request) Successful in 1m2s
macOS checks / Native Rust tests and unsigned build (pull_request) Successful in 1m38s
CI/CD / test_and_check_app (pull_request) Successful in 6m47s
CI/CD / Publish immutable image (pull_request) Skipped
48 lines
2.2 KiB
Objective-C
48 lines
2.2 KiB
Objective-C
#import <WebKit/WebKit.h>
|
|
|
|
typedef char *(*SettingsCallback)(const char *, const char *, const char *, bool);
|
|
typedef void (*SettingsFree)(char *);
|
|
|
|
@interface KanbanSettingsHandler : NSObject <WKScriptMessageHandlerWithReply>
|
|
@property(nonatomic, weak) WKWebView *webview;
|
|
@property(nonatomic, copy) NSString *label;
|
|
@property(nonatomic) SettingsCallback callback;
|
|
@property(nonatomic) SettingsFree releaseReply;
|
|
@end
|
|
|
|
@implementation KanbanSettingsHandler
|
|
- (void)userContentController:(WKUserContentController *)controller
|
|
didReceiveScriptMessage:(WKScriptMessage *)message
|
|
replyHandler:(void (^)(id, NSString *))replyHandler {
|
|
if (message.webView != self.webview || !message.frameInfo.isMainFrame ||
|
|
![message.body isKindOfClass:NSString.class]) {
|
|
replyHandler(nil, @"untrustedFrame");
|
|
return;
|
|
}
|
|
char *reply = self.callback(self.label.UTF8String,
|
|
message.frameInfo.request.URL.absoluteString.UTF8String,
|
|
[(NSString *)message.body UTF8String], message.frameInfo.isMainFrame);
|
|
if (!reply) { replyHandler(nil, @"bridgeUnavailable"); return; }
|
|
NSString *value = [NSString stringWithUTF8String:reply];
|
|
self.releaseReply(reply);
|
|
replyHandler(value, nil);
|
|
}
|
|
@end
|
|
|
|
void install_workspace_settings(void *pointer, const char *label, const char *script,
|
|
SettingsCallback callback, SettingsFree releaseReply) {
|
|
WKWebView *webview = (__bridge WKWebView *)pointer;
|
|
KanbanSettingsHandler *handler = [KanbanSettingsHandler new];
|
|
handler.webview = webview;
|
|
handler.label = [NSString stringWithUTF8String:label];
|
|
handler.callback = callback;
|
|
handler.releaseReply = releaseReply;
|
|
[webview.configuration.userContentController addScriptMessageHandlerWithReply:handler
|
|
contentWorld:WKContentWorld.pageWorld name:@"kanbanSettings"];
|
|
[webview.configuration.userContentController addUserScript:[[WKUserScript alloc]
|
|
initWithSource:[NSString stringWithUTF8String:script]
|
|
injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]];
|
|
// The initial document may already have started loading before the handler is attached.
|
|
[webview evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:nil];
|
|
}
|