@@ -14,24 +14,12 @@ use tauri_utils::{
1414} ;
1515
1616use std:: {
17+ collections:: HashSet ,
1718 fs:: { create_dir_all, write} ,
1819 path:: Path ,
1920} ;
2021
21- macro_rules! move_allowlist_object {
22- ( $plugins: ident, $value: expr, $plugin: literal, $field: literal) => { {
23- if $value != Default :: default ( ) {
24- $plugins
25- . entry( $plugin)
26- . or_insert_with( || Value :: Object ( Default :: default ( ) ) )
27- . as_object_mut( )
28- . unwrap( )
29- . insert( $field. into( ) , serde_json:: to_value( $value. clone( ) ) ?) ;
30- }
31- } } ;
32- }
33-
34- pub fn migrate ( tauri_dir : & Path ) -> Result < ( ) > {
22+ pub fn migrate ( tauri_dir : & Path ) -> Result < MigratedConfig > {
3523 if let Ok ( ( mut config, config_path) ) =
3624 tauri_utils_v1:: config:: parse:: parse_value ( tauri_dir. join ( "tauri.conf.json" ) )
3725 {
@@ -50,7 +38,7 @@ pub fn migrate(tauri_dir: &Path) -> Result<()> {
5038 . into_iter ( )
5139 . map ( |p| PermissionEntry :: PermissionRef ( p. to_string ( ) . try_into ( ) . unwrap ( ) ) )
5240 . collect ( ) ;
53- permissions. extend ( migrated. permissions ) ;
41+ permissions. extend ( migrated. permissions . clone ( ) ) ;
5442
5543 let capabilities_path = config_path. parent ( ) . unwrap ( ) . join ( "capabilities" ) ;
5644 create_dir_all ( & capabilities_path) ?;
@@ -73,18 +61,23 @@ pub fn migrate(tauri_dir: &Path) -> Result<()> {
7361 ] ,
7462 } ) ?,
7563 ) ?;
64+
65+ return Ok ( migrated) ;
7666 }
7767
78- Ok ( ( ) )
68+ Ok ( Default :: default ( ) )
7969}
8070
81- struct MigratedConfig {
82- permissions : Vec < PermissionEntry > ,
71+ #[ derive( Default ) ]
72+ pub struct MigratedConfig {
73+ pub permissions : Vec < PermissionEntry > ,
74+ pub plugins : HashSet < String > ,
8375}
8476
8577fn migrate_config ( config : & mut Value ) -> Result < MigratedConfig > {
8678 let mut migrated = MigratedConfig {
8779 permissions : Vec :: new ( ) ,
80+ plugins : HashSet :: new ( ) ,
8881 } ;
8982
9083 if let Some ( config) = config. as_object_mut ( ) {
@@ -101,8 +94,9 @@ fn migrate_config(config: &mut Value) -> Result<MigratedConfig> {
10194 if let Some ( tauri_config) = config. get_mut ( "tauri" ) . and_then ( |c| c. as_object_mut ( ) ) {
10295 // allowlist
10396 if let Some ( allowlist) = tauri_config. remove ( "allowlist" ) {
104- let allowlist = process_allowlist ( tauri_config, & mut plugins , allowlist) ?;
97+ let allowlist = process_allowlist ( tauri_config, allowlist) ?;
10598 let permissions = allowlist_to_permissions ( allowlist) ;
99+ migrated. plugins = plugins_from_permissions ( & permissions) ;
106100 migrated. permissions = permissions;
107101 }
108102
@@ -178,8 +172,11 @@ fn process_build(config: &mut Map<String, Value>) {
178172 if let Some ( dist_dir) = build_config. remove ( "distDir" ) {
179173 build_config. insert ( "frontendDist" . into ( ) , dist_dir) ;
180174 }
181- if let Some ( dist_dir) = build_config. remove ( "devPath" ) {
182- build_config. insert ( "devUrl" . into ( ) , dist_dir) ;
175+ if let Some ( dev_path) = build_config. remove ( "devPath" ) {
176+ let is_url = url:: Url :: parse ( dev_path. as_str ( ) . unwrap_or_default ( ) ) . is_ok ( ) ;
177+ if is_url {
178+ build_config. insert ( "devUrl" . into ( ) , dev_path) ;
179+ }
183180 }
184181 if let Some ( with_global_tauri) = build_config. remove ( "withGlobalTauri" ) {
185182 config
@@ -282,13 +279,10 @@ fn process_security(security: &mut Map<String, Value>) -> Result<()> {
282279
283280fn process_allowlist (
284281 tauri_config : & mut Map < String , Value > ,
285- plugins : & mut Map < String , Value > ,
286282 allowlist : Value ,
287283) -> Result < tauri_utils_v1:: config:: AllowlistConfig > {
288284 let allowlist: tauri_utils_v1:: config:: AllowlistConfig = serde_json:: from_value ( allowlist) ?;
289285
290- move_allowlist_object ! ( plugins, allowlist. shell. open, "shell" , "open" ) ;
291-
292286 if allowlist. protocol . asset_scope != Default :: default ( ) {
293287 let security = tauri_config
294288 . entry ( "security" )
@@ -524,6 +518,34 @@ fn process_updater(
524518 Ok ( ( ) )
525519}
526520
521+ const KNOWN_PLUGINS : & [ & str ] = & [
522+ "fs" ,
523+ "shell" ,
524+ "dialog" ,
525+ "http" ,
526+ "notification" ,
527+ "global-shortcut" ,
528+ "os" ,
529+ "process" ,
530+ "clipboard-manager" ,
531+ ] ;
532+
533+ fn plugins_from_permissions ( permissions : & Vec < PermissionEntry > ) -> HashSet < String > {
534+ let mut plugins = HashSet :: new ( ) ;
535+
536+ for permission in permissions {
537+ let permission = permission. identifier ( ) . get ( ) ;
538+ for plugin in KNOWN_PLUGINS {
539+ if permission. starts_with ( plugin) {
540+ plugins. insert ( plugin. to_string ( ) ) ;
541+ break ;
542+ }
543+ }
544+ }
545+
546+ plugins
547+ }
548+
527549#[ cfg( test) ]
528550mod test {
529551 fn migrate ( original : & serde_json:: Value ) -> serde_json:: Value {
@@ -846,4 +868,22 @@ mod test {
846868 "connect-src migration failed"
847869 ) ;
848870 }
871+
872+ #[ test]
873+ fn migrate_invalid_url_dev_path ( ) {
874+ let original = serde_json:: json!( {
875+ "build" : {
876+ "devPath" : "../src" ,
877+ "distDir" : "../src"
878+ }
879+ } ) ;
880+
881+ let migrated = migrate ( & original) ;
882+
883+ assert ! ( migrated[ "build" ] . get( "devUrl" ) . is_none( ) ) ;
884+ assert_eq ! (
885+ migrated[ "build" ] [ "distDir" ] ,
886+ original[ "build" ] [ "frontendDist" ]
887+ ) ;
888+ }
849889}
0 commit comments