Skip to content

Commit

Permalink
feat(cli): update template with permissions and capabilities (#8666)
Browse files Browse the repository at this point in the history
* feat(cli): update template with permissions and capabilities

* update gitignore [skip ci]
  • Loading branch information
lucasfernog authored Feb 1, 2024
1 parent 6639a57 commit f492efd
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .changes/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions .changes/update-template-for-permissions.md
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 2 additions & 1 deletion tooling/cli/metadata-v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 2 additions & 0 deletions tooling/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
11 changes: 10 additions & 1 deletion tooling/cli/src/plugin/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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
),
)
};

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schemas/
16 changes: 16 additions & 0 deletions tooling/cli/templates/app/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions tooling/cli/templates/plugin/Cargo.crate-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ thiserror = "1.0"

[build-dependencies]
tauri-build = {{{ tauri_build_dep }}}
tauri-plugin = {{{ tauri_plugin_dep }}}
4 changes: 4 additions & 0 deletions tooling/cli/templates/plugin/build.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -9,4 +11,6 @@ fn main() {
println!("{error:#}");
exit(1);
}

tauri_plugin::Builder::new(COMMANDS).build();
}
1 change: 1 addition & 0 deletions tooling/cli/templates/plugin/permissions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schemas/

0 comments on commit f492efd

Please sign in to comment.