load popup in app window
This commit is contained in:
parent
f30e7352a4
commit
fda37716a8
|
@ -18,6 +18,7 @@
|
|||
27E5E9AE22F3D5FE005EA1D9 /* script.js in Resources */ = {isa = PBXBuildFile; fileRef = 27E5E9AD22F3D5FE005EA1D9 /* script.js */; };
|
||||
27E5E9B022F3D5FE005EA1D9 /* ToolbarItemIcon.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 27E5E9AF22F3D5FE005EA1D9 /* ToolbarItemIcon.pdf */; };
|
||||
27E5E9B422F3D5FE005EA1D9 /* safari.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 27E5E9A022F3D5FE005EA1D9 /* safari.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
27E5E9BC22F4B9D5005EA1D9 /* app in Resources */ = {isa = PBXBuildFile; fileRef = 27E5E9BB22F4B9D5005EA1D9 /* app */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -61,6 +62,7 @@
|
|||
27E5E9AD22F3D5FE005EA1D9 /* script.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = script.js; sourceTree = "<group>"; };
|
||||
27E5E9AF22F3D5FE005EA1D9 /* ToolbarItemIcon.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = ToolbarItemIcon.pdf; sourceTree = "<group>"; };
|
||||
27E5E9B122F3D5FE005EA1D9 /* safari.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = safari.entitlements; sourceTree = "<group>"; };
|
||||
27E5E9BB22F4B9D5005EA1D9 /* app */ = {isa = PBXFileReference; lastKnownFileType = folder; path = app; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -125,6 +127,7 @@
|
|||
27E5E9A422F3D5FE005EA1D9 /* safari */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
27E5E9BB22F4B9D5005EA1D9 /* app */,
|
||||
27E5E9A522F3D5FE005EA1D9 /* SafariExtensionHandler.swift */,
|
||||
27E5E9A722F3D5FE005EA1D9 /* SafariExtensionViewController.swift */,
|
||||
27E5E9A922F3D5FE005EA1D9 /* SafariExtensionViewController.xib */,
|
||||
|
@ -231,6 +234,7 @@
|
|||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
27E5E9BC22F4B9D5005EA1D9 /* app in Resources */,
|
||||
27E5E9B022F3D5FE005EA1D9 /* ToolbarItemIcon.pdf in Resources */,
|
||||
27E5E9AB22F3D5FE005EA1D9 /* SafariExtensionViewController.xib in Resources */,
|
||||
27E5E9AE22F3D5FE005EA1D9 /* script.js in Resources */,
|
||||
|
|
Binary file not shown.
|
@ -7,13 +7,52 @@
|
|||
//
|
||||
|
||||
import SafariServices
|
||||
import WebKit
|
||||
|
||||
class SafariExtensionViewController: SFSafariExtensionViewController {
|
||||
class SafariExtensionViewController: SFSafariExtensionViewController, WKScriptMessageHandler, WKNavigationDelegate {
|
||||
|
||||
var webView: WKWebView!
|
||||
|
||||
static let shared: SafariExtensionViewController = {
|
||||
let shared = SafariExtensionViewController()
|
||||
shared.preferredContentSize = NSSize(width:320, height:240)
|
||||
shared.preferredContentSize = NSSize(width:375, height:600)
|
||||
return shared
|
||||
}()
|
||||
|
||||
func initWebView() {
|
||||
let parentHeight = SafariExtensionViewController.shared.preferredContentSize.height
|
||||
let parentWidth = SafariExtensionViewController.shared.preferredContentSize.width
|
||||
let webViewConfig = WKWebViewConfiguration()
|
||||
let bundleURL = Bundle.main.resourceURL!.absoluteURL
|
||||
let html = bundleURL.appendingPathComponent("app/popup/index.html")
|
||||
webViewConfig.preferences.setValue(true, forKey: "developerExtrasEnabled")
|
||||
webViewConfig.userContentController.add(self, name: "webViewOnLoad")
|
||||
webView = WKWebView(frame: CGRect(x: 0, y: 0, width: parentWidth, height: parentHeight), configuration: webViewConfig)
|
||||
webView.navigationDelegate = self
|
||||
webView.allowsLinkPreview = false
|
||||
webView.loadFileURL(html, allowingReadAccessTo:bundleURL)
|
||||
webView.alphaValue = 0.0;
|
||||
self.view.addSubview(webView)
|
||||
}
|
||||
|
||||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
||||
NSAnimationContext.runAnimationGroup({_ in
|
||||
NSAnimationContext.current.duration = 0.35
|
||||
webView.animator().alphaValue = 1.0
|
||||
})
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
let backgroundColor = NSColor.init(red: (39/255.0), green: (42/255.0), blue: (46/255.0), alpha: 1.0)
|
||||
view.setValue(backgroundColor, forKey: "backgroundColor")
|
||||
initWebView()
|
||||
}
|
||||
|
||||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
if message.name == "webViewOnLoad" {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html class="safari">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Bitwarden</title>
|
||||
<base href="">
|
||||
<link href="main.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<app-root>
|
||||
<div id="loading"><i class="fa fa-spinner fa-spin fa-3x"></i></div>
|
||||
</app-root>
|
||||
<script type="text/javascript" src="../vendor.js"></script>
|
||||
<script type="text/javascript" src="../background.js"></script>
|
||||
<script type="text/javascript" src="vendor.js"></script>
|
||||
<script type="text/javascript" src="main.js"></script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue