33// SPDX-License-Identifier: MIT
44
55use std:: {
6+ collections:: HashMap ,
67 env:: { var, var_os} ,
7- fs:: { copy, create_dir, create_dir_all, remove_dir_all, rename} ,
8+ fs:: { copy, create_dir, create_dir_all, read_to_string , remove_dir_all, rename, write } ,
89 path:: { Path , PathBuf } ,
910} ;
1011
1112use anyhow:: { Context , Result } ;
13+ use serde:: { Deserialize , Serialize } ;
14+
15+ #[ derive( Deserialize , Serialize ) ]
16+ pub ( crate ) struct PluginMetadata {
17+ pub path : PathBuf ,
18+ }
1219
1320#[ derive( Default ) ]
1421pub struct PluginBuilder {
@@ -49,6 +56,7 @@ impl PluginBuilder {
4956
5057 let tauri_library_path = std:: env:: var ( "DEP_TAURI_ANDROID_LIBRARY_PATH" )
5158 . expect ( "missing `DEP_TAURI_ANDROID_LIBRARY_PATH` environment variable. Make sure `tauri` is a dependency of the plugin." ) ;
59+ println ! ( "cargo:rerun-if-env-changed=DEP_TAURI_ANDROID_LIBRARY_PATH" ) ;
5260
5361 create_dir_all ( source. join ( ".tauri" ) ) . context ( "failed to create .tauri directory" ) ?;
5462 copy_folder (
@@ -62,12 +70,15 @@ impl PluginBuilder {
6270 let pkg_name = var ( "CARGO_PKG_NAME" ) . unwrap ( ) ;
6371 println ! ( "cargo:rerun-if-env-changed=TAURI_ANDROID_PROJECT_PATH" ) ;
6472
65- inject_android_project (
66- & source,
67- project_dir. join ( ".tauri" ) . join ( "plugins" ) . join ( pkg_name) ,
68- & [ "tauri-api" ] ,
69- )
70- . context ( "failed to inject plugin Android project" ) ?;
73+ let plugins_json_path = project_dir. join ( ".tauri" ) . join ( "plugins.json" ) ;
74+ let mut plugins: HashMap < String , PluginMetadata > = if plugins_json_path. exists ( ) {
75+ let s = read_to_string ( & plugins_json_path) ?;
76+ serde_json:: from_str ( & s) ?
77+ } else {
78+ Default :: default ( )
79+ } ;
80+ plugins. insert ( pkg_name, PluginMetadata { path : source } ) ;
81+ write ( & plugins_json_path, serde_json:: to_string ( & plugins) ?) ?;
7182 }
7283 }
7384 }
0 commit comments