-
Notifications
You must be signed in to change notification settings - Fork 0
impl ios library #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| name: ci | ||
| on: | ||
| pull_request: | ||
| concurrency: | ||
| group: ci-${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} | ||
| cancel-in-progress: true | ||
| jobs: | ||
| swift-test: | ||
| runs-on: macos-26 | ||
| steps: | ||
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # 6.0.1 | ||
| - run: swift test | ||
| e2e: | ||
| runs-on: macos-26 | ||
| steps: | ||
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # 6.0.1 | ||
| - uses: jdx/mise-action@1648a7812b9aeae629881980618f079932869151 # 4.0.1 | ||
| - run: corepack enable | ||
| - run: yarn install --immutable | ||
| working-directory: e2e | ||
| - run: yarn test | ||
| working-directory: e2e | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import Foundation | ||
|
|
||
| extension HttpMethod { | ||
| /// Maps a `URLRequest.httpMethod` string to the FFI ``HttpMethod``. | ||
| /// Defaults to `.get` for unknown or missing methods. | ||
| static func from(_ method: String?) -> HttpMethod { | ||
| switch method?.uppercased() { | ||
| case "GET": return .get | ||
| case "HEAD": return .head | ||
| case "OPTIONS": return .options | ||
| case "POST": return .post | ||
| case "PUT": return .put | ||
| case "PATCH": return .patch | ||
| case "DELETE": return .delete | ||
| case "TRACE": return .trace | ||
| case "CONNECT": return .connect | ||
| default: return .get | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension HttpResponse { | ||
| /// Builds an `HTTPURLResponse` for `url` from this response's status and | ||
| /// headers. | ||
| func makeURLResponse(url: URL) -> HTTPURLResponse { | ||
| HTTPURLResponse( | ||
| url: url, | ||
| statusCode: Int(status), | ||
| httpVersion: "HTTP/1.1", | ||
| headerFields: headers | ||
| ) ?? HTTPURLResponse( | ||
| url: url, | ||
| statusCode: Int(status), | ||
| httpVersion: "HTTP/1.1", | ||
| headerFields: nil | ||
| )! | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import Foundation | ||
|
|
||
| /// Common shape of the UniFFI request handlers used by the WebView integration. | ||
| /// | ||
| /// Both ``BundleUrlHandler`` and ``LocalUrlHandler`` (generated into this module | ||
| /// by UniFFI) already expose this exact `handle` signature, so they conform | ||
| /// without extra code. | ||
| protocol WebViewBundleRequestHandler: AnyObject, Sendable { | ||
| func handle( | ||
| method: HttpMethod, | ||
| uri: String, | ||
| headers: [String: String]? | ||
| ) async throws -> HttpResponse | ||
| } | ||
|
|
||
| extension BundleUrlHandler: WebViewBundleRequestHandler {} | ||
| extension LocalUrlHandler: WebViewBundleRequestHandler {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import Foundation | ||
|
|
||
| /// Options for building a ``BundleSource`` with sensible iOS/macOS defaults. | ||
| /// | ||
| /// Every field is optional and falls back to a platform default when omitted: | ||
| /// - `builtinDir` → `<app resources>/bundles` (read-only, shipped with the app). | ||
| /// - `remoteDir` → `<Application Support>/<bundle id>/bundles` (writable, holds | ||
| /// bundles downloaded at runtime). | ||
| public struct SourceOptions: Sendable { | ||
| public var builtinDir: String? | ||
| public var remoteDir: String? | ||
| public var builtinManifestFilepath: String? | ||
| public var remoteManifestFilepath: String? | ||
|
|
||
| public init( | ||
| builtinDir: String? = nil, | ||
| remoteDir: String? = nil, | ||
| builtinManifestFilepath: String? = nil, | ||
| remoteManifestFilepath: String? = nil | ||
| ) { | ||
| self.builtinDir = builtinDir | ||
| self.remoteDir = remoteDir | ||
| self.builtinManifestFilepath = builtinManifestFilepath | ||
| self.remoteManifestFilepath = remoteManifestFilepath | ||
| } | ||
| } | ||
|
|
||
| extension BundleSource { | ||
| /// Builds a ``BundleSource`` from ``SourceOptions``, filling in default | ||
| /// directories and creating the writable `remoteDir`. | ||
| public static func make(_ options: SourceOptions = SourceOptions()) throws -> BundleSource { | ||
| let builtinDir = options.builtinDir ?? defaultBuiltinDir() | ||
| let remoteDir = options.remoteDir ?? defaultRemoteDir() | ||
| try FileManager.default.createDirectory( | ||
| atPath: remoteDir, | ||
| withIntermediateDirectories: true | ||
| ) | ||
| return BundleSource(config: BundleSourceConfig( | ||
| builtinDir: builtinDir, | ||
| remoteDir: remoteDir, | ||
| builtinManifestFilepath: options.builtinManifestFilepath, | ||
| remoteManifestFilepath: options.remoteManifestFilepath | ||
| )) | ||
| } | ||
|
|
||
| /// `<app resources>/bundles` — the read-only directory shipped with the app. | ||
| public static func defaultBuiltinDir() -> String { | ||
| // `Foundation.Bundle` because unqualified `Bundle` resolves to the FFI's | ||
| // own bundle type in this module. | ||
| let base = Foundation.Bundle.main.resourceURL ?? Foundation.Bundle.main.bundleURL | ||
| return base.appendingPathComponent("bundles").path | ||
| } | ||
|
|
||
| /// `<Application Support>/<bundle id>/bundles` — the writable directory for | ||
| /// bundles downloaded at runtime. Falls back to caches/temporary if | ||
| /// Application Support is unavailable. | ||
| /// | ||
| /// Scoped under the bundle id because macOS's Application Support is shared | ||
| /// (unlike iOS's per-app sandbox), so two apps linking this SDK would | ||
| /// otherwise clobber one `bundles` directory. | ||
| public static func defaultRemoteDir() -> String { | ||
| let fm = FileManager.default | ||
| let base = (try? fm.url( | ||
| for: .applicationSupportDirectory, | ||
| in: .userDomainMask, | ||
| appropriateFor: nil, | ||
| create: true | ||
| )) ?? fm.urls(for: .cachesDirectory, in: .userDomainMask).first | ||
| ?? fm.temporaryDirectory | ||
| let appId = Foundation.Bundle.main.bundleIdentifier ?? "WebViewBundle" | ||
| return base | ||
| .appendingPathComponent(appId) | ||
| .appendingPathComponent("bundles") | ||
| .path | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.