CH-J Toolspengurusan pelayan melalui SSH
Menu
Sumber yang diterbitkan

CH-J Tools

Layari direktori dan fail untuk keluaran aplikasi tertentu.

Muat turun ZIP sumber
CH-J / Server Manager 1704 fail
0.1.2-beta Ditambah: · Dibina:
license.rs Ditambah: Tarikh tidak direkodkan 3.4 KB · 96 baris
Kod Muat turun fail
1//! License window commands (port of `legal/showLicenseWindow.js`). The flow is enforced in
2//! the Core: guidance must be read before `license_show`, `license_show` before accept.
4use super::{payload, CommandResult};
5use crate::core::error::CoreError;
6use crate::core::legal::LicenseAcceptance;
7use crate::security::caller::require_license;
8use parking_lot::Mutex;
9use serde_json::{json, Value};
10use std::sync::Arc;
11use tauri::{Manager, State, Webview};
13pub struct LicenseFlow {
14 pub acceptance: Arc<LicenseAcceptance>,
15 pub language: String,
16 pub presented: bool,
17 pub shown: bool,
18 pub accepted: bool,
19 pub done: Option<tokio::sync::oneshot::Sender<bool>>,
22#[derive(Default)]
23pub struct LicenseSlot(pub Mutex<Option<LicenseFlow>>);
25fn guard(webview: &Webview) -> Result<(), CoreError> {
26 require_license(webview.label(), webview.url().ok())
29#[tauri::command]
30pub async fn license_read(webview: Webview, slot: State<'_, LicenseSlot>) -> CommandResult {
31 guard(&webview)?;
32 let mut flow = slot.0.lock();
33 let flow = flow.as_mut().ok_or_else(|| CoreError::plain("License dialog is not active."))?;
34 flow.presented = true;
35 let mut value = json!({ "text": flow.acceptance.text, "guidance": flow.acceptance.guidance });
36 for (k, v) in &flow.acceptance.identity {
37 value[k] = v.clone();
38 }
39 value["language"] = json!(flow.language);
40 Ok(value)
43#[tauri::command]
44pub async fn license_show(webview: Webview, slot: State<'_, LicenseSlot>, payload: Option<Value>) -> CommandResult {
45 guard(&webview)?;
46 let payload = super::payload(payload);
47 let mut flow = slot.0.lock();
48 let flow = flow.as_mut().ok_or_else(|| CoreError::plain("License dialog is not active."))?;
49 if !flow.presented || payload.get("guidanceSha256").and_then(Value::as_str) != Some(flow.acceptance.identity_value("guidanceSha256")) {
50 return Err(CoreError::plain("Display the current operational guidance before continuing."));
51 }
52 flow.shown = true;
53 Ok(json!({ "ok": true }))
56#[tauri::command]
57pub async fn license_accept(webview: Webview, slot: State<'_, LicenseSlot>, payload: Option<Value>) -> CommandResult {
58 guard(&webview)?;
59 let payload = super::payload(payload);
60 {
61 let mut flow = slot.0.lock();
62 let flow = flow.as_mut().ok_or_else(|| CoreError::plain("License dialog is not active."))?;
63 if !flow.shown {
64 return Err(CoreError::plain("Display operational guidance before accepting the license."));
65 }
66 flow.acceptance.accept(&payload, flow.shown)?;
67 flow.accepted = true;
68 // The license window closes after the main window exists: closing the last window of a WebView2
69 // process family first shuts the family down, and a window created meanwhile dies with it.
70 if let Some(done) = flow.done.take() {
71 let _ = done.send(true);
72 }
73 }
74 Ok(json!({ "ok": true }))
77#[tauri::command]
78pub async fn license_decline(webview: Webview) -> CommandResult {
79 guard(&webview)?;
80 close_later(&webview);
81 Ok(json!({ "ok": true }))
84/// Lets the IPC reply reach the renderer before the window closes.
85fn close_later(webview: &Webview) {
86 let window = webview.window();
87 let _ = window.app_handle();
88 tauri::async_runtime::spawn(async move {
89 tokio::time::sleep(std::time::Duration::from_millis(50)).await;
90 let _ = window.close();
91 });
94pub fn _unused(value: Option<Value>) -> Value {
95 payload(value)
SHA-256b360e3f62bada0dcdfbf0d5cbc884e1c99bb493d3ca7f3643502fcd3e613cab9

CH-J Proprietary Software License 1.14 · Kod sumber disediakan di bawah CH-J Proprietary Software License 1.14. Ketersediaannya tidak mengubah terma lesen atau memberikan hak tambahan.

SHA-256 arkibac8fe790f4ba60fc098f8c985fc2656cfcc6cdc21fb34b30e308a2b54e62258f
Fail