mirror of
https://github.com/readest/readest.git
synced 2026-04-28 19:42:21 +00:00
This commit is contained in:
parent
f2f744a2fe
commit
f46be89036
16 changed files with 156 additions and 29 deletions
|
|
@ -13,6 +13,7 @@ const COMMANDS: &[&str] = &[
|
|||
"iap_fetch_products",
|
||||
"iap_purchase_product",
|
||||
"iap_restore_purchases",
|
||||
"get_system_color_scheme",
|
||||
];
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -533,6 +533,12 @@ class NativeBridgePlugin: Plugin {
|
|||
invoke.resolve(["purchases": restored])
|
||||
}
|
||||
}
|
||||
|
||||
@objc public func get_system_color_scheme(_ invoke: Invoke) {
|
||||
let userInterfaceStyle = UITraitCollection.current.userInterfaceStyle
|
||||
let colorScheme = (userInterfaceStyle == .dark) ? "dark" : "light"
|
||||
invoke.resolve(["colorScheme": colorScheme])
|
||||
}
|
||||
}
|
||||
|
||||
@_cdecl("init_plugin_native_bridge")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
# Automatically generated - DO NOT EDIT!
|
||||
|
||||
"$schema" = "../../schemas/schema.json"
|
||||
|
||||
[[permission]]
|
||||
identifier = "allow-get-system-color-scheme"
|
||||
description = "Enables the get_system_color_scheme command without any pre-configured scope."
|
||||
commands.allow = ["get_system_color_scheme"]
|
||||
|
||||
[[permission]]
|
||||
identifier = "deny-get-system-color-scheme"
|
||||
description = "Denies the get_system_color_scheme command without any pre-configured scope."
|
||||
commands.deny = ["get_system_color_scheme"]
|
||||
|
|
@ -18,6 +18,7 @@ Default permissions for the plugin
|
|||
- `allow-iap-fetch-products`
|
||||
- `allow-iap-purchase-product`
|
||||
- `allow-iap-restore-purchases`
|
||||
- `allow-get-system-color-scheme`
|
||||
|
||||
## Permission Table
|
||||
|
||||
|
|
@ -161,6 +162,32 @@ Denies the get_sys_fonts_list command without any pre-configured scope.
|
|||
<tr>
|
||||
<td>
|
||||
|
||||
`native-bridge:allow-get-system-color-scheme`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Enables the get_system_color_scheme command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`native-bridge:deny-get-system-color-scheme`
|
||||
|
||||
</td>
|
||||
<td>
|
||||
|
||||
Denies the get_system_color_scheme command without any pre-configured scope.
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
`native-bridge:allow-iap-fetch-products`
|
||||
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ permissions = [
|
|||
"allow-iap-fetch-products",
|
||||
"allow-iap-purchase-product",
|
||||
"allow-iap-restore-purchases",
|
||||
"allow-get-system-color-scheme",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -354,6 +354,18 @@
|
|||
"const": "deny-get-sys-fonts-list",
|
||||
"markdownDescription": "Denies the get_sys_fonts_list command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the get_system_color_scheme command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "allow-get-system-color-scheme",
|
||||
"markdownDescription": "Enables the get_system_color_scheme command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the get_system_color_scheme command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "deny-get-system-color-scheme",
|
||||
"markdownDescription": "Denies the get_system_color_scheme command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the iap_fetch_products command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
|
@ -463,10 +475,10 @@
|
|||
"markdownDescription": "Denies the use_background_audio command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-auth-with-safari`\n- `allow-auth-with-custom-tab`\n- `allow-copy-uri-to-path`\n- `allow-use-background-audio`\n- `allow-install-package`\n- `allow-set-system-ui-visibility`\n- `allow-get-status-bar-height`\n- `allow-get-sys-fonts-list`\n- `allow-intercept-keys`\n- `allow-lock-screen-orientation`\n- `allow-iap-initialize`\n- `allow-iap-fetch-products`\n- `allow-iap-purchase-product`\n- `allow-iap-restore-purchases`",
|
||||
"description": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-auth-with-safari`\n- `allow-auth-with-custom-tab`\n- `allow-copy-uri-to-path`\n- `allow-use-background-audio`\n- `allow-install-package`\n- `allow-set-system-ui-visibility`\n- `allow-get-status-bar-height`\n- `allow-get-sys-fonts-list`\n- `allow-intercept-keys`\n- `allow-lock-screen-orientation`\n- `allow-iap-initialize`\n- `allow-iap-fetch-products`\n- `allow-iap-purchase-product`\n- `allow-iap-restore-purchases`\n- `allow-get-system-color-scheme`",
|
||||
"type": "string",
|
||||
"const": "default",
|
||||
"markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-auth-with-safari`\n- `allow-auth-with-custom-tab`\n- `allow-copy-uri-to-path`\n- `allow-use-background-audio`\n- `allow-install-package`\n- `allow-set-system-ui-visibility`\n- `allow-get-status-bar-height`\n- `allow-get-sys-fonts-list`\n- `allow-intercept-keys`\n- `allow-lock-screen-orientation`\n- `allow-iap-initialize`\n- `allow-iap-fetch-products`\n- `allow-iap-purchase-product`\n- `allow-iap-restore-purchases`"
|
||||
"markdownDescription": "Default permissions for the plugin\n#### This default permission set includes:\n\n- `allow-auth-with-safari`\n- `allow-auth-with-custom-tab`\n- `allow-copy-uri-to-path`\n- `allow-use-background-audio`\n- `allow-install-package`\n- `allow-set-system-ui-visibility`\n- `allow-get-status-bar-height`\n- `allow-get-sys-fonts-list`\n- `allow-intercept-keys`\n- `allow-lock-screen-orientation`\n- `allow-iap-initialize`\n- `allow-iap-fetch-products`\n- `allow-iap-purchase-product`\n- `allow-iap-restore-purchases`\n- `allow-get-system-color-scheme`"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,3 +112,10 @@ pub(crate) async fn iap_restore_purchases<R: Runtime>(
|
|||
) -> Result<IAPRestorePurchasesResponse> {
|
||||
app.native_bridge().iap_restore_purchases()
|
||||
}
|
||||
|
||||
#[command]
|
||||
pub(crate) async fn get_system_color_scheme<R: Runtime>(
|
||||
app: AppHandle<R>,
|
||||
) -> Result<GetSystemColorSchemeResponse> {
|
||||
app.native_bridge().get_system_color_scheme()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,4 +98,8 @@ impl<R: Runtime> NativeBridge<R> {
|
|||
pub fn iap_restore_purchases(&self) -> crate::Result<IAPRestorePurchasesResponse> {
|
||||
Err(crate::Error::UnsupportedPlatformError)
|
||||
}
|
||||
|
||||
pub fn get_system_color_scheme(&self) -> crate::Result<GetSystemColorSchemeResponse> {
|
||||
Err(crate::Error::UnsupportedPlatformError)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
|
|||
commands::iap_fetch_products,
|
||||
commands::iap_purchase_product,
|
||||
commands::iap_restore_purchases,
|
||||
commands::get_system_color_scheme,
|
||||
])
|
||||
.setup(|app, api| {
|
||||
#[cfg(mobile)]
|
||||
|
|
|
|||
|
|
@ -147,11 +147,17 @@ impl<R: Runtime> NativeBridge<R> {
|
|||
}
|
||||
|
||||
impl<R: Runtime> NativeBridge<R> {
|
||||
pub fn iap_restore_purchases(
|
||||
&self,
|
||||
) -> crate::Result<IAPRestorePurchasesResponse> {
|
||||
pub fn iap_restore_purchases(&self) -> crate::Result<IAPRestorePurchasesResponse> {
|
||||
self.0
|
||||
.run_mobile_plugin("iap_restore_purchases", ())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Runtime> NativeBridge<R> {
|
||||
pub fn get_system_color_scheme(&self) -> crate::Result<GetSystemColorSchemeResponse> {
|
||||
self.0
|
||||
.run_mobile_plugin("get_system_color_scheme", ())
|
||||
.map_err(Into::into)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ pub struct Purchase {
|
|||
pub purchase_date: String,
|
||||
pub original_transaction_id: String,
|
||||
pub purchase_state: String, // "purchased", "pending", "cancelled"
|
||||
pub platform: String, // "ios" or "android"
|
||||
pub platform: String, // "ios" or "android"
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
|
|
@ -152,3 +152,9 @@ pub struct IAPPurchaseProductResponse {
|
|||
pub struct IAPRestorePurchasesResponse {
|
||||
pub purchases: Vec<Purchase>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct GetSystemColorSchemeResponse {
|
||||
pub color_scheme: String, // "light" or "dark"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue