Skip to content

Commit fd1fdd6

Browse files
committed
Fix the permissions piping
1 parent f5a1de2 commit fd1fdd6

File tree

3 files changed

+40
-50
lines changed

3 files changed

+40
-50
lines changed

packages/permissions/permissions-macro/src/permission.rs

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,42 +32,20 @@ impl ToTokens for PermissionParser {
3232
self.expr.to_string().hash(&mut hash);
3333
let permission_hash = format!("{:016x}", hash.finish());
3434

35-
// Check if this is a Custom permission by examining the expression
36-
// Custom permissions are built via PermissionBuilder::custom() or contain PermissionKind::Custom
37-
let expr_str = self.expr.to_string();
38-
let is_custom = expr_str.contains("custom()")
39-
|| expr_str.contains("Custom {")
40-
|| expr_str.contains("PermissionKind::Custom");
41-
4235
let expr = &self.expr;
36+
let link_section =
37+
crate::linker::generate_link_section(quote!(__PERMISSION), &permission_hash);
4338

44-
if is_custom {
45-
// For Custom permissions, skip linker section generation due to buffer size limitations
46-
// Custom permissions can exceed the 4096 byte buffer limit when serialized
47-
tokens.extend(quote! {
48-
{
49-
// Create the permission instance directly for Custom permissions
50-
// Skip linker section generation due to buffer size limitations
51-
const __PERMISSION: permissions_core::Permission = #expr;
52-
__PERMISSION
53-
}
54-
});
55-
} else {
56-
// For regular permissions, use the normal serialization approach with linker sections
57-
let link_section =
58-
crate::linker::generate_link_section(quote!(__PERMISSION), &permission_hash);
59-
60-
tokens.extend(quote! {
61-
{
62-
// Create the permission instance from the expression
63-
const __PERMISSION: permissions_core::Permission = #expr;
39+
tokens.extend(quote! {
40+
{
41+
// Create the permission instance from the expression
42+
const __PERMISSION: permissions::Permission = #expr;
6443

65-
#link_section
44+
#link_section
6645

67-
// Return the permission
68-
__PERMISSION
69-
}
70-
});
71-
}
46+
// Return the permission
47+
__PERMISSION
48+
}
49+
});
7250
}
7351
}

packages/permissions/permissions/README.md

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,24 @@ This crate provides a unified API for declaring permissions across supported pla
1717
### Basic Permission Declaration
1818

1919
```rust
20-
use permissions::{static_permission, Permission};
20+
use permissions::{static_permission, Permission, PermissionBuilder, PermissionKind};
2121

22-
// Declare a camera permission
23-
const CAMERA: Permission = static_permission!(Camera, description = "Take photos");
22+
// Declare a camera permission using the builder
23+
const CAMERA: Permission = static_permission!(
24+
Permission::new(PermissionKind::Camera, "Take photos")
25+
);
2426

25-
// Declare a location permission with precision
26-
const LOCATION: Permission = static_permission!(Location(Fine), description = "Track your runs");
27+
// Declare a fine-grained location permission
28+
const LOCATION: Permission = static_permission!(
29+
PermissionBuilder::location(permissions::LocationPrecision::Fine)
30+
.with_description("Track your runs")
31+
.build()
32+
);
2733

2834
// Declare a microphone permission
29-
const MICROPHONE: Permission = static_permission!(Microphone, description = "Record audio");
35+
const MICROPHONE: Permission = static_permission!(
36+
Permission::new(PermissionKind::Microphone, "Record audio")
37+
);
3038
```
3139

3240
### Custom Permissions (For Untested or Special Use Cases)
@@ -35,16 +43,16 @@ For permissions that aren't yet tested or for special use cases, use the `Custom
3543
with platform-specific identifiers:
3644

3745
```rust
38-
use permissions::{static_permission, Permission};
46+
use permissions::{static_permission, Permission, PermissionBuilder};
3947

4048
// Example: Request storage permission
4149
const STORAGE: Permission = static_permission!(
42-
Custom {
43-
android = "android.permission.READ_EXTERNAL_STORAGE",
44-
ios = "NSPhotoLibraryUsageDescription",
45-
macos = "NSPhotoLibraryUsageDescription"
46-
},
47-
description = "Access files on your device"
50+
PermissionBuilder::custom()
51+
.with_android("android.permission.READ_EXTERNAL_STORAGE")
52+
.with_ios("NSPhotoLibraryUsageDescription")
53+
.with_macos("NSPhotoLibraryUsageDescription")
54+
.with_description("Access files on your device")
55+
.build()
4856
);
4957
```
5058

@@ -55,9 +63,13 @@ const STORAGE: Permission = static_permission!(
5563
### Using Permissions
5664

5765
```rust
58-
use permissions::{static_permission, Permission, Platform};
66+
use permissions::{
67+
static_permission, Permission, PermissionBuilder, PermissionKind, Platform,
68+
};
5969

60-
const CAMERA: Permission = static_permission!(Camera, description = "Take photos");
70+
const CAMERA: Permission = static_permission!(
71+
Permission::new(PermissionKind::Camera, "Take photos")
72+
);
6173

6274
// Get the description
6375
println!("Description: {}", CAMERA.description());

packages/permissions/permissions/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
//! > to preserve backward compatibility with existing code.
3131
3232
pub use permissions_core::{
33-
LocationPrecision, Permission, PermissionKind, PermissionManifest, Platform, PlatformFlags,
34-
PlatformIdentifiers,
33+
CustomPermissionBuilder, LocationPrecision, Permission, PermissionBuilder, PermissionKind,
34+
PermissionManifest, Platform, PlatformFlags, PlatformIdentifiers,
3535
};
3636
pub use permissions_macro::{permission, static_permission};
3737

0 commit comments

Comments
 (0)