2023-03-31 16:23:34 +03:00
|
|
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2023-10-17 19:09:59 +03:00
|
|
|
use super::SectionItem;
|
2023-03-31 16:23:34 +03:00
|
|
|
use crate::helpers::framework;
|
2023-04-03 15:58:14 +03:00
|
|
|
use std::{
|
|
|
|
fs::read_to_string,
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
};
|
2023-09-12 19:18:23 +03:00
|
|
|
use tauri_utils::platform::Target;
|
2023-03-31 16:23:34 +03:00
|
|
|
|
2023-04-03 15:58:14 +03:00
|
|
|
pub fn items(app_dir: Option<&PathBuf>, tauri_dir: Option<&Path>) -> Vec<SectionItem> {
|
2023-03-31 16:23:34 +03:00
|
|
|
let mut items = Vec::new();
|
|
|
|
if tauri_dir.is_some() {
|
2023-09-12 19:18:23 +03:00
|
|
|
if let Ok(config) = crate::helpers::config::get(Target::current(), None) {
|
2023-03-31 16:23:34 +03:00
|
|
|
let config_guard = config.lock().unwrap();
|
|
|
|
let config = config_guard.as_ref().unwrap();
|
|
|
|
|
2024-02-03 06:39:48 +03:00
|
|
|
let bundle_or_build = if config.bundle.active {
|
2023-10-17 19:09:59 +03:00
|
|
|
"bundle"
|
2023-03-31 16:23:34 +03:00
|
|
|
} else {
|
2023-10-17 19:09:59 +03:00
|
|
|
"build"
|
2023-03-31 16:23:34 +03:00
|
|
|
};
|
2023-10-17 19:09:59 +03:00
|
|
|
items.push(SectionItem::new().description(format!("build-type: {bundle_or_build}")));
|
2023-03-31 16:23:34 +03:00
|
|
|
|
|
|
|
let csp = config
|
2024-02-03 06:39:48 +03:00
|
|
|
.app
|
2023-03-31 16:23:34 +03:00
|
|
|
.security
|
|
|
|
.csp
|
|
|
|
.clone()
|
|
|
|
.map(|c| c.to_string())
|
|
|
|
.unwrap_or_else(|| "unset".to_string());
|
2023-10-17 19:09:59 +03:00
|
|
|
items.push(SectionItem::new().description(format!("CSP: {csp}")));
|
2023-03-31 16:23:34 +03:00
|
|
|
|
2024-02-03 06:39:48 +03:00
|
|
|
if let Some(frontend_dist) = &config.build.frontend_dist {
|
|
|
|
items.push(SectionItem::new().description(format!("frontendDist: {frontend_dist}")));
|
2024-01-31 15:38:25 +03:00
|
|
|
}
|
2023-03-31 16:23:34 +03:00
|
|
|
|
2024-02-03 06:39:48 +03:00
|
|
|
if let Some(dev_url) = &config.build.dev_url {
|
|
|
|
items.push(SectionItem::new().description(format!("devUrl: {dev_url}")));
|
2024-01-31 15:38:25 +03:00
|
|
|
}
|
2023-03-31 16:23:34 +03:00
|
|
|
|
|
|
|
if let Some(app_dir) = app_dir {
|
|
|
|
if let Ok(package_json) = read_to_string(app_dir.join("package.json")) {
|
|
|
|
let (framework, bundler) = framework::infer_from_package_json(&package_json);
|
2023-10-17 19:09:59 +03:00
|
|
|
|
2023-03-31 16:23:34 +03:00
|
|
|
if let Some(framework) = framework {
|
2023-10-17 19:09:59 +03:00
|
|
|
items.push(SectionItem::new().description(format!("framework: {framework}")));
|
2023-03-31 16:23:34 +03:00
|
|
|
}
|
2023-10-17 19:09:59 +03:00
|
|
|
|
2023-03-31 16:23:34 +03:00
|
|
|
if let Some(bundler) = bundler {
|
2023-10-17 19:09:59 +03:00
|
|
|
items.push(SectionItem::new().description(format!("bundler: {bundler}")));
|
2023-03-31 16:23:34 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
items
|
|
|
|
}
|