chore: run swiftlint

experiment-on-whiteboard-exporting
Andelf 2022-10-11 15:30:10 +08:00 committed by Tienson Qin
parent 503e33f614
commit a8e35db725
5 changed files with 40 additions and 46 deletions

View File

@ -5,13 +5,13 @@ import Capacitor
class AppDelegate: UIResponder, UIApplicationDelegate { class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow? var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch. // Override point for customization after application launch.
return true return true
} }
func applicationWillResignActive(_ application: UIApplication) { func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
@ -28,15 +28,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func applicationDidBecomeActive(_ application: UIApplication) { func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
} }
func applicationWillTerminate(_ application: UIApplication) { func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
} }
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
return ApplicationDelegateProxy.shared.application(application, open: url, options: options) return ApplicationDelegateProxy.shared.application(application, open: url, options: options)
} }
@ -48,4 +47,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
} }
} }

View File

@ -14,47 +14,44 @@ public class FileContainer: CAPPlugin, UIDocumentPickerDelegate {
var iCloudContainerUrl: URL? { var iCloudContainerUrl: URL? {
return FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents") return FileManager.default.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")
} }
var localContainerUrl: URL? { var localContainerUrl: URL? {
return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first return FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
} }
@objc func ensureDocuments(_ call: CAPPluginCall) { @objc func ensureDocuments(_ call: CAPPluginCall) {
if self.iCloudContainerUrl != nil { if self.iCloudContainerUrl != nil {
validateDocuments(at: self.iCloudContainerUrl!) validateDocuments(at: self.iCloudContainerUrl!)
} }
if self.localContainerUrl != nil { if self.localContainerUrl != nil {
validateDocuments(at: self.localContainerUrl!) validateDocuments(at: self.localContainerUrl!)
} }
call.resolve(["path": [self.iCloudContainerUrl?.absoluteString as Any, call.resolve(["path": [self.iCloudContainerUrl?.absoluteString as Any,
self.localContainerUrl?.absoluteString as Any]]) self.localContainerUrl?.absoluteString as Any]])
} }
func validateDocuments(at url: URL) { func validateDocuments(at url: URL) {
if !FileManager.default.fileExists(atPath: url.path, isDirectory: nil) { if !FileManager.default.fileExists(atPath: url.path, isDirectory: nil) {
do { do {
print("the url = " + url.path) print("the url = " + url.path)
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil) try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
} } catch {
catch {
print("container doesn't exist") print("container doesn't exist")
print(error.localizedDescription) print(error.localizedDescription)
} }
} }
let str = "" let str = ""
let filename = url.appendingPathComponent(".logseq", isDirectory: false) let filename = url.appendingPathComponent(".logseq", isDirectory: false)
if !FileManager.default.fileExists(atPath: filename.path) { if !FileManager.default.fileExists(atPath: filename.path) {
do { do {
try str.write(to: filename, atomically: true, encoding: String.Encoding.utf8) try str.write(to: filename, atomically: true, encoding: String.Encoding.utf8)
} } catch {
catch {
print("write .logseq failed") print("write .logseq failed")
print(error.localizedDescription) print(error.localizedDescription)
} }

View File

@ -12,15 +12,15 @@ import MobileCoreServices
@objc(FolderPicker) @objc(FolderPicker)
public class FolderPicker: CAPPlugin, UIDocumentPickerDelegate { public class FolderPicker: CAPPlugin, UIDocumentPickerDelegate {
public var _call: CAPPluginCall? = nil public var _call: CAPPluginCall?
@objc func pickFolder(_ call: CAPPluginCall) { @objc func pickFolder(_ call: CAPPluginCall) {
self._call = call self._call = call
DispatchQueue.main.async { [weak self] in DispatchQueue.main.async { [weak self] in
let documentPicker = UIDocumentPickerViewController( let documentPicker = UIDocumentPickerViewController(
documentTypes: [String(kUTTypeFolder)], documentTypes: [String(kUTTypeFolder)],
in: UIDocumentPickerMode.open in: UIDocumentPickerMode.open
) )
documentPicker.allowsMultipleSelection = false documentPicker.allowsMultipleSelection = false
@ -28,27 +28,27 @@ public class FolderPicker: CAPPlugin, UIDocumentPickerDelegate {
documentPicker.modalPresentationStyle = UIModalPresentationStyle.fullScreen documentPicker.modalPresentationStyle = UIModalPresentationStyle.fullScreen
self?.bridge?.viewController?.present( self?.bridge?.viewController?.present(
documentPicker, documentPicker,
animated: true, animated: true,
completion: nil completion: nil
) )
} }
} }
public func documentPicker( public func documentPicker(
_ controller: UIDocumentPickerViewController, _ controller: UIDocumentPickerViewController,
didPickDocumentsAt urls: [URL] didPickDocumentsAt urls: [URL]
){ ) {
var items: [String] = [] var items: [String] = []
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
for url in urls { for url in urls {
items.append(url.absoluteString) items.append(url.absoluteString)
} }
self._call?.resolve([ self._call?.resolve([
"path": items.first as Any, "path": items.first as Any,
"localDocumentsPath": documentsPath[0] as Any "localDocumentsPath": documentsPath[0] as Any
]) ])
} }
} }

View File

@ -12,8 +12,8 @@ import Capacitor
@objc(FsWatcher) @objc(FsWatcher)
public class FsWatcher: CAPPlugin, PollingWatcherDelegate { public class FsWatcher: CAPPlugin, PollingWatcherDelegate {
private var watcher: PollingWatcher? = nil private var watcher: PollingWatcher?
private var baseUrl: URL? = nil private var baseUrl: URL?
override public func load() { override public func load() {
print("debug FsWatcher iOS plugin loaded!") print("debug FsWatcher iOS plugin loaded!")
@ -51,11 +51,11 @@ public class FsWatcher: CAPPlugin, PollingWatcherDelegate {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.notifyListeners("watcher", data: ["event": "unlink", self.notifyListeners("watcher", data: ["event": "unlink",
"dir": self.baseUrl?.description as Any, "dir": self.baseUrl?.description as Any,
"path": url.description, "path": url.description
]) ])
} }
case .Add, .Change: case .Add, .Change:
var content: String? = nil var content: String?
if url.shouldNotifyWithContent() { if url.shouldNotifyWithContent() {
content = try? String(contentsOf: url, encoding: .utf8) content = try? String(contentsOf: url, encoding: .utf8)
} }
@ -66,7 +66,7 @@ public class FsWatcher: CAPPlugin, PollingWatcherDelegate {
"stat": ["mtime": metadata?.contentModificationTimestamp ?? 0, "stat": ["mtime": metadata?.contentModificationTimestamp ?? 0,
"ctime": metadata?.creationTimestamp ?? 0, "ctime": metadata?.creationTimestamp ?? 0,
"size": metadata?.fileSize as Any] "size": metadata?.fileSize as Any]
]) ])
case .Error: case .Error:
// TODO: handle error? // TODO: handle error?
@ -83,7 +83,7 @@ extension URL {
if self.lastPathComponent.starts(with: ".") { if self.lastPathComponent.starts(with: ".") {
return true return true
} }
if self.absoluteString.contains("/logseq/bak/") || self.absoluteString.contains("/logseq/version-files/"){ if self.absoluteString.contains("/logseq/bak/") || self.absoluteString.contains("/logseq/version-files/") {
return true return true
} }
if self.lastPathComponent == "graphs-txid.edn" || self.lastPathComponent == "broken-config.edn" { if self.lastPathComponent == "graphs-txid.edn" || self.lastPathComponent == "broken-config.edn" {
@ -134,7 +134,6 @@ public enum PollingWatcherEvent {
} }
} }
public struct SimpleFileMetadata: CustomStringConvertible, Equatable { public struct SimpleFileMetadata: CustomStringConvertible, Equatable {
var contentModificationTimestamp: Double var contentModificationTimestamp: Double
var creationTimestamp: Double var creationTimestamp: Double
@ -142,7 +141,7 @@ public struct SimpleFileMetadata: CustomStringConvertible, Equatable {
public init?(of fileURL: URL) { public init?(of fileURL: URL) {
do { do {
let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey, .fileSizeKey, .contentModificationDateKey, .creationDateKey]) let fileAttributes = try fileURL.resourceValues(forKeys: [.isRegularFileKey, .fileSizeKey, .contentModificationDateKey, .creationDateKey])
if fileAttributes.isRegularFile! { if fileAttributes.isRegularFile! {
contentModificationTimestamp = fileAttributes.contentModificationDate?.timeIntervalSince1970 ?? 0.0 contentModificationTimestamp = fileAttributes.contentModificationDate?.timeIntervalSince1970 ?? 0.0
creationTimestamp = fileAttributes.creationDate?.timeIntervalSince1970 ?? 0.0 creationTimestamp = fileAttributes.creationDate?.timeIntervalSince1970 ?? 0.0
@ -163,7 +162,7 @@ public struct SimpleFileMetadata: CustomStringConvertible, Equatable {
public class PollingWatcher { public class PollingWatcher {
private let url: URL private let url: URL
private var timer: DispatchSourceTimer? private var timer: DispatchSourceTimer?
public var delegate: PollingWatcherDelegate? = nil public var delegate: PollingWatcherDelegate?
private var metaDb: [URL: SimpleFileMetadata] = [:] private var metaDb: [URL: SimpleFileMetadata] = [:]
public init?(at: URL) { public init?(at: URL) {

View File

@ -9,14 +9,14 @@ import Foundation
import Capacitor import Capacitor
@objc(Utils) @objc(Utils)
public class Utils: CAPPlugin { public class Utils: CAPPlugin {
@objc func isZoomed(_ call: CAPPluginCall) { @objc func isZoomed(_ call: CAPPluginCall) {
var isZoomed: Bool { var isZoomed: Bool {
return UIScreen.main.scale < UIScreen.main.nativeScale return UIScreen.main.scale < UIScreen.main.nativeScale
} }
call.resolve(["isZoomed": isZoomed]) call.resolve(["isZoomed": isZoomed])
} }
} }