Skip to content

Commit eeb60f7

Browse files
wheregmisealmloffjkelleyrtp
authored
permissions, manganis::ffi, full Info.plist/AndroidManifest.xml customization (#4842)
* initial version * make custom permission work without const-vec change * wiring up with cli * yey symbol found * wip * holy moly * proper ui * cleanup * okay * wip cleanup * reduce boilerplate code into mobile-core * Delete copilot-instructions.md * revert hello-world example for low diff * fix android build in mobile-core * rename permission to static_permission * small success with popup location on android * android popup working * Refactor permission checks for readability Improves code formatting in has_location_permission and check_permission functions by splitting long lines and updating function signatures for better readability. No functional changes were made. * wip consolidate all java files and build from cli instead of build.rs * few cli cleanups * wip java_plugin macro * cleanup cleanup cleanup * Update java_plugin macro to use full relative file paths The java_plugin macro now accepts full relative paths for Java files instead of assuming a fixed directory structure. Documentation and usage examples have been updated to reflect this change, improving flexibility and clarity for specifying file locations. * Improve iOS geolocation permission and retrieval logic Added checks for authorization status before requesting location permissions and retrieving location data. Now only requests permission if not determined, and attempts to retrieve cached location before starting location updates, improving efficiency and user experience. * Add ios_plugin macro for iOS framework metadata Introduces the ios_plugin! macro in mobile-core-macro for declarative iOS framework metadata embedding. Updates mobile-core to re-export the macro and refactors mobile-geolocation to use ios_plugin! instead of manual linker attributes. * not needed * simplify the plugin * rename mobile-core to platform-bridge and mobile-core-macro to platform-bridge-macro * Refactor metadata serialization buffer initialization Replaces inline creation of ConstVec with a named EMPTY constant for buffer initialization in metadata serialization. This improves code clarity and maintainability. * mobile-geolocation out of dioxus * take the example also out of dioxus * remove example from cargo toml * remove demo css * revert hello-world example * revert mac.plist * revert gitignore * Remove basic usage example for permissions crate Deleted the basic_usage.rs example file from the permissions crate. This change may be part of a cleanup or refactoring to remove outdated or unnecessary example code. * Delete plan.md * remove dups * cleanup java build * cleanup permission symbol extraction * update todo * small slop of tested permissions in enums for minimum diff * Refactor symbol extraction into linker_symbols module Moved generic symbol extraction logic from android_java.rs and permissions.rs into a new linker_symbols.rs module. Updated both files to use the shared utilities for finding symbol offsets, reducing code duplication and improving maintainability. * wip consolidate ios and macos as darwin * Add docs and re-export for MainThreadCell and MainThreadMarker Expanded documentation for MainThreadCell, clarifying usage and safety. Changed visibility of MainThreadCell to public, improved method docs, and re-exported MainThreadMarker in darwin/mod.rs for easier access. * Update Darwin framework symbol and section names Changed the framework symbol prefix from '__DARWIN_FRAMEWORK__' to '__DARWIN_FW__' and updated the Mach-O section name from '__darwin_framework' to '__darwin_fw' for compliance with section name length limits and consistency. * Fix Info.plist path handling for iOS and macOS Adds comments and corrects the path to Info.plist for iOS and macOS app bundles. For iOS, Info.plist is at the root of the .app bundle, while for macOS it is inside Contents/. Also improves warning message to include the missing path. * Handle missing permission symbols and web bundle case Improves permission extraction by returning an empty manifest when no permission symbols are found or when building a web bundle, as permissions are runtime-only in that case. Adds debug logging for missing symbols and ensures robust handling of these scenarios. * objc2 over framework * windows, linux, web all permissions are runtime so cleanup * only include permissions for build time * cleanup unnecessary test * more cleanup * extract shared into dx-macro-helpers * rc.3 to 0.7.0 for const-serialize * Add CustomPermissionBuilder and enhance PermissionBuilder for better permission management - Introduced `CustomPermissionBuilder` for creating custom permissions with platform-specific identifiers. - Enhanced `PermissionBuilder` to support custom permissions and location permissions with a clear builder pattern. - Updated documentation and examples in the macro README to reflect new usage patterns for custom and location permissions. - Improved parsing logic in the macro to handle both builder and direct construction patterns for permissions. * clippy fixes * implement const cbor encoding + decoding for basic types * Add #[used] attribute to linker sections for optimization protection - Added #[used] attribute to linker sections in both permission and Android plugin macros to prevent the linker from optimizing away symbols, ensuring they are preserved even if unused. - Created static references to linker sections to enhance defense-in-depth against optimization issues. * implement map encoding and decoding * fix map test * wip unified linker symbol * cleanup permissions * pipe java sources with manganis as well * all tests passing * dynamically sized arrays * smaller str encoding * swap array and list and add more documentation * move serialization and deserialization for each struct together * support both legacy and new assets * bump const serialize version * fix asset conversion code * pull out manganis symbol struct from tuble * test reading old asset versions * more list/array cleanup and bump rust version * fix clippy * Revert "pipe java sources with manganis as well" This reverts commit ddea9a4. * Revert "cleanup permissions" This reverts commit 7b18500. * Revert "wip unified linker symbol" This reverts commit 813e33f. * Revert "Add #[used] attribute to linker sections for optimization protection" This reverts commit a94a7a3. * update cargo lock * wip permission through assets * abit cleanup * fix reexports * fix assets * Fix the permissions piping * some small cleanups * checkout const-serialize as per #4932 and fix build * invoking swift as a package * geolocation package & example dumping for easy testing * keep geolocation simple for testing * cleanups * pipe everything through __ASSETS__ and cleanup * remove linker_symbols helper file * example * re example * copy build methos into mobile-plugin-build crate * Add conditional import for dioxus_07 feature Introduces a conditional import to use the dioxus_07 crate when the corresponding feature is enabled, improving compatibility with different dioxus versions. * Improve error handling and JNI reference usage Adds a null check for Objective-C instance initialization in the iOS geolocation plugin to prevent errors on failed allocation. Refactors Android callback to use local JNI references instead of creating unnecessary global references, reducing potential memory leaks. * revert changes on playwright * Update dioxus dependency to 0.7.2 in Cargo.lock Removed dioxus 0.7.1 from dependencies, retaining only dioxus 0.7.2 for the dioxus-cli-optimization-test package. * small cleanup * Add legacy const-serialize 0.7 support to dx-macro-helpers Introduces support for the const-serialize 0.7 format in dx-macro-helpers by adding a new dependency and export, as well as a helper function for serialization with layout padding. Updates manganis to use the new helper for serializing assets in the legacy format, simplifying code and improving maintainability. * Add helper for legacy and current linker sections Introduces generate_link_sections_with_legacy in dx-macro-helpers to emit both legacy and current linker sections for compatibility. Refactors manganis-macro to use this new helper, reducing duplication and improving maintainability. * Fix lints * Fix clippy and doctest * Refactor asset bundling and allow large enum variant Refactored Asset::bundled to use Vec<u8> instead of ConstVec for reading volatile slices, simplifying the code and improving compatibility. Added #[allow(clippy::large_enum_variant)] to SymbolData enum to suppress Clippy warnings about large enum variants. * Update license URLs in README to use angle brackets Changed license URLs in the README from parentheses to angle brackets for improved formatting and clarity. * Fix asset deserialization with correct buffer type Replaces the use of `bytes.read()` with `ConstReadBuffer::new(bytes.as_ref())` for asset deserialization, ensuring compatibility with the expected deserialization API. * Refactor geolocation and asset handling for clarity Removed unnecessary clones in geolocation example event handlers to simplify state management. Updated SymbolDataOrAsset to store SymbolData in a Box for improved memory handling and adjusted related logic. Fixed documentation example in geolocation lib to include PermissionState in the import. * Update geolocation example and permissions usage docs Removes unused variables in the geolocation example's App function. Updates the permissions crate documentation to reflect new API usage with PermissionBuilder and LocationPrecision. * Update permissions-macro to use permissions crate Switched imports and dev-dependency from permissions_core to permissions in permissions-macro. Updated documentation and examples to reflect the new crate usage. * rollback const-serialize changes * move items around (doesn't compile) * convert gelocation plugin to example * remove dx-macro-helpers * we're just gonna full-send linker everything * rollback desktop changes * remove gradle * fix most compile? * fix dioxus vers * small cleanups * add claude design docs * add ffi macro * remove * loads but not linking yet * fix output leak * a little bit closer but not quite * improve android code gen * sheeeeee works!!! * small tweaks to demo * replace ios/android plugin with ffi macro entirely * simplify ffi module * simplify again * condense / rip out some stuff from manganis * remove types form public api * wip, permissions * oops I broke it * I unbroke it * move arch doc * remove extra manifest types * drop bindgen file * remove permission * small cleanup * remove unsafecall mtm thing * yoink perms * wire up manifest * Add deeplinks * add schema generation * update schema * wip.... * fix recurse limit schema generation * wip, muck around with schema * add inline dioxus.toml support * merge bundle config schemas * claude my man * Remove cdecl, annotate ffi * rename design docs * wip: live activities * wip: apple plugin bundling * wip * get live activities linking properly * small cleanups * remove sidecars * remove widget * yoink legacy * cleanup * more fixups * wire up more things to dioxus.toml * fix workspace join * final cleanups * fmt * final bit of clippy * ci tweak * update schema * fmt, doc * update schema docs --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com> Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
1 parent 64cc42e commit eeb60f7

73 files changed

Lines changed: 13761 additions & 330 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,25 @@ jobs:
119119
cache-all-crates: "true"
120120
- run: cargo fmt --all -- --check
121121

122+
schema:
123+
if: github.event.pull_request.draft == false
124+
name: Check Schema
125+
runs-on: blacksmith-4vcpu-ubuntu-2404
126+
steps:
127+
- uses: actions/checkout@v5
128+
- uses: dtolnay/rust-toolchain@1.88.0
129+
- uses: Swatinem/rust-cache@v2
130+
with:
131+
cache-all-crates: "true"
132+
- name: Generate schema
133+
run: cargo run -p dioxus-cli -- config schema --out packages/cli/schema.json
134+
- name: Check for uncommitted changes
135+
run: |
136+
if ! git diff --exit-code packages/cli/schema.json; then
137+
echo "::error::Schema is out of date. Run 'dx config schema --out packages/cli/schema.json' and commit the changes."
138+
exit 1
139+
fi
140+
122141
docs:
123142
if: github.event.pull_request.draft == false
124143
name: Docs

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ node_modules/
3030
/test-results/
3131
/packages/playwright-report/
3232
/packages/playwright/.cache/
33-
33+
# Allow geolocation plugin sources to be tracked
34+
/packages/geolocation/android/build/
35+
/packages/geolocation/android/.gradle/
3436
# Zed
3537
.zed/
3638

Cargo.lock

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ members = [
88
"packages/cli-opt",
99
"packages/cli-config",
1010
"packages/cli-telemetry",
11-
"packages/core-types",
1211
"packages/core-macro",
1312
"packages/config-macro",
1413
"packages/router-macro",
@@ -24,42 +23,22 @@ members = [
2423
"packages/liveview",
2524
"packages/autofmt",
2625
"packages/check",
27-
"packages/config-macro",
28-
"packages/core-macro",
29-
"packages/core-types",
30-
"packages/core",
31-
"packages/desktop",
3226
"packages/devtools-types",
3327
"packages/devtools",
34-
"packages/dioxus",
3528
"packages/document",
36-
"packages/extension",
3729
"packages/fullstack",
3830
"packages/fullstack-core",
3931
"packages/fullstack-macro",
4032
"packages/fullstack-server",
4133
"packages/generational-box",
4234
"packages/history",
43-
"packages/hooks",
44-
"packages/html-internal-macro",
45-
"packages/html",
46-
"packages/interpreter",
4735
"packages/lazy-js-bundle",
48-
"packages/liveview",
49-
"packages/router-macro",
50-
"packages/router",
5136
"packages/rsx-hotreload",
5237
"packages/rsx-rosetta",
5338
"packages/rsx",
5439
"packages/signals",
5540
"packages/stores",
5641
"packages/stores-macro",
57-
"packages/ssr",
58-
"packages/lazy-js-bundle",
59-
"packages/cli-config",
60-
"packages/devtools",
61-
"packages/devtools-types",
62-
"packages/rsx-hotreload",
6342
"packages/const-serialize",
6443
"packages/const-serialize-macro",
6544
"packages/dx-wire-format",
@@ -77,9 +56,22 @@ members = [
7756
# Playwright tests
7857
"packages/playwright-tests/liveview",
7958
"packages/playwright-tests/web",
59+
"packages/playwright-tests/web-routing",
60+
"packages/playwright-tests/web-hash-routing",
61+
"packages/playwright-tests/barebones-template",
8062
"packages/playwright-tests/fullstack",
63+
"packages/playwright-tests/fullstack-errors",
64+
"packages/playwright-tests/fullstack-mounted",
65+
"packages/playwright-tests/fullstack-spread",
66+
"packages/playwright-tests/fullstack-routing",
67+
"packages/playwright-tests/fullstack-hydration-order",
8168
"packages/playwright-tests/suspense-carousel",
8269
"packages/playwright-tests/nested-suspense",
70+
"packages/playwright-tests/cli-optimization",
71+
"packages/playwright-tests/wasm-split-harness",
72+
"packages/playwright-tests/default-features-disabled",
73+
"packages/playwright-tests/fullstack-error-codes",
74+
"packages/playwright-tests/windows-headless",
8375

8476
# manganis
8577
"packages/manganis/manganis",
@@ -106,6 +98,7 @@ members = [
10698
"examples/01-app-demos/bluetooth-scanner",
10799
"examples/01-app-demos/file-explorer",
108100
"examples/01-app-demos/hotdog",
101+
"examples/01-app-demos/geolocation-native-plugin",
109102

110103
# Fullstack examples
111104
"examples/07-fullstack/hello-world",
@@ -121,28 +114,9 @@ members = [
121114
"examples/10-integrations/native-headless",
122115
"examples/10-integrations/native-headless-in-bevy",
123116
"examples/10-integrations/bevy",
124-
125-
# Playwright tests
126-
"packages/playwright-tests/liveview",
127-
"packages/playwright-tests/web",
128-
"packages/playwright-tests/web-routing",
129-
"packages/playwright-tests/web-hash-routing",
130-
"packages/playwright-tests/barebones-template",
131-
"packages/playwright-tests/fullstack",
132-
"packages/playwright-tests/fullstack-errors",
133-
"packages/playwright-tests/fullstack-mounted",
134-
"packages/playwright-tests/fullstack-spread",
135-
"packages/playwright-tests/fullstack-routing",
136-
"packages/playwright-tests/fullstack-hydration-order",
137-
"packages/playwright-tests/suspense-carousel",
138-
"packages/playwright-tests/nested-suspense",
139-
"packages/playwright-tests/cli-optimization",
140-
"packages/playwright-tests/wasm-split-harness",
141-
"packages/playwright-tests/default-features-disabled",
142-
"packages/playwright-tests/fullstack-error-codes",
143-
"packages/playwright-tests/windows-headless",
144117
]
145118

119+
146120
[workspace.package]
147121
version = "0.7.3"
148122

@@ -213,7 +187,8 @@ manganis-core = { path = "packages/manganis/manganis-core", version = "0.7.3" }
213187
manganis-macro = { path = "packages/manganis/manganis-macro", version = "0.7.3" }
214188
manganis-core-07 = { path = "packages/manganis/manganis-07", version = "0.7.2" }
215189

216-
# const-serialize. these are on "alpha" versions, but really, we are prepping for 0.8 but not committing to it yet
190+
# const-serialize.
191+
# these are on "alpha" versions, but really, we are prepping for 0.8 but not committing to it yet
217192
# once the workspace moves onto 0.8, we can clean this up, moving the const-serialize stuff back to normal versions
218193
const-serialize = { path = "packages/const-serialize", version = "0.8.0-alpha.0" }
219194
const-serialize-macro = { path = "packages/const-serialize-macro", version = "0.8.0-alpha.0" }
@@ -292,6 +267,7 @@ rustls = { version = "0.23.28", default-features = false, features = [
292267
] }
293268
serde_json = "1.0.140"
294269
serde = "1.0.219"
270+
schemars = "1.0"
295271
syn = "2.0"
296272
quote = "1.0"
297273
axum-core = "0.5"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "geolocation-native-plugin"
3+
version = "0.1.0"
4+
authors = ["Sabin Regmi <get2sabin@gmail.com>"]
5+
edition = "2021"
6+
publish = false
7+
8+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9+
10+
[dependencies]
11+
dioxus = { workspace = true, features = [] }
12+
manganis = { workspace = true }
13+
serde = { workspace = true, features = ["derive"] }
14+
serde_json = { workspace = true }
15+
thiserror = { workspace = true }
16+
17+
[features]
18+
default = ["mobile"]
19+
web = ["dioxus/web"]
20+
desktop = ["dioxus/desktop"]
21+
mobile = ["dioxus/mobile"]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#:schema ../../../packages/cli/schema.json
2+
3+
[bundle]
4+
identifier = "com.dioxuslabs.geolocation"
5+
publisher = "Dioxus Labs"
6+
7+
[ios]
8+
deployment_target = "16.2"
9+
background_modes = ["location"]
10+
11+
[ios.plist]
12+
NSSupportsLiveActivities = true
13+
14+
[[ios.widget_extensions]]
15+
source = "src/ios/widget"
16+
display_name = "Location Widget"
17+
bundle_id_suffix = "location-widget"
18+
deployment_target = "16.2"
19+
module_name = "GeolocationPlugin"
20+
21+
[android]
22+
min_sdk = 24
23+
target_sdk = 34
24+
features = ["android.hardware.location.gps"]
25+
26+
[permissions]
27+
location = { precision = "fine", description = "Access your precise location to provide location-based services" }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Geolocation demo
2+
3+
A minimal Dioxus application that implements a native plugin.
4+
5+
The plugin demonstrated here makes it possible to access the user's geolocation. It does a few things:
6+
7+
- Inspect and request location permissions using the native Android/iOS dialogs.
8+
- Configure one-shot position requests (high-accuracy toggle + maximum cached age).
9+
- Inspect the last reported coordinates, accuracy, altitude, heading, and speed.
10+
11+
The example shares the same metadata pipeline as any plugin crate: the native Gradle/Swift
12+
artifacts are embedded via linker symbols and bundled automatically by `dx`.
13+
14+
## Running the example
15+
16+
```bash
17+
# Inside the repository root
18+
dx serve --project examples/01-app-demos/geolocation --platform mobile
19+
```
20+
21+
For Android/iOS you’ll need the respective toolchains installed (Android SDK/NDK, Xcode) so the
22+
geolocation crate’s `build.rs` can build the native modules. The UI also works on desktop/web,
23+
but location calls will return an error because the plugin only supports mobile targets—those
24+
errors are shown inline in the demo.
25+
26+
## Things to try
27+
28+
1. Tap **Check permissions** to see the current OS state (granted/denied/prompt).
29+
2. Tap **Request permissions** to trigger the native dialog from within the app.
30+
3. Toggle *High accuracy* and set a *Max cached age* before requesting the current position.
31+
4. Observe the coordinate grid update whenever a new reading arrives, or the error banner if the
32+
operation fails (e.g., permissions denied or running on an unsupported platform).
Binary file not shown.

examples/01-app-demos/geolocation-native-plugin/assets/header.svg

Lines changed: 20 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)