CH-J Toolsserverhåndtering over SSH
Menu
Offentliggjort kilde

CH-J Tools

Gennemse mapper og filer til en specifik applikationsudgivelse.

Download kilde ZIP
CH-J / Server Manager 1704 filer
0.1.2-beta Tilføjet: · Bygget:
app.rs Tilføjet: Dato ikke registreret 7,3 KB · 168 linjer
Kode Download fil
1//! Application info, legal documents, configuration, languages and window controls.
3use super::{logged, main_core, payload, text, CommandResult};
4use crate::core::app::{CoreSlot, CORE_API_VERSION, COPYRIGHT, DATA_SCHEMA, MODULE_API_VERSION};
5use crate::core::error::{CoreError, CoreResult};
6use crate::core::legal::{LICENSE_NAME, LICENSE_VERSION};
7use crate::security::caller::MAIN_LABEL;
8use crate::security::url_policy::is_allowed_external_url;
9use serde_json::{json, Value};
10use tauri::{Manager, State, Webview};
11use tauri_plugin_opener::OpenerExt;
13#[tauri::command]
14pub async fn core_get_info(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {
15 let core = main_core(&webview, &slot)?;
16 core.services.modules.install_close_guard(&core)?;
17 let (platform, arch) = crate::core::diagnostics::http::node_platform_arch();
18 Ok(json!({
19 "name": "CH-J Tools",
20 "version": core.build.version,
21 "buildId": core.build.build_id,
22 "platform": platform,
23 "arch": arch,
24 "coreApi": CORE_API_VERSION,
25 "pluginApi": MODULE_API_VERSION,
26 "moduleApi": MODULE_API_VERSION,
27 "dataSchema": DATA_SCHEMA,
28 "license": format!("{LICENSE_NAME} {LICENSE_VERSION}"),
29 "copyright": COPYRIGHT,
30 "runtime": "tauri"
31 }))
34#[tauri::command]
35pub async fn core_legal_open(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
36 let core = main_core(&webview, &slot)?;
37 let payload = super::payload(payload);
38 let result = (|| -> CoreResult<Value> {
39 let key = text(&payload, "document");
40 let path = match key {
41 "documentation" => core.paths.docs().join("README.md"),
42 "safetyCzech" => core.paths.docs().join("provozni-bezpecnost-a-zalohovani.md"),
43 "safetyEnglish" => core.paths.docs().join("operational-safety-and-backup-guidance.md"),
44 "safetyGerman" => core.paths.docs().join("betriebssicherheit-und-datensicherung.md"),
45 "application" => core.paths.licenses().join("APPLICATION_LICENSE.txt"),
46 "notice" => core.paths.licenses().join("NOTICE.txt"),
47 // Electron/Chromium are no longer shipped; their former entries open the
48 // third-party notices that now cover Tauri, WebView and Rust crates.
49 "thirdParty" | "tauri" | "electron" | "chromium" => core.paths.licenses().join("THIRD_PARTY_NOTICES.txt"),
50 "thirdPartyBundle" => core.paths.licenses().join("THIRD_PARTY_LICENSES.zip"),
51 _ => return Err(CoreError::plain("Unknown legal document.")),
52 };
53 core.app.opener().open_path(path.to_string_lossy(), None::<&str>).map_err(|e| CoreError::plain(format!("The legal document could not be opened: {e}")))?;
54 Ok(json!({ "ok": true }))
55 })();
56 logged(&core, "legal:open", result)
59#[tauri::command]
60pub async fn core_open_external(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
61 let core = main_core(&webview, &slot)?;
62 let payload = super::payload(payload);
63 let url = text(&payload, "url");
64 if !is_allowed_external_url(url) {
65 return logged(&core, "core:openExternal", Err(CoreError::plain("The address is not an allowed external link.")));
66 }
67 core.app.opener().open_url(url, None::<&str>).map_err(|e| CoreError::plain(e.to_string()))?;
68 Ok(json!({ "ok": true }))
71#[tauri::command]
72pub async fn core_config_get(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {
73 Ok(main_core(&webview, &slot)?.config.get())
76#[tauri::command]
77pub async fn core_config_update(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
78 let core = main_core(&webview, &slot)?;
79 let payload = super::payload(payload);
80 let result = async {
81 if payload.get("security").map(|s| !s.is_null()).unwrap_or(false) {
82 core.vault.verify_password(text(&payload, "masterPassword")).await?;
83 if payload["security"]["requireSystemAuthentication"] == true && core.services.biometrics.availability().await["available"] != true {
84 return Err(CoreError::plain("BIOMETRIC_UNAVAILABLE"));
85 }
86 }
87 let config = core.config.update(&payload)?;
88 core.services.modules.notify_language(&core, &core.config.language());
89 Ok(config)
90 }
91 .await;
92 core.services.availability.changed();
93 logged(&core, "config:update", result)
96#[tauri::command]
97pub async fn core_i18n_languages(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {
98 Ok(main_core(&webview, &slot)?.i18n.languages_json())
101/// Catalogs of one language and its lookup chain, fetched when the user switches to a language the main window
102/// was not started with (see `I18n::main_window_data`).
103#[tauri::command]
104pub async fn core_i18n_catalogs(webview: Webview, slot: State<'_, CoreSlot>, payload: Option<Value>) -> CommandResult {
105 let core = main_core(&webview, &slot)?;
106 let payload = super::payload(payload);
107 let language = text(&payload, "language");
108 if !core.i18n.codes().iter().any(|c| c == language) {
109 return Err(CoreError::new("I18N_LANGUAGE_UNKNOWN", "Unknown language."));
110 }
111 Ok(core.i18n.catalog_bundle(language))
114/// Frameless window controls; every window may control only itself.
115#[tauri::command]
116pub async fn window_control(webview: Webview, payload: Option<Value>) -> CommandResult {
117 let payload = payload_or_empty(payload);
118 let window = webview.window();
119 if text(&payload, "action") == "closeQueryReply" {
120 if let Some(core) = webview.app_handle().state::<CoreSlot>().try_get() {
121 if let (Some(id), Some(dirty)) = (payload["queryId"].as_u64(), payload["dirty"].as_bool()) {
122 core.services.modules.close_query_reply(webview.label(), id, dirty);
123 }
124 }
125 return Ok(json!({ "ok": true }));
126 }
127 // An embedded module shares the main window, which is not its to minimize, resize or close.
128 if window.label() == MAIN_LABEL && webview.label() != MAIN_LABEL {
129 return Err(CoreError::plain("Window controls are not available for an embedded module."));
130 }
131 let result = match text(&payload, "action") {
132 "minimize" => window.minimize(),
133 "toggleMaximize" => {
134 if window.is_maximized().unwrap_or(false) {
135 window.unmaximize()
136 } else {
137 window.maximize()
138 }
139 }
140 "close" => window.close(),
141 "startDrag" => window.start_dragging(),
142 _ => return Err(CoreError::plain("Unknown window action.")),
143 };
144 result.map_err(|e| CoreError::plain(e.to_string()))?;
145 Ok(json!({ "ok": true }))
148fn payload_or_empty(value: Option<Value>) -> Value {
149 payload(value)
152#[tauri::command]
153pub async fn window_is_maximized(webview: Webview) -> CommandResult {
154 Ok(json!(webview.window().is_maximized().unwrap_or(false)))
157/// User activity from any Core-owned window (vault auto-lock).
158#[tauri::command]
159pub fn window_activity(webview: Webview, slot: State<'_, CoreSlot>) -> CommandResult {
160 if let Some(core) = slot.try_get() {
161 let label = webview.label();
162 if label == MAIN_LABEL || core.windows.module_by_label(label).is_some() {
163 core.services.lock.activity();
164 }
165 }
166 let _ = webview.app_handle();
167 Ok(Value::Null)
SHA-256ebad7bbdf7bae47f7799537238d687cbbc99c655b82335a5bd92a4af1fd516c9

CH-J Proprietary Software License 1.14 · Kilden leveres under CH-J Proprietary Software License 1.14. Dens tilgængelighed ændrer ikke licensbetingelserne eller giver yderligere rettigheder.

Arkiv SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Filer