swiftlint

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