swiftlint
This commit is contained in:
@@ -6,19 +6,19 @@ import UIKit
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
var window: UIWindow?
|
||||
var controller: ViewController?
|
||||
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
self.window = UIWindow()
|
||||
|
||||
|
||||
self.controller = ViewController(window: self.window!)
|
||||
|
||||
self.window?.rootViewController = self.controller
|
||||
self.window?.makeKeyAndVisible()
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
|
||||
|
||||
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
|
||||
self.controller?.handleURL(url: url)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -4,39 +4,38 @@ import StoreKit
|
||||
|
||||
class ViewController: UIViewController, WKScriptMessageHandler {
|
||||
let defaults = UserDefaults(suiteName: "group.app.bsky")
|
||||
|
||||
|
||||
var window: UIWindow
|
||||
var webView: WKWebView?
|
||||
var userContentController: WKUserContentController?
|
||||
|
||||
|
||||
var starterPackUrl: URL?
|
||||
|
||||
|
||||
init(window: UIWindow) {
|
||||
self.window = window
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
|
||||
let contentController = WKUserContentController()
|
||||
contentController.add(self, name: "onMessage")
|
||||
let configuration = WKWebViewConfiguration()
|
||||
configuration.userContentController = contentController
|
||||
|
||||
|
||||
let webView = WKWebView(frame: self.view.bounds, configuration: configuration)
|
||||
webView.translatesAutoresizingMaskIntoConstraints = false
|
||||
webView.contentMode = .scaleToFill
|
||||
|
||||
|
||||
self.view.addSubview(webView)
|
||||
|
||||
self.webView = webView
|
||||
}
|
||||
|
||||
|
||||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
||||
guard let response = message.body as? String,
|
||||
let data = response.data(using: .utf8, allowLossyConversion: false),
|
||||
@@ -44,42 +43,42 @@ class ViewController: UIViewController, WKScriptMessageHandler {
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
switch payload.action {
|
||||
case .present:
|
||||
guard let url = self.starterPackUrl else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
self.presentAppStoreOverlay()
|
||||
defaults?.setValue(url.absoluteString, forKey: "starterPackUri")
|
||||
|
||||
|
||||
case .store:
|
||||
guard let keyToStoreAs = payload.keyToStoreAs, let jsonToStore = payload.jsonToStore else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
self.defaults?.setValue(jsonToStore, forKey: keyToStoreAs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func handleURL(url: URL) {
|
||||
self.starterPackUrl = url
|
||||
let urlString = "\(url.absoluteString)?clip=true"
|
||||
|
||||
|
||||
if let url = URL(string: urlString) {
|
||||
self.webView?.load(URLRequest(url: url))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func presentAppStoreOverlay() {
|
||||
guard let windowScene = self.window.windowScene else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
let configuration = SKOverlay.AppClipConfiguration(position: .bottomRaised)
|
||||
let overlay = SKOverlay(configuration: configuration)
|
||||
|
||||
|
||||
overlay.present(in: windowScene)
|
||||
}
|
||||
}
|
||||
@@ -88,7 +87,7 @@ struct WebViewActionPayload: Decodable {
|
||||
enum Action: String, Decodable {
|
||||
case present, store
|
||||
}
|
||||
|
||||
|
||||
let action: Action
|
||||
let keyToStoreAs: String?
|
||||
let jsonToStore: String?
|
||||
|
||||
@@ -8,16 +8,16 @@ public class ExpoBlueskySwissArmyModule: Module {
|
||||
return UserDefaults.standard
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("ExpoBlueskySwissArmy")
|
||||
|
||||
|
||||
AsyncFunction("getStringValueAsync") { (key: String, useAppGroup: Bool) in
|
||||
let defaults = self.getDefaults(useAppGroup)
|
||||
|
||||
|
||||
return defaults?.string(forKey: key)
|
||||
}
|
||||
|
||||
|
||||
AsyncFunction("setStringValueAsync") { (key: String, value: String?, useAppGroup: Bool) in
|
||||
let defaults = self.getDefaults(useAppGroup)
|
||||
defaults?.setValue(value, forKey: key)
|
||||
|
||||
Reference in New Issue
Block a user