remove iCloud sync swift codes (#5698)

This commit is contained in:
llcc
2022-06-14 18:51:32 +08:00
committed by GitHub
parent 7c8ae98911
commit 1af776a845
4 changed files with 4 additions and 141 deletions

View File

@@ -1,13 +0,0 @@
//
// DownloadiCloudFiles.m
// Logseq
//
// Created by leizhe on 2021/12/29.
//
#import <Foundation/Foundation.h>
#import <Capacitor/Capacitor.h>
CAP_PLUGIN(DownloadiCloudFiles, "DownloadiCloudFiles",
CAP_PLUGIN_METHOD(syncGraph, CAPPluginReturnPromise);
)

View File

@@ -1,109 +0,0 @@
//
// DownloadiCloudFiles.swift
// Logseq
//
// Created by leizhe on 2021/12/29.
//
import Foundation
import Capacitor
@objc(DownloadiCloudFiles)
public class DownloadiCloudFiles: CAPPlugin, UIDocumentPickerDelegate {
public var _call: CAPPluginCall? = nil
let fileManager = FileManager.default
var filesNeededToDownload = Set<String>()
let extensions = [
"md",
"org",
"css",
"edn",
"excalidraw"
]
var containerUrl: URL? {
return fileManager.url(forUbiquityContainerIdentifier: nil)?.appendingPathComponent("Documents")
}
var isDirectory: ObjCBool = false
var downloaded = false
@objc func syncGraph(_ call: CAPPluginCall) {
guard let graph = call.options["graph"] as? String else {
call.reject("Missing graph name")
return
}
let ignores = [".git", ".trash", "bak", ".recycle"]
if let url = self.containerUrl?.appendingPathComponent(graph) {
do {
downloaded = try self.downloadAllFilesFromCloud(at: url, ignorePattern: ignores)
handleDownloadFolderLoop()
} catch {
print(error.localizedDescription)
}
}
call.resolve(["success": downloaded])
}
func appendUndownloadedFile(at url: URL){
var lastPathComponent = url.lastPathComponent
lastPathComponent.removeFirst()
let dirPath = url.deletingLastPathComponent().path
let filePath = dirPath + "/" + lastPathComponent.replacingOccurrences(of: ".icloud", with: "")
let neededToHandle = !extensions.allSatisfy{ !filePath.hasSuffix($0) }
if neededToHandle {
filesNeededToDownload.insert(filePath)
}
}
func downloadAllFilesFromCloud(at url: URL, ignorePattern ignores: [String] = []) throws -> Bool {
let files = try fileManager.contentsOfDirectory(at: url, includingPropertiesForKeys: nil, options: [])
for file in files {
if file.pathExtension.lowercased() == "icloud" {
do {
try fileManager.startDownloadingUbiquitousItem(at: file)
appendUndownloadedFile(at: file)
} catch {
print("Unexpected error: \(error).")
}
} else {
if fileManager.fileExists(atPath: file.path, isDirectory:&isDirectory) {
if isDirectory.boolValue && !ignores.contains(file.lastPathComponent) {
if try downloadAllFilesFromCloud(at: file, ignorePattern: ignores) {
downloaded = true
}
}
}
}
}
return downloaded
}
func handleDownloadFolder() {
for file in filesNeededToDownload {
if fileManager.fileExists(atPath: file) {
filesNeededToDownload.remove(file)
}
}
}
func handleDownloadFolderLoop () {
while !filesNeededToDownload.isEmpty {
let count = filesNeededToDownload.count
let interval = min(Double(count) * 0.1, 2)
Thread.sleep(forTimeInterval: interval)
handleDownloadFolder()
}
}
}

View File

@@ -275,16 +275,10 @@
{:keys [path localDocumentsPath]} (p/chain
(.pickFolder mobile-util/folder-picker)
#(js->clj % :keywordize-keys true))
_ (when (mobile-util/native-ios?)
(cond
(not (or (local-container-path? path localDocumentsPath)
(mobile-util/iCloud-container-path? path)))
(state/pub-event! [:modal/show-instruction])
(mobile-util/iCloud-container-path? path)
(mobile-util/sync-icloud-repo path)
:else nil))
_ (when (and (mobile-util/native-ios?)
(not (or (local-container-path? path localDocumentsPath)
(mobile-util/iCloud-container-path? path))))
(state/pub-event! [:modal/show-instruction]))
files (readdir path)
files (js->clj files :keywordize-keys true)]
(into [] (concat [{:path path}] files))))

View File

@@ -23,7 +23,6 @@
(defonce folder-picker (registerPlugin "FolderPicker"))
(when (native-ios?)
(defonce download-icloud-files (registerPlugin "DownloadiCloudFiles"))
(defonce ios-utils (registerPlugin "Utils"))
(defonce ios-file-container (registerPlugin "FileContainer"))
(defonce file-sync (registerPlugin "FileSync")))
@@ -32,14 +31,6 @@
(when (native-platform?)
(defonce fs-watcher (registerPlugin "FsWatcher")))
(defn sync-icloud-repo [repo-dir]
(let [repo-name (-> (string/split repo-dir "Documents/")
last
string/trim
js/decodeURI)]
(.syncGraph download-icloud-files
(clj->js {:graph repo-name}))))
(defn hide-splash []
(.hide SplashScreen))