mirror of https://github.com/logseq/logseq
fix(ios): file-sync reload when running
parent
f157490d61
commit
bca0dd42ae
|
@ -19,5 +19,7 @@ CAP_PLUGIN(FileSync, "FileSync",
|
|||
CAP_PLUGIN_METHOD(updateRemoteFiles, CAPPluginReturnPromise);
|
||||
CAP_PLUGIN_METHOD(encryptFnames, CAPPluginReturnPromise);
|
||||
CAP_PLUGIN_METHOD(decryptFnames, CAPPluginReturnPromise);
|
||||
CAP_PLUGIN_METHOD(decryptWithPassphrase, CAPPluginReturnPromise);
|
||||
CAP_PLUGIN_METHOD(encryptWithPassphrase, CAPPluginReturnPromise);
|
||||
CAP_PLUGIN_METHOD(updateLocalVersionFiles, CAPPluginReturnPromise);
|
||||
)
|
||||
|
|
|
@ -218,6 +218,47 @@ public class FileSync: CAPPlugin, SyncDebugDelegate {
|
|||
}
|
||||
call.resolve(["value": fnames])
|
||||
}
|
||||
|
||||
@objc func encryptWithPassphrase(_ call: CAPPluginCall) {
|
||||
guard let passphrase = call.getString("passphrase"),
|
||||
let content = call.getString("content") else {
|
||||
call.reject("required parameters: passphrase, content")
|
||||
return
|
||||
}
|
||||
guard let ciphertext = content.data(using: .utf8) else {
|
||||
call.reject("cannot decode ciphertext with utf8")
|
||||
return
|
||||
}
|
||||
call.keepAlive = true
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
if let encrypted = AgeEncryption.encryptWithPassphrase(ciphertext, passphrase, armor: true) {
|
||||
call.resolve(["data": String(data: encrypted, encoding: .utf8) as Any])
|
||||
} else {
|
||||
call.reject("cannot encrypt with passphrase")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func decryptWithPassphrase(_ call: CAPPluginCall) {
|
||||
guard let passphrase = call.getString("passphrase"),
|
||||
let content = call.getString("content") else {
|
||||
call.reject("required parameters: passphrase, content")
|
||||
return
|
||||
}
|
||||
guard let ciphertext = content.data(using: .utf8) else {
|
||||
call.reject("cannot decode ciphertext with utf8")
|
||||
return
|
||||
}
|
||||
call.keepAlive = true
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
if let decrypted = AgeEncryption.decryptWithPassphrase(ciphertext, passphrase) {
|
||||
call.resolve(["data": String(data: decrypted, encoding: .utf8) as Any])
|
||||
} else {
|
||||
call.reject("cannot decrypt with passphrase")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getLocalFilesMeta(_ call: CAPPluginCall) {
|
||||
// filePaths are url encoded
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
[promesa.core :as p]
|
||||
[electron.ipc :as ipc]
|
||||
[shadow.loader :as loader]
|
||||
[lambdaisland.glogi :as log]))
|
||||
[lambdaisland.glogi :as log]
|
||||
[frontend.mobile.util :as mobile-util]))
|
||||
|
||||
(defonce age-pem-header-line "-----BEGIN AGE ENCRYPTED FILE-----")
|
||||
(defonce age-version-line "age-encryption.org/v1")
|
||||
|
@ -96,6 +97,12 @@
|
|||
encrypted (ipc/ipc "encrypt-with-passphrase" passphrase raw-content)]
|
||||
(utf8/decode encrypted))
|
||||
|
||||
(mobile-util/native-ios?)
|
||||
(p/chain (.encryptWithPassphrase mobile-util/file-sync
|
||||
(clj->js {:passphrase passphrase :content content}))
|
||||
#(js->clj % :keywordize-keys true)
|
||||
:data)
|
||||
|
||||
:else
|
||||
(p/let [lazy-encrypt-with-user-passphrase (resolve 'frontend.extensions.age-encryption/encrypt-with-user-passphrase)
|
||||
content (utf8/encode content)
|
||||
|
@ -110,6 +117,12 @@
|
|||
decrypted (ipc/ipc "decrypt-with-passphrase" passphrase raw-content)]
|
||||
(utf8/decode decrypted))
|
||||
|
||||
(mobile-util/native-ios?)
|
||||
(p/chain (.decryptWithPassphrase mobile-util/file-sync
|
||||
(clj->js {:passphrase passphrase :content content}))
|
||||
#(js->clj % :keywordize-keys true)
|
||||
:data)
|
||||
|
||||
:else
|
||||
(p/let [_ (loader/load :age-encryption)
|
||||
lazy-decrypt-with-user-passphrase (resolve 'frontend.extensions.age-encryption/decrypt-with-user-passphrase)
|
||||
|
|
Loading…
Reference in New Issue