initial plugin config with androidmanifest rewrite

pull/504/head
FabianLars 2 years ago
parent a379e6a1e6
commit c4356b4d1b
No known key found for this signature in database
GPG Key ID: 838F329885A9C43D

@ -9,6 +9,8 @@ links = "tauri-plugin-deep-link"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
serde = "1"
serde_json = "1"
tauri-build = { git = "https://github.com/lucasfernog/tauri", branch = "feat/ipc-custom-protocol" }
[dependencies]
@ -19,3 +21,6 @@ log = "0.4"
thiserror = "1"
url = "2"
[patch."https://github.com/lucasfernog/tauri"]
tauri-build = { path = "C:/Users/Fabian-Lars/dev/FabianLars/tauri-lucas/core/tauri-build" }
tauri = { path = "C:/Users/Fabian-Lars/dev/FabianLars/tauri-lucas/core/tauri" }

@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- TODO: (tauri-cli?) Add auto manifest rewriter to add domains. Format: -->
<application>
<activity android:name="app-id.MainActivity" android:exported="true">
<activity android:name="${applicationId}.MainActivity" android:exported="true">
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />

@ -60,7 +60,7 @@ class DeepLinkPlugin(private val activity: Activity): Plugin(activity) {
if (intent.action == Intent.ACTION_VIEW) {
// TODO: check if it makes sense to split up init url and last url
this.lastUrl = intent.data.toString()
// TODO: Emit event - may not work here timing wise
// TODO: Test if emitting it here makes sense timing wise
val event = JSObject()
event.put("url", this.lastUrl)
this.channel?.send(event)

@ -4,6 +4,38 @@
use std::process::exit;
#[derive(Clone, serde::Deserialize)]
struct Config {
android: Vec<AndroidConfig>,
}
#[derive(Clone, serde::Deserialize)]
struct AndroidConfig {
domain: String,
#[serde(rename = "pathPrefix")]
path_prefix: Option<String>,
}
// TODO: Consider using activity-alias in case users may have multiple activities in their app.
// TODO: Do we need multiple pathPrefixes? Do we want to support the other path* configs too?
fn intent_filter(domain: &str, path: Option<&str>) -> String {
format!(
r#"<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="{domain}" />{}
</intent-filter>"#,
if let Some(path) = path {
format!("\n <data android:pathPrefix=\"{path}\" />")
} else {
String::new()
}
)
}
fn main() {
if let Err(error) = tauri_build::mobile::PluginBuilder::new()
.android_path("android")
@ -12,4 +44,34 @@ fn main() {
println!("{error:#}");
exit(1);
}
if let Some(config) = tauri_build::config::plugin_config::<Config>("deep-link") {
tauri_build::mobile::update_android_manifest(
"DEEP LINK PLUGIN",
"activity",
config
.android
.iter()
.map(|e| intent_filter(&e.domain, e.path_prefix.as_deref()))
.collect::<Vec<_>>()
.join("\n"),
)
.expect("failed to rewrite AndroidManifest.xml");
/* #[cfg(target_os = "macos")]
{
tauri_build::mobile::update_entitlements(|entitlements| {
entitlements.insert(
"com.apple.developer.associated-domains".into(),
config
.domains
.into_iter()
.map(Into::into)
.collect::<Vec<_>>()
.into(),
);
})
.expect("failed to update entitlements");
} */
}
}

@ -637,6 +637,8 @@ dependencies = [
name = "deep-link-example"
version = "0.0.0"
dependencies = [
"serde",
"serde_json",
"tauri",
"tauri-build",
"tauri-plugin-deep-link",
@ -2735,9 +2737,9 @@ dependencies = [
[[package]]
name = "signal-hook"
version = "0.3.16"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b824b6e687aff278cdbf3b36f07aa52d4bd4099699324d5da86a2ebce3aa00b3"
checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801"
dependencies = [
"libc",
"signal-hook-registry",
@ -2985,7 +2987,6 @@ checksum = "1b1c7f239eb94671427157bd93b3694320f3668d4e1eff08c7285366fd777fac"
[[package]]
name = "tauri"
version = "2.0.0-alpha.10"
source = "git+https://github.com/lucasfernog/tauri?branch=feat/ipc-custom-protocol#3e04d52348811e2f0e508015634a2d9ff74866de"
dependencies = [
"anyhow",
"bytes",
@ -3030,7 +3031,6 @@ dependencies = [
[[package]]
name = "tauri-build"
version = "2.0.0-alpha.6"
source = "git+https://github.com/lucasfernog/tauri?branch=feat/ipc-custom-protocol#3e04d52348811e2f0e508015634a2d9ff74866de"
dependencies = [
"anyhow",
"cargo_toml",
@ -3048,7 +3048,6 @@ dependencies = [
[[package]]
name = "tauri-codegen"
version = "2.0.0-alpha.6"
source = "git+https://github.com/lucasfernog/tauri?branch=feat/ipc-custom-protocol#3e04d52348811e2f0e508015634a2d9ff74866de"
dependencies = [
"base64",
"brotli",
@ -3073,7 +3072,6 @@ dependencies = [
[[package]]
name = "tauri-macros"
version = "2.0.0-alpha.6"
source = "git+https://github.com/lucasfernog/tauri?branch=feat/ipc-custom-protocol#3e04d52348811e2f0e508015634a2d9ff74866de"
dependencies = [
"heck",
"proc-macro2",
@ -3099,7 +3097,6 @@ dependencies = [
[[package]]
name = "tauri-runtime"
version = "0.13.0-alpha.6"
source = "git+https://github.com/lucasfernog/tauri?branch=feat/ipc-custom-protocol#3e04d52348811e2f0e508015634a2d9ff74866de"
dependencies = [
"gtk",
"http",
@ -3119,7 +3116,6 @@ dependencies = [
[[package]]
name = "tauri-runtime-wry"
version = "0.13.0-alpha.6"
source = "git+https://github.com/lucasfernog/tauri?branch=feat/ipc-custom-protocol#3e04d52348811e2f0e508015634a2d9ff74866de"
dependencies = [
"cocoa",
"gtk",
@ -3139,7 +3135,6 @@ dependencies = [
[[package]]
name = "tauri-utils"
version = "2.0.0-alpha.6"
source = "git+https://github.com/lucasfernog/tauri?branch=feat/ipc-custom-protocol#3e04d52348811e2f0e508015634a2d9ff74866de"
dependencies = [
"brotli",
"ctor",

@ -19,9 +19,15 @@ tauri-build = { git = "https://github.com/lucasfernog/tauri", branch = "feat/ipc
[dependencies]
tauri = { git = "https://github.com/lucasfernog/tauri", branch = "feat/ipc-custom-protocol", features = [] }
tauri-plugin-deep-link = { path = "../../../" }
serde = "1"
serde_json = "1"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem and the built-in dev server is disabled.
# If you use cargo directly instead of tauri's cli you can use this feature flag to switch between tauri's `dev` and `build` modes.
# DO NOT REMOVE!!
custom-protocol = [ "tauri/custom-protocol" ]
[patch."https://github.com/lucasfernog/tauri"]
tauri-build = { path = "C:/Users/Fabian-Lars/dev/FabianLars/tauri-lucas/core/tauri-build" }
tauri = { path = "C:/Users/Fabian-Lars/dev/FabianLars/tauri-lucas/core/tauri" }

@ -7,7 +7,7 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<!-- <intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
@ -15,12 +15,31 @@
<data android:scheme="http" />
<data android:scheme="https" />
<!-- Each host needs a new intent-filter -->
<!- - Each host needs a new intent-filter - ->
<data android:host="fabianlars.de" />
<!-- This should also be configurable otherwise the app will trigger on all paths -->
<!- - This should also be configurable otherwise the app will trigger on all paths - ->
<data android:pathPrefix="/intent" />
</intent-filter> -->
<!-- DEEP LINK PLUGIN. AUTO-GENERATED. DO NOT REMOVE. -->
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="fabianlars.de" />
<data android:pathPrefix="/intent" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="tauri.app" />
</intent-filter>
<!-- DEEP LINK PLUGIN. AUTO-GENERATED. DO NOT REMOVE. -->
</activity>
<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true">

@ -1,7 +1,7 @@
{
"build": {
"beforeDevCommand": "yarn dev",
"beforeBuildCommand": "yarn build",
"beforeDevCommand": "pnpm dev",
"beforeBuildCommand": "pnpm build",
"devPath": "http://localhost:1420",
"distDir": "../dist",
"withGlobalTauri": false
@ -56,5 +56,17 @@
"width": 800
}
]
},
"plugins": {
"whatever": "helloworld",
"sec": {
"hello": "world"
},
"deep-link": {
"android": [
{ "domain": "fabianlars.de", "pathPrefix": "/intent" },
{ "domain": "tauri.app" }
]
}
}
}

@ -12,4 +12,4 @@ export async function getLastLink(): Promise<string[] | null> {
return await window.__TAURI_INVOKE__("plugin:deep-link|get_last_link");
}
// TODO: REGISTER EVENT LISTENER
// TODO: onUrlEvent function (helper function for the event listener)

@ -0,0 +1,13 @@
#![allow(dead_code)]
#[derive(serde::Deserialize)]
pub struct Config {
android: Vec<AndroidConfig>,
}
#[derive(serde::Deserialize)]
pub struct AndroidConfig {
domain: String,
#[serde(rename = "pathPrefix")]
path_prefix: Option<String>,
}

@ -9,6 +9,7 @@ use tauri::{
};
mod commands;
mod config;
mod error;
pub use error::{Error, Result};
@ -129,7 +130,7 @@ impl<R: Runtime, T: Manager<R>> crate::DeepLinkExt<R> for T {
}
/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
pub fn init<R: Runtime>() -> TauriPlugin<R, Option<config::Config>> {
Builder::new("deep-link")
.js_init_script(include_str!("api-iife.js").to_string())
.invoke_handler(tauri::generate_handler![

Loading…
Cancel
Save