@@ -42,6 +42,19 @@ const ACL_MANIFESTS_FILE_NAME: &str = "acl-manifests.json";
4242pub struct InlinedPlugin {
4343 commands : & ' static [ & ' static str ] ,
4444 permissions_path_pattern : Option < & ' static str > ,
45+ default : Option < DefaultPermissionRule > ,
46+ }
47+
48+ /// Variants of a generated default permission that can be used on an [`InlinedPlugin`].
49+ #[ derive( Debug ) ]
50+ pub enum DefaultPermissionRule {
51+ /// Allow all commands from [`InlinedPlugin::commands`].
52+ AllowAllCommands ,
53+ /// Allow the given list of permissions.
54+ ///
55+ /// Note that the list refers to permissions instead of command names,
56+ /// so for example a command called `execute` would need to be allowed as `allow-execute`.
57+ Allow ( Vec < String > ) ,
4558}
4659
4760impl InlinedPlugin {
@@ -65,6 +78,14 @@ impl InlinedPlugin {
6578 self . permissions_path_pattern . replace ( pattern) ;
6679 self
6780 }
81+
82+ /// Creates a default permission for the plugin using the given rule.
83+ ///
84+ /// Alternatively you can pull a permission in the filesystem in the permissions directory, see [`Self::permissions_path_pattern`].
85+ pub fn default_permission ( mut self , default : DefaultPermissionRule ) -> Self {
86+ self . default . replace ( default) ;
87+ self
88+ }
6889}
6990
7091/// Tauri application permission manifest.
@@ -337,12 +358,35 @@ pub fn inline_plugins(
337358 let mut permission_files = if plugin. commands . is_empty ( ) {
338359 Vec :: new ( )
339360 } else {
340- tauri_utils:: acl:: build:: autogenerate_command_permissions (
361+ let autogenerated = tauri_utils:: acl:: build:: autogenerate_command_permissions (
341362 & plugin_out_dir,
342363 plugin. commands ,
343364 "" ,
344365 false ,
345366 ) ;
367+
368+ let default_permissions = plugin. default . map ( |default| match default {
369+ DefaultPermissionRule :: AllowAllCommands => autogenerated. allowed ,
370+ DefaultPermissionRule :: Allow ( permissions) => permissions,
371+ } ) ;
372+ if let Some ( default_permissions) = default_permissions {
373+ let default_permission_toml = format ! (
374+ r###"# Automatically generated - DO NOT EDIT!
375+ [default]
376+ permissions = [{default_permissions}]
377+ "### ,
378+ default_permissions = default_permissions
379+ . iter( )
380+ . map( |p| format!( "\" {p}\" " ) )
381+ . collect:: <Vec <String >>( )
382+ . join( "," )
383+ ) ;
384+
385+ let default_permission_toml_path = plugin_out_dir. join ( "default.toml" ) ;
386+
387+ write_if_changed ( & default_permission_toml, & default_permission_toml_path) ;
388+ }
389+
346390 tauri_utils:: acl:: build:: define_permissions (
347391 & plugin_out_dir. join ( "*" ) . to_string_lossy ( ) ,
348392 name,
@@ -384,6 +428,12 @@ pub fn inline_plugins(
384428 Ok ( acl_manifests)
385429}
386430
431+ fn write_if_changed ( content : & str , path : & Path ) {
432+ if content != read_to_string ( path) . unwrap_or_default ( ) {
433+ std:: fs:: write ( path, content) . unwrap_or_else ( |_| panic ! ( "unable to autogenerate {path:?}" ) ) ;
434+ }
435+ }
436+
387437pub fn app_manifest_permissions (
388438 out_dir : & Path ,
389439 manifest : AppManifest ,
0 commit comments