Browse Source

feat(cli): update template with permissions and capabilities (#8666)

* feat(cli): update template with permissions and capabilities

* update gitignore [skip ci]
Lucas Fernandes Nogueira 1 năm trước cách đây
mục cha
commit
f492efd714

+ 2 - 1
.changes/config.json

@@ -218,7 +218,8 @@
       "manager": "rust",
       "dependencies": [
         "tauri"
-      ]
+      ],
+      "postversion": "node ../../.scripts/covector/sync-cli-metadata.js ${ pkg.pkg } ${ release.type }"
     },
     "tauri-build": {
       "path": "./core/tauri-build",

+ 6 - 0
.changes/update-template-for-permissions.md

@@ -0,0 +1,6 @@
+---
+"tauri-cli": patch:enhance
+"@tauri-apps/cli": patch:enhance
+---
+
+Update app and plugin template following the new access control permission model.

+ 2 - 1
tooling/cli/metadata-v2.json

@@ -4,5 +4,6 @@
     "node": ">= 10.0.0"
   },
   "tauri": "2.0.0-alpha.21",
-  "tauri-build": "2.0.0-alpha.14"
+  "tauri-build": "2.0.0-alpha.14",
+  "tauri-plugin": "2.0.0-alpha.-1"
 }

+ 2 - 0
tooling/cli/src/lib.rs

@@ -69,6 +69,8 @@ pub struct VersionMetadata {
   tauri: String,
   #[serde(rename = "tauri-build")]
   tauri_build: String,
+  #[serde(rename = "tauri-plugin")]
+  tauri_plugin: String,
 }
 
 #[derive(Deserialize)]

+ 10 - 1
tooling/cli/src/plugin/init.rs

@@ -84,7 +84,7 @@ pub fn command(mut options: Options) -> Result<()> {
   if std::fs::read_dir(&template_target_path)?.count() > 0 {
     warn!("Plugin dir ({:?}) not empty.", template_target_path);
   } else {
-    let (tauri_dep, tauri_example_dep, tauri_build_dep) =
+    let (tauri_dep, tauri_example_dep, tauri_build_dep, tauri_plugin_dep) =
       if let Some(tauri_path) = options.tauri_path {
         (
           format!(
@@ -99,12 +99,20 @@ pub fn command(mut options: Options) -> Result<()> {
             "{{  path = {:?} }}",
             resolve_tauri_path(&tauri_path, "core/tauri-build")
           ),
+          format!(
+            r#"{{  path = {:?}, features = ["build"] }}"#,
+            resolve_tauri_path(&tauri_path, "core/tauri-plugin")
+          ),
         )
       } else {
         (
           format!(r#"{{ version = "{}" }}"#, metadata.tauri),
           format!(r#"{{ version = "{}" }}"#, metadata.tauri),
           format!(r#"{{ version = "{}" }}"#, metadata.tauri_build),
+          format!(
+            r#"{{ version = "{}", features = ["build"] }}"#,
+            metadata.tauri_plugin
+          ),
         )
       };
 
@@ -117,6 +125,7 @@ pub fn command(mut options: Options) -> Result<()> {
     data.insert("tauri_dep", to_json(tauri_dep));
     data.insert("tauri_example_dep", to_json(tauri_example_dep));
     data.insert("tauri_build_dep", to_json(tauri_build_dep));
+    data.insert("tauri_plugin_dep", to_json(tauri_plugin_dep));
     data.insert("author", to_json(options.author));
 
     if options.tauri {

+ 1 - 0
tooling/cli/templates/app/src-tauri/capabilities/.gitignore

@@ -0,0 +1 @@
+schemas/

+ 16 - 0
tooling/cli/templates/app/src-tauri/capabilities/default.json

@@ -0,0 +1,16 @@
+{
+  "$schema": "./schemas/desktop-schema.json",
+  "identifier": "default-plugins",
+  "description": "enables the default permissions",
+  "windows": ["main"],
+  "permissions": [
+    "path:default",
+    "event:default",
+    "window:default",
+    "webview:default",
+    "app:default",
+    "resources:default",
+    "menu:default",
+    "tray:default",
+  ]
+}

+ 1 - 0
tooling/cli/templates/plugin/Cargo.crate-manifest

@@ -15,3 +15,4 @@ thiserror = "1.0"
 
 [build-dependencies]
 tauri-build = {{{ tauri_build_dep }}}
+tauri-plugin = {{{ tauri_plugin_dep }}}

+ 4 - 0
tooling/cli/templates/plugin/build.rs

@@ -1,5 +1,7 @@
 use std::process::exit;
 
+const COMMANDS: &[&str] = &["ping", "execute"];
+
 fn main() {
   if let Err(error) = tauri_build::mobile::PluginBuilder::new()
     .android_path("android")
@@ -9,4 +11,6 @@ fn main() {
     println!("{error:#}");
     exit(1);
   }
+
+  tauri_plugin::Builder::new(COMMANDS).build();
 }

+ 1 - 0
tooling/cli/templates/plugin/permissions/.gitignore

@@ -0,0 +1 @@
+schemas/