fix: restore macOS navigation with unsaved forms
CI/CD / preconditions (pull_request) Successful in 6s
Native JavaScript checks / Native launcher and release tests (pull_request) Successful in 3m43s
macOS checks / Native Rust tests and unsigned build (pull_request) Canceled after 0s
CI/CD / Publish immutable image (pull_request) Canceled after 0s
CI/CD / test_and_check_app (pull_request) Canceled after 1m36s

This commit is contained in:
2026-10-15 08:56:29 +02:00
parent ba12e65e81
commit 1082b6ac82
9 changed files with 152 additions and 12 deletions
+49
View File
@@ -1,6 +1,55 @@
#import <AppKit/AppKit.h>
#import <WebKit/WebKit.h>
#import <objc/runtime.h>
@interface KanbanWorkspaceUIDelegate : NSObject <WKUIDelegate>
@property(nonatomic, strong) id<WKUIDelegate> originalDelegate;
@end
@implementation KanbanWorkspaceUIDelegate
- (BOOL)respondsToSelector:(SEL)selector {
return [super respondsToSelector:selector] || [self.originalDelegate respondsToSelector:selector];
}
- (id)forwardingTargetForSelector:(SEL)selector {
if ([self.originalDelegate respondsToSelector:selector]) {
return self.originalDelegate;
}
return [super forwardingTargetForSelector:selector];
}
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message
initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL))completionHandler {
NSWindow *window = webView.window;
if (!window || window.attachedSheet) {
completionHandler(NO);
return;
}
NSAlert *alert = [NSAlert new];
alert.alertStyle = NSAlertStyleWarning;
alert.messageText = frame.request.URL.host ?: @"KanbanGit";
alert.informativeText = message;
[alert addButtonWithTitle:@"OK"];
[alert addButtonWithTitle:@"Cancel"];
[alert beginSheetModalForWindow:window completionHandler:^(NSModalResponse response) {
completionHandler(response == NSAlertFirstButtonReturn);
}];
}
@end
static char workspaceUIDelegateKey;
void install_workspace_navigation(void *pointer) {
WKWebView *webview = (__bridge WKWebView *)pointer;
webview.allowsBackForwardNavigationGestures = YES;
if ([webview.UIDelegate isKindOfClass:KanbanWorkspaceUIDelegate.class]) {
return;
}
KanbanWorkspaceUIDelegate *delegate = [KanbanWorkspaceUIDelegate new];
delegate.originalDelegate = webview.UIDelegate;
// WKWebView keeps a weak UI delegate, so retain the forwarding adapter with its view.
objc_setAssociatedObject(webview, &workspaceUIDelegateKey, delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
webview.UIDelegate = delegate;
}