Skip to content

Commit d8b8e83

Browse files
committed
fix: apply rustfmt to pass lint checks
1 parent 5dc849c commit d8b8e83

File tree

108 files changed

+4864
-3625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+4864
-3625
lines changed

apps/desktop/src-tauri/build.rs

Lines changed: 182 additions & 118 deletions
Large diffs are not rendered by default.

apps/desktop/src-tauri/build_scripts/scan_plugins.rs

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,64 @@
1+
use serde_json::json;
2+
use std::collections::HashMap;
13
use std::fs;
24
use std::path::Path;
3-
use std::collections::HashMap;
4-
use serde_json::json;
55

66
/// Scan a plugin directory to extract command information
77
pub fn scan_plugin(plugin_path: &Path) -> Option<PluginInfo> {
88
let plugin_name = plugin_path.file_name()?.to_str()?;
99
if !plugin_name.starts_with("tauri-plugin-") {
1010
return None;
1111
}
12-
12+
1313
let plugin_id = plugin_name.trim_start_matches("tauri-plugin-");
14-
14+
1515
// Read build.rs to find COMMANDS array
1616
let build_rs_path = plugin_path.join("build.rs");
1717
let commands = if build_rs_path.exists() {
1818
extract_commands_from_build_rs(&build_rs_path)?
1919
} else {
2020
vec![]
2121
};
22-
22+
2323
// Read permissions to get descriptions
2424
let permissions_dir = plugin_path.join("permissions");
2525
let command_metadata = if permissions_dir.exists() {
2626
scan_permissions_dir(&permissions_dir, &commands)
2727
} else {
2828
HashMap::new()
2929
};
30-
30+
3131
Some(PluginInfo {
3232
id: plugin_id.to_string(),
3333
name: humanize_plugin_name(plugin_id),
34-
commands: commands.into_iter().map(|cmd| {
35-
let metadata = command_metadata.get(&cmd);
36-
CommandInfo {
37-
name: cmd.clone(),
38-
description: metadata
39-
.and_then(|m| m.get("description"))
40-
.and_then(|d| d.as_str())
41-
.unwrap_or("No description available")
42-
.to_string(),
43-
permission: format!("plugin:{}:{}", plugin_id, cmd),
44-
}
45-
}).collect(),
34+
commands: commands
35+
.into_iter()
36+
.map(|cmd| {
37+
let metadata = command_metadata.get(&cmd);
38+
CommandInfo {
39+
name: cmd.clone(),
40+
description: metadata
41+
.and_then(|m| m.get("description"))
42+
.and_then(|d| d.as_str())
43+
.unwrap_or("No description available")
44+
.to_string(),
45+
permission: format!("plugin:{}:{}", plugin_id, cmd),
46+
}
47+
})
48+
.collect(),
4649
})
4750
}
4851

4952
/// Extract COMMANDS array from build.rs
5053
fn extract_commands_from_build_rs(build_rs_path: &Path) -> Option<Vec<String>> {
5154
let content = fs::read_to_string(build_rs_path).ok()?;
52-
55+
5356
// Find COMMANDS array
5457
let commands_start = content.find("const COMMANDS: &[&str] = &[")?;
5558
let array_start = commands_start + "const COMMANDS: &[&str] = &[".len();
5659
let array_end = content[array_start..].find(']')?;
5760
let commands_str = &content[array_start..array_start + array_end];
58-
61+
5962
// Parse command names, handling comments properly
6063
let commands: Vec<String> = commands_str
6164
.lines()
@@ -68,22 +71,25 @@ fn extract_commands_from_build_rs(build_rs_path: &Path) -> Option<Vec<String>> {
6871
} else {
6972
line
7073
};
71-
74+
7275
// Extract quoted strings from the line
7376
line.split(',')
7477
.map(|s| s.trim().trim_matches('"').to_string())
7578
.filter(|s| !s.is_empty())
7679
.collect::<Vec<_>>()
7780
})
7881
.collect();
79-
82+
8083
Some(commands)
8184
}
8285

8386
/// Scan permissions directory for command metadata
84-
fn scan_permissions_dir(permissions_dir: &Path, commands: &[String]) -> HashMap<String, serde_json::Value> {
87+
fn scan_permissions_dir(
88+
permissions_dir: &Path,
89+
commands: &[String],
90+
) -> HashMap<String, serde_json::Value> {
8591
let mut metadata = HashMap::new();
86-
92+
8793
// Check autogenerated commands directory
8894
let commands_dir = permissions_dir.join("autogenerated").join("commands");
8995
if commands_dir.exists() {
@@ -101,7 +107,7 @@ fn scan_permissions_dir(permissions_dir: &Path, commands: &[String]) -> HashMap<
101107
}
102108
}
103109
}
104-
110+
105111
metadata
106112
}
107113

@@ -138,7 +144,7 @@ pub struct CommandInfo {
138144
pub fn scan_all_plugins(project_root: &Path) -> Vec<PluginInfo> {
139145
let plugins_dir = project_root.join("plugins");
140146
let mut plugins = Vec::new();
141-
147+
142148
if let Ok(entries) = fs::read_dir(&plugins_dir) {
143149
for entry in entries.flatten() {
144150
if entry.file_type().map(|t| t.is_dir()).unwrap_or(false) {
@@ -148,14 +154,14 @@ pub fn scan_all_plugins(project_root: &Path) -> Vec<PluginInfo> {
148154
}
149155
}
150156
}
151-
157+
152158
plugins
153159
}
154160

155161
/// Generate Rust code for plugin metadata
156162
pub fn generate_plugin_metadata_code(plugins: &[PluginInfo]) -> String {
157163
let mut code = String::from(
158-
r#"// This file is auto-generated by build.rs
164+
r#"// This file is auto-generated by build.rs
159165
// Do not edit manually
160166
161167
use crate::plugin_metadata::{PluginMetadata, CommandMetadata, PluginRegistry};
@@ -164,17 +170,19 @@ use serde_json::json;
164170
pub fn get_plugin_metadata_registry() -> PluginRegistry {
165171
let mut registry = PluginRegistry::new();
166172
167-
"#);
173+
"#,
174+
);
168175

169176
for plugin in plugins {
170177
code.push_str(&format!(
171-
r#" {{
178+
r#" {{
172179
let mut commands = vec![];
173-
"#));
180+
"#
181+
));
174182

175183
for cmd in &plugin.commands {
176184
code.push_str(&format!(
177-
r#" commands.push(CommandMetadata {{
185+
r#" commands.push(CommandMetadata {{
178186
name: "{}".to_string(),
179187
description: "{}".to_string(),
180188
params_schema: json!({{
@@ -187,11 +195,15 @@ r#" commands.push(CommandMetadata {{
187195
destructive: false,
188196
examples: vec![],
189197
}});
190-
"#, cmd.name, cmd.description.replace('"', r#"\""#), cmd.permission));
198+
"#,
199+
cmd.name,
200+
cmd.description.replace('"', r#"\""#),
201+
cmd.permission
202+
));
191203
}
192204

193205
code.push_str(&format!(
194-
r#"
206+
r#"
195207
registry.add_plugin(PluginMetadata {{
196208
id: "{}".to_string(),
197209
name: "{}".to_string(),
@@ -200,12 +212,16 @@ r#"
200212
}});
201213
}}
202214
203-
"#, plugin.id, plugin.name, plugin.name));
215+
"#,
216+
plugin.id, plugin.name, plugin.name
217+
));
204218
}
205219

206-
code.push_str(r#" registry
220+
code.push_str(
221+
r#" registry
207222
}
208-
"#);
223+
"#,
224+
);
209225

210226
code
211-
}
227+
}

apps/desktop/src-tauri/src/acl_manifest.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,30 @@ pub fn load_acl_manifest(path: &Path) -> Result<AclManifest, Box<dyn std::error:
5656

5757
pub fn extract_commands_from_manifest(manifest: &AclManifest) -> Vec<ExtractedCommand> {
5858
let mut commands = Vec::new();
59-
59+
6060
for (plugin_name, plugin_acl) in &manifest.plugins {
6161
// Skip core plugins as they're Tauri internals
6262
if plugin_name.starts_with("core:") || plugin_name == "core" {
6363
continue;
6464
}
65-
65+
6666
// Extract commands from permissions
6767
for (perm_name, permission) in &plugin_acl.permissions {
6868
// Skip deny permissions
6969
if perm_name.starts_with("deny-") {
7070
continue;
7171
}
72-
72+
7373
// Extract allowed commands
7474
for cmd in &permission.commands.allow {
7575
// Skip if we already have this command
76-
if commands.iter().any(|c: &ExtractedCommand| c.name == *cmd && c.plugin == *plugin_name) {
76+
if commands
77+
.iter()
78+
.any(|c: &ExtractedCommand| c.name == *cmd && c.plugin == *plugin_name)
79+
{
7780
continue;
7881
}
79-
82+
8083
commands.push(ExtractedCommand {
8184
name: cmd.clone(),
8285
description: permission.description.clone(),
@@ -86,7 +89,7 @@ pub fn extract_commands_from_manifest(manifest: &AclManifest) -> Vec<ExtractedCo
8689
}
8790
}
8891
}
89-
92+
9093
commands
9194
}
9295

@@ -97,7 +100,7 @@ pub fn get_acl_manifest_path() -> Option<std::path::PathBuf> {
97100
.join("gen")
98101
.join("schemas")
99102
.join("acl-manifests.json");
100-
103+
101104
if acl_path.exists() {
102105
Some(acl_path)
103106
} else {
@@ -108,22 +111,20 @@ pub fn get_acl_manifest_path() -> Option<std::path::PathBuf> {
108111

109112
pub fn load_and_extract_commands() -> Vec<ExtractedCommand> {
110113
match get_acl_manifest_path() {
111-
Some(path) => {
112-
match load_acl_manifest(&path) {
113-
Ok(manifest) => {
114-
let commands = extract_commands_from_manifest(&manifest);
115-
log::info!("Extracted {} commands from ACL manifest", commands.len());
116-
commands
117-
}
118-
Err(e) => {
119-
log::error!("Failed to load ACL manifest: {}", e);
120-
Vec::new()
121-
}
114+
Some(path) => match load_acl_manifest(&path) {
115+
Ok(manifest) => {
116+
let commands = extract_commands_from_manifest(&manifest);
117+
log::info!("Extracted {} commands from ACL manifest", commands.len());
118+
commands
122119
}
123-
}
120+
Err(e) => {
121+
log::error!("Failed to load ACL manifest: {}", e);
122+
Vec::new()
123+
}
124+
},
124125
None => {
125126
log::warn!("ACL manifest path not found");
126127
Vec::new()
127128
}
128129
}
129-
}
130+
}

0 commit comments

Comments
 (0)