-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from zhangferry/develop
Develop
- Loading branch information
Showing
44 changed files
with
1,758 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ build/ | |
.vscode/ | ||
.DS_Store | ||
.env | ||
*.log | ||
*.log | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
safari/SummarAI/Shared (App)/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
safari/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "logo-1024.png", | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"filename" : "[email protected]", | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+261 KB
safari/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/logo-1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.3 KB
...ri/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.4 KB
...ri/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+759 Bytes
safari/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.88 KB
safari/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+32.4 KB
...ri/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.7 KB
...ri/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.88 KB
safari/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.12 KB
safari/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+87.7 KB
...ri/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+250 KB
...ri/SummarAI/Shared (App)/Assets.xcassets/AppIcon.appiconset/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
safari/SummarAI/Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x", | ||
"filename" : "logo-128.png" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+14.7 KB
safari/SummarAI/Shared (App)/Assets.xcassets/LargeIcon.imageset/logo-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'"> | ||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> | ||
|
||
<link rel="stylesheet" href="../Style.css"> | ||
<script src="../Script.js" defer></script> | ||
</head> | ||
<body> | ||
<img src="../Icon.png" width="128" height="128" alt="SummarAI Icon"> | ||
<p class="platform-ios">You can turn on SummarAI’s Safari extension in Settings.</p> | ||
<p class="platform-mac state-unknown">You can turn on SummarAI’s extension in Safari Extensions preferences.</p> | ||
<p class="platform-mac state-on">SummarAI’s extension is currently on. You can turn it off in Safari Extensions preferences.</p> | ||
<p class="platform-mac state-off">SummarAI’s extension is currently off. You can turn it on in Safari Extensions preferences.</p> | ||
<button class="platform-mac open-preferences">Quit and Open Safari Extensions Preferences…</button> | ||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function show(platform, enabled, useSettingsInsteadOfPreferences) { | ||
document.body.classList.add(`platform-${platform}`); | ||
|
||
if (useSettingsInsteadOfPreferences) { | ||
document.getElementsByClassName('platform-mac state-on')[0].innerText = "SummarAI’s extension is currently on. You can turn it off in the Extensions section of Safari Settings."; | ||
document.getElementsByClassName('platform-mac state-off')[0].innerText = "SummarAI’s extension is currently off. You can turn it on in the Extensions section of Safari Settings."; | ||
document.getElementsByClassName('platform-mac state-unknown')[0].innerText = "You can turn on SummarAI’s extension in the Extensions section of Safari Settings."; | ||
document.getElementsByClassName('platform-mac open-preferences')[0].innerText = "Quit and Open Safari Settings…"; | ||
} | ||
|
||
if (typeof enabled === "boolean") { | ||
document.body.classList.toggle(`state-on`, enabled); | ||
document.body.classList.toggle(`state-off`, !enabled); | ||
} else { | ||
document.body.classList.remove(`state-on`); | ||
document.body.classList.remove(`state-off`); | ||
} | ||
} | ||
|
||
function openPreferences() { | ||
webkit.messageHandlers.controller.postMessage("open-preferences"); | ||
} | ||
|
||
document.querySelector("button.open-preferences").addEventListener("click", openPreferences); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
* { | ||
-webkit-user-select: none; | ||
-webkit-user-drag: none; | ||
cursor: default; | ||
} | ||
|
||
:root { | ||
color-scheme: light dark; | ||
|
||
--spacing: 20px; | ||
} | ||
|
||
html { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
|
||
gap: var(--spacing); | ||
margin: 0 calc(var(--spacing) * 2); | ||
height: 100%; | ||
|
||
font: -apple-system-short-body; | ||
text-align: center; | ||
} | ||
|
||
body:not(.platform-mac, .platform-ios) :is(.platform-mac, .platform-ios) { | ||
display: none; | ||
} | ||
|
||
body.platform-ios .platform-mac { | ||
display: none; | ||
} | ||
|
||
body.platform-mac .platform-ios { | ||
display: none; | ||
} | ||
|
||
body.platform-ios .platform-mac { | ||
display: none; | ||
} | ||
|
||
body:not(.state-on, .state-off) :is(.state-on, .state-off) { | ||
display: none; | ||
} | ||
|
||
body.state-on :is(.state-off, .state-unknown) { | ||
display: none; | ||
} | ||
|
||
body.state-off :is(.state-on, .state-unknown) { | ||
display: none; | ||
} | ||
|
||
button { | ||
font-size: 1em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// ViewController.swift | ||
// Shared (App) | ||
// | ||
// Created by zhangferry on 2023/7/15. | ||
// | ||
|
||
import WebKit | ||
|
||
#if os(iOS) | ||
import UIKit | ||
typealias PlatformViewController = UIViewController | ||
#elseif os(macOS) | ||
import Cocoa | ||
import SafariServices | ||
typealias PlatformViewController = NSViewController | ||
#endif | ||
|
||
let extensionBundleIdentifier = "com.zhangferry.SummarAI.Extension" | ||
|
||
class ViewController: PlatformViewController, WKNavigationDelegate, WKScriptMessageHandler { | ||
|
||
@IBOutlet var webView: WKWebView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.webView.navigationDelegate = self | ||
|
||
#if os(iOS) | ||
self.webView.scrollView.isScrollEnabled = false | ||
#endif | ||
|
||
self.webView.configuration.userContentController.add(self, name: "controller") | ||
|
||
self.webView.loadFileURL(Bundle.main.url(forResource: "Main", withExtension: "html")!, allowingReadAccessTo: Bundle.main.resourceURL!) | ||
} | ||
|
||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | ||
#if os(iOS) | ||
webView.evaluateJavaScript("show('ios')") | ||
#elseif os(macOS) | ||
webView.evaluateJavaScript("show('mac')") | ||
|
||
SFSafariExtensionManager.getStateOfSafariExtension(withIdentifier: extensionBundleIdentifier) { (state, error) in | ||
guard let state = state, error == nil else { | ||
// Insert code to inform the user that something went wrong. | ||
return | ||
} | ||
|
||
DispatchQueue.main.async { | ||
if #available(macOS 13, *) { | ||
webView.evaluateJavaScript("show('mac', \(state.isEnabled), true)") | ||
} else { | ||
webView.evaluateJavaScript("show('mac', \(state.isEnabled), false)") | ||
} | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { | ||
#if os(macOS) | ||
if (message.body as! String != "open-preferences") { | ||
return; | ||
} | ||
|
||
SFSafariApplication.showPreferencesForExtension(withIdentifier: extensionBundleIdentifier) { error in | ||
guard error == nil else { | ||
// Insert code to inform the user that something went wrong. | ||
return | ||
} | ||
|
||
DispatchQueue.main.async { | ||
NSApplication.shared.terminate(nil) | ||
} | ||
} | ||
#endif | ||
} | ||
|
||
} |
Oops, something went wrong.