feat: Add native iOS download support using URLSession - #7
Conversation
a3868ec to
4cc6991
Compare
40881bd to
a9b84de
Compare
jjhafer
left a comment
There was a problem hiding this comment.
@velocitysystems Finished my initial review and offered suggestions. We can certainly discuss which suggestions are actually necessary before this can be merged.
041ac8c to
1d9699c
Compare
1d9699c to
0232724
Compare
| } | ||
| } | ||
|
|
||
| func getDownloadTask(_ key: String) -> URLSessionDownloadTask? { |
There was a problem hiding this comment.
@jjhafer With async/await this could be simplified to:
func getDownloadTask(_ key: String) async -> URLSessionDownloadTask? {
guard let session = session else { return nil }
let tasks = await withCheckedContinuation { continuation in
session.getAllTasks { tasks in
continuation.resume(returning: tasks)
}
}
return tasks.compactMap { $0 as? URLSessionDownloadTask }.first { $0.taskDescription == key }
}
However from testing I ran into issues with invoking the commands from Tauri's IPC when either:
- Decorated with
async - Using an embedded
Task { }wrapper
Will do some further research and may revisit this in a future PR.
| } | ||
|
|
||
| #[tauri::command(rename_all = "snake_case")] | ||
| pub(crate) async fn is_native<R: Runtime>(_app: AppHandle<R>) -> Result<bool> { |
There was a problem hiding this comment.
This command allows the JS API to determine whether to register a plugin listener for iOS or a global listener for Android/desktop. Adding this command was a low-cost alternative to bringing in an external dependency such as the OS information plugin.
yokuze
left a comment
There was a problem hiding this comment.
Thank you for all of the great work here! A few questions/suggestions there for you.
Thanks @yokuze. I've addressed all of your feedback in the PR. |
This PR introduces native iOS download support using
URLSessionsplitting the original shared code into platform-specific modules (desktop and mobile). It utilises a new Swift packageDownloadManagerKitwhich is integrated with the Tauri plugin architecture.Key Changes
build.rs: Added ios_path("ios") to the tauri_plugin builder to include the iOS implementationguest-js/index.ts: AddedaddPluginListenerto handle events from the iOS pluginios-src/DownloadManagerKit: Created a Swift package containing the core download logicios-src/DownloadManagerExample: Created an example iOS app that utilizes theDownloadManagerKitpackage.Impact
DownloadManagerKitSwift package for iOS builds, and Tauri package.Maintenance
package.jsonto add new run targets for iOS and Android