This commit is contained in:
Balazs Perlaki-Horvath 2024-10-31 21:09:49 +01:00 committed by Kelson
parent f85839d0df
commit 017315ae2f

View File

@ -347,6 +347,7 @@ final class BrowserViewModel: NSObject, ObservableObject,
// MARK: - New Tab Creation // MARK: - New Tab Creation
#if os(macOS) #if os(macOS)
@MainActor
private func createNewWindow(with url: URL) -> Bool { private func createNewWindow(with url: URL) -> Bool {
guard let currentWindow = NSApp.keyWindow, guard let currentWindow = NSApp.keyWindow,
let windowController = currentWindow.windowController else { return false } let windowController = currentWindow.windowController else { return false }
@ -536,6 +537,7 @@ final class BrowserViewModel: NSObject, ObservableObject,
return nil return nil
} }
#else #else
@MainActor
func webView( func webView(
_ webView: WKWebView, _ webView: WKWebView,
createWebViewWith configuration: WKWebViewConfiguration, createWebViewWith configuration: WKWebViewConfiguration,
@ -550,7 +552,6 @@ final class BrowserViewModel: NSObject, ObservableObject,
externalURL = newURL externalURL = newURL
return nil return nil
} }
NotificationCenter.openURL(newURL, inNewTab: true)
return nil return nil
} }
#endif #endif
@ -572,22 +573,24 @@ final class BrowserViewModel: NSObject, ObservableObject,
return WebViewController(webView: webView) return WebViewController(webView: webView)
}, },
actionProvider: { [weak self] _ in actionProvider: { [weak self] _ in
guard let self = self else { return UIMenu(children: []) } guard let self else { return UIMenu(children: []) }
var actions = [UIAction]() var actions = [UIAction]()
// open url // open url
actions.append( actions.append(
UIAction(title: "common.dialog.button.open".localized, UIAction(title: "common.dialog.button.open".localized,
image: UIImage(systemName: "doc.text")) { _ in image: UIImage(systemName: "doc.text")) { [weak self] _ in
webView.load(URLRequest(url: url)) self?.webView.load(URLRequest(url: url))
} }
) )
actions.append( actions.append(
UIAction(title: "common.dialog.button.open_in_new_tab".localized, UIAction(title: "common.dialog.button.open_in_new_tab".localized,
image: UIImage(systemName: "doc.badge.plus")) { [weak self] _ in image: UIImage(systemName: "doc.badge.plus")) { [weak self] _ in
guard let self = self else { return } guard let self else { return }
Task { @MainActor in
NotificationCenter.openURL(url, inNewTab: true) NotificationCenter.openURL(url, inNewTab: true)
} }
}
) )
// bookmark // bookmark