Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to enable this by default? or better can menu:default and tray:default include this permission? because resources is kinda internal and users should not need to deal with it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now there's no way for a plugin to enable commands on other plugins.. but we can adapt core to ignore permission checks for the resources plugin worst case

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that for a security reason or just not implemented?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't make much sense really.. but i can include a set of permissions that are enabled by default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can include all core plugin default permissions automatically.. then the user can deny the functions he doesn't want.. what do you think @chippers

"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/