CH-J Toolsmanagementul serverului peste SSH
Meniu
Sursă publicată

CH-J Tools

Navighează directoarele și fișierele pentru o anumită versiune a aplicației.

Descarcă sursa ZIP
CH-J / Server Manager 1704 fișiere
0.1.2-beta Adăugat: · Construit:
app.rs Adăugat: Data neînregistrată 3,1 KB · 97 linii
Cod Descarcă fișierul
1//! Core composition root (replaces `bootstrap()` of the Electron `src/main/index.js`).
2//! Services are created once and shared through `Arc`; Tauri commands reach them via
3//! the managed [`CoreSlot`].
5use crate::core::config::ConfigStore;
6use crate::core::error::{CoreError, CoreResult};
7use crate::core::i18n::I18n;
8use crate::core::logging::Logger;
9use crate::core::paths::AppPaths;
10use crate::core::profile_transfer::ProfileTransfer;
11use crate::core::profiles::ProfileService;
12use crate::core::vault::VaultStore;
13use crate::security::caller::{WindowRegistry, MAIN_LABEL};
14use once_cell::sync::OnceCell;
15use serde::Serialize;
16use serde_json::Value;
17use std::sync::Arc;
18use tauri::{AppHandle, Emitter, EventTarget};
20pub const CORE_API_VERSION: &str = "1.1.0";
21/// Public Module API (formerly Plugin API). 1.7.0 = unchanged contract of 0.1.0.
22pub const MODULE_API_VERSION: &str = "1.16.0";
23pub const DATA_SCHEMA: u32 = 1;
24pub const COPYRIGHT: &str = "Copyright 2026 Josef Chudy";
26#[derive(Clone, Debug, Serialize)]
27#[serde(rename_all = "camelCase")]
28pub struct BuildInfo {
29 pub version: String,
30 pub build_id: String,
31 pub built_at: String,
34impl BuildInfo {
35 pub fn current(version: &str) -> Self {
36 Self { version: version.to_string(), build_id: env!("CHJ_BUILD_ID").to_string(), built_at: env!("CHJ_BUILT_AT").to_string() }
37 }
40pub struct Core {
41 pub app: AppHandle,
42 pub paths: AppPaths,
43 pub build: BuildInfo,
44 pub logger: Arc<Logger>,
45 pub i18n: Arc<I18n>,
46 pub config: Arc<ConfigStore>,
47 pub vault: Arc<VaultStore>,
48 pub profiles: Arc<ProfileService>,
49 pub profile_transfer: ProfileTransfer,
50 pub windows: Arc<WindowRegistry>,
51 pub services: crate::core::services::Services,
54impl Core {
55 pub fn language(&self) -> String {
56 self.config.language()
57 }
59 pub fn t(&self, key: &str) -> String {
60 self.i18n.t(&self.language(), key)
61 }
63 /// Push event to the main window only (never to module windows).
64 pub fn emit_main<S: Serialize + Clone>(&self, event: &str, payload: S) {
65 let _ = self.app.emit_to(EventTarget::webview_window(MAIN_LABEL), event, payload);
66 }
68 /// Push event to one module window.
69 pub fn emit_window<S: Serialize + Clone>(&self, label: &str, event: &str, payload: S) {
70 let _ = self.app.emit_to(EventTarget::AnyLabel { label: label.to_string() }, event, payload);
71 }
73 pub fn log_ipc_failure(&self, channel: &str, error: &CoreError) {
74 self.logger.error(
75 "IPC operation failed.",
76 serde_json::json!({ "channel": channel, "code": if error.code.is_empty() { Value::Null } else { Value::String(error.code.clone()) } }),
77 );
78 }
81/// Holder managed by Tauri before the Core exists (license dialog runs first).
82#[derive(Default)]
83pub struct CoreSlot(OnceCell<Arc<Core>>);
85impl CoreSlot {
86 pub fn set(&self, core: Arc<Core>) {
87 let _ = self.0.set(core);
88 }
90 pub fn get(&self) -> CoreResult<Arc<Core>> {
91 self.0.get().cloned().ok_or_else(|| CoreError::new("CORE_NOT_READY", "The Core is not initialized yet."))
92 }
94 pub fn try_get(&self) -> Option<Arc<Core>> {
95 self.0.get().cloned()
96 }
SHA-256356a5f2d799a8bcc815a263fdd36681201fabe7bb338f7deb258c9e14a4bbd87

CH-J Proprietary Software License 1.14 · Sursa este furnizată în cadrul CH-J Proprietary Software License 1.14. Disponibilitatea sa nu modifică termenii licenţei sau nu acordă drepturi suplimentare.

Archive SHA-256ac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Fișiere