Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Add HTTP protocol support (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanglam2807 authored Feb 26, 2021
1 parent 4fe4ce9 commit 7008c9b
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 295 deletions.
22 changes: 20 additions & 2 deletions Sources/WebkitWrapper/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class WindowDelegate: NSObject, NSWindowDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate {
let window = NSWindow()
let windowDelegate = WindowDelegate()
let webView = WKWebView(frame: .zero)
var didHandleHTTPProtocol = false

func webView(_: WKWebView, createWebViewWith: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
// If the target of the navigation is a new window, this property is nil
Expand Down Expand Up @@ -189,7 +191,6 @@ class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKUIDe
window.makeKeyAndOrderFront(window)

// WebView
let webView = WKWebView(frame: window.frame)
webView.navigationDelegate = self
webView.uiDelegate = self
webView.allowsBackForwardNavigationGestures = true
Expand All @@ -200,11 +201,28 @@ class AppDelegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKUIDe
if #available(macOS 10.11, *) {
webView.customUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Safari/605.1.15"
}
webView.load(URLRequest(url: jsonData.url!))
if (!didHandleHTTPProtocol) {
webView.load(URLRequest(url: jsonData.url!))
}

NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
}

func application(_ application: NSApplication, open urls: [URL]) {
guard
urls.count == 1,
let firstUrl = urls.first
else {
let alert = NSAlert()
alert.informativeText = "The app can only open one URL at the time."
alert.runModal()
return
}

didHandleHTTPProtocol = true
webView.load(URLRequest(url: firstUrl))
}
}

let app = NSApplication.shared
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webkit-wrapper",
"version": "1.0.1",
"minimumWebCatalogVersion": "27.0.0",
"minimumWebCatalogVersion": "29.0.0",
"main": "package.js",
"repository": "https://github.com/webcatalog/webkit-wrapper.git",
"author": "Quang Lam <[email protected]>",
Expand All @@ -14,13 +14,13 @@
"lint": "eslint package.js --ext js"
},
"devDependencies": {
"eslint": "7.2.0",
"eslint": "7.20.0",
"eslint-config-airbnb": "18.2.1",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-react": "7.21.5",
"eslint-plugin-react-hooks": "4.0.0",
"fs-extra": "9.0.1",
"eslint-plugin-react": "7.22.0",
"eslint-plugin-react-hooks": "4.2.0",
"fs-extra": "9.1.0",
"hasha": "5.2.2"
}
}
Loading

0 comments on commit 7008c9b

Please sign in to comment.