Initial Commit
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "16x16"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "16x16"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "32x32"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "32x32"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "128x128"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "128x128"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "256x256"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "256x256"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "512x512"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"scale" : "2x",
|
||||
"size" : "512x512"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
6
Shared (App)/Assets.xcassets/Contents.json
Normal file
6
Shared (App)/Assets.xcassets/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
20
Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json
vendored
Normal file
20
Shared (App)/Assets.xcassets/LargeIcon.imageset/Contents.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
20
Shared (App)/Base.lproj/Main.html
Normal file
20
Shared (App)/Base.lproj/Main.html
Normal file
@@ -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="nostore Icon">
|
||||
<p class="platform-ios">You can turn on nostore’s Safari extension in Settings.</p>
|
||||
<p class="platform-mac state-unknown">You can turn on nostore’s extension in Safari Extensions preferences.</p>
|
||||
<p class="platform-mac state-on">nostore’s extension is currently on. You can turn it off in Safari Extensions preferences.</p>
|
||||
<p class="platform-mac state-off">nostore’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>
|
||||
BIN
Shared (App)/Resources/Icon.png
Normal file
BIN
Shared (App)/Resources/Icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 98 KiB |
24
Shared (App)/Resources/Script.js
Normal file
24
Shared (App)/Resources/Script.js
Normal file
@@ -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 = "nostore’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 = "nostore’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 nostore’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);
|
||||
61
Shared (App)/Resources/Style.css
Normal file
61
Shared (App)/Resources/Style.css
Normal file
@@ -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;
|
||||
}
|
||||
81
Shared (App)/ViewController.swift
Normal file
81
Shared (App)/ViewController.swift
Normal file
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// Shared (App)
|
||||
//
|
||||
// Created by Ryan Breen on 1/11/23.
|
||||
//
|
||||
|
||||
import WebKit
|
||||
|
||||
#if os(iOS)
|
||||
import UIKit
|
||||
typealias PlatformViewController = UIViewController
|
||||
#elseif os(macOS)
|
||||
import Cocoa
|
||||
import SafariServices
|
||||
typealias PlatformViewController = NSViewController
|
||||
#endif
|
||||
|
||||
let extensionBundleIdentifier = "camp.ursus.nostore.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
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user