@@ -19,7 +19,7 @@ private final class DashboardWindowDragRegionView: NSView {
|
19 | 19 | } |
20 | 20 | |
21 | 21 | @MainActor |
22 | | -final class DashboardWindowController: NSWindowController, WKNavigationDelegate, NSWindowDelegate { |
| 22 | +final class DashboardWindowController: NSWindowController, WKNavigationDelegate, WKUIDelegate, NSWindowDelegate { |
23 | 23 | private let webView: WKWebView |
24 | 24 | private var currentURL: URL |
25 | 25 | private var auth: DashboardWindowAuth |
@@ -44,9 +44,37 @@ final class DashboardWindowController: NSWindowController, WKNavigationDelegate,
|
44 | 44 | super.init(window: window) |
45 | 45 | |
46 | 46 | self.webView.navigationDelegate = self |
| 47 | +self.webView.uiDelegate = self |
47 | 48 | self.window?.delegate = self |
48 | 49 | } |
49 | 50 | |
| 51 | + // MARK: - WKUIDelegate |
| 52 | + |
| 53 | + /// Bridges `<input type="file">` clicks in the embedded Control UI to a native |
| 54 | + /// `NSOpenPanel`; without a `WKUIDelegate`, WebKit silently drops the request |
| 55 | + /// and "Choose image" / file-picker buttons do nothing. |
| 56 | +func webView( |
| 57 | + _ webView: WKWebView, |
| 58 | + runOpenPanelWith parameters: WKOpenPanelParameters, |
| 59 | + initiatedByFrame frame: WKFrameInfo, |
| 60 | + completionHandler: @escaping @MainActor @Sendable ([URL]?) -> Void) |
| 61 | +{ |
| 62 | +let panel = NSOpenPanel() |
| 63 | + panel.canChooseFiles = true |
| 64 | + panel.canChooseDirectories = parameters.allowsDirectories |
| 65 | + panel.allowsMultipleSelection = parameters.allowsMultipleSelection |
| 66 | + panel.resolvesAliases = true |
| 67 | +if let window = self.window { |
| 68 | + panel.beginSheetModal(for: window) { response in |
| 69 | +completionHandler(response == .OK ? panel.urls : nil) |
| 70 | +} |
| 71 | +return |
| 72 | +} |
| 73 | + panel.begin { response in |
| 74 | +completionHandler(response == .OK ? panel.urls : nil) |
| 75 | +} |
| 76 | +} |
| 77 | + |
50 | 78 | @available(*, unavailable) |
51 | 79 | required init?(coder: NSCoder) { |
52 | 80 | fatalError("init(coder:) is not supported") |
|