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 {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
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.
// 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) {
// 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) {
// 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)
}
@ -48,4 +47,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

View File

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

View File

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

View File

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

View File

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