mirror of
https://github.com/readest/readest.git
synced 2026-04-29 12:00:49 +00:00
feat(iOS): support open file with Readest in Files App, closes #2334 (#2705)
Some checks are pending
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
Some checks are pending
Deploy to vercel on merge / build_and_deploy (push) Waiting to run
This commit is contained in:
parent
730fadb834
commit
c1530cc5c4
10 changed files with 261 additions and 16 deletions
|
|
@ -53,6 +53,11 @@ class SetScreenBrightnessRequestArgs: Decodable {
|
|||
let brightness: Float?
|
||||
}
|
||||
|
||||
class CopyUriToPathRequestArgs: Decodable {
|
||||
let uri: String?
|
||||
let dst: String?
|
||||
}
|
||||
|
||||
struct InitializeRequest: Decodable {
|
||||
let publicKey: String?
|
||||
}
|
||||
|
|
@ -816,6 +821,59 @@ class NativeBridgePlugin: Plugin {
|
|||
}
|
||||
invoke.resolve(["success": true])
|
||||
}
|
||||
|
||||
@objc public func copy_uri_to_path(_ invoke: Invoke) {
|
||||
guard let args = try? invoke.parseArgs(CopyUriToPathRequestArgs.self) else {
|
||||
return invoke.reject("Failed to parse arguments")
|
||||
}
|
||||
|
||||
guard let uriString = args.uri, let dstPath = args.dst else {
|
||||
return invoke.reject("URI and destination path must be provided")
|
||||
}
|
||||
|
||||
guard let uri = URL(string: uriString) else {
|
||||
return invoke.reject("Invalid URI")
|
||||
}
|
||||
|
||||
let fileManager = FileManager.default
|
||||
let dstURL = URL(fileURLWithPath: dstPath)
|
||||
|
||||
do {
|
||||
let didStartAccessing = uri.startAccessingSecurityScopedResource()
|
||||
defer {
|
||||
if didStartAccessing {
|
||||
uri.stopAccessingSecurityScopedResource()
|
||||
}
|
||||
}
|
||||
|
||||
var shouldCopy = false
|
||||
|
||||
if fileManager.fileExists(atPath: dstURL.path) {
|
||||
let srcAttributes = try fileManager.attributesOfItem(atPath: uri.path)
|
||||
let dstAttributes = try fileManager.attributesOfItem(atPath: dstURL.path)
|
||||
|
||||
let srcModDate = srcAttributes[.modificationDate] as? Date ?? Date.distantPast
|
||||
let dstModDate = dstAttributes[.modificationDate] as? Date ?? Date.distantPast
|
||||
|
||||
if srcModDate > dstModDate {
|
||||
try fileManager.removeItem(at: dstURL)
|
||||
shouldCopy = true
|
||||
} else {
|
||||
shouldCopy = false
|
||||
}
|
||||
} else {
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if shouldCopy {
|
||||
try fileManager.copyItem(at: uri, to: dstURL)
|
||||
}
|
||||
|
||||
invoke.resolve(["success": true])
|
||||
} catch {
|
||||
invoke.reject("Failed to copy file: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("init_plugin_native_bridge")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue