This commit is contained in:
fengchuanhn@gmail.com
2026-05-17 12:54:04 +08:00
parent e6c8c18be0
commit f1fce871bb
28 changed files with 2566 additions and 235 deletions

View File

@@ -0,0 +1,19 @@
use std::collections::HashMap;
use tauri::State;
use crate::app_config::AppConfig;
#[tauri::command]
pub async fn get_app_config(
app_config: State<'_, AppConfig>,
) -> Result<HashMap<String, String>, String> {
Ok(app_config.entries().await)
}
#[tauri::command]
pub async fn get_app_config_last_message(
app_config: State<'_, AppConfig>,
) -> Result<String, String> {
Ok(app_config.last_message().await)
}

View File

@@ -1,12 +1,18 @@
use tauri::State;
use crate::app_config::AppConfig;
use crate::auth_session::{AuthSession, AuthUser};
#[tauri::command]
pub fn sync_auth_session(
pub async fn sync_auth_session(
session: State<'_, AuthSession>,
app_config: State<'_, AppConfig>,
token: String,
user: Option<AuthUser>,
) {
session.set(token, user);
) -> Result<(), String> {
session.set(token.clone(), user);
if let Err(e) = app_config.refresh_after_auth(&token).await {
log::debug!(target: "auth", "refresh app config: {}", e);
}
Ok(())
}

View File

@@ -1,3 +1,4 @@
pub mod app_config;
pub mod auth;
pub mod nodejs;
pub mod quickjs;

View File

@@ -26,6 +26,7 @@ use serde_json::Value;
use tauri::{AppHandle, Emitter, Window};
use tokio::sync::mpsc;
use crate::app_config::AppConfig;
use crate::js_runtime::PipelineEvent;
use crate::nodejs;
@@ -80,13 +81,15 @@ fn spawn_event_pump(
pub async fn run_nodejs_script(
app: AppHandle,
window: Window,
app_config: tauri::State<'_, AppConfig>,
script_name: String,
params: Value,
) -> Result<Value, String> {
let (tx, rx) = mpsc::unbounded_channel::<PipelineEvent>();
let pump = spawn_event_pump(app, window, script_name.clone(), rx);
let config_env = app_config.env_for_node().await;
let result = nodejs::run_node_script(script_name, params, tx)
let result = nodejs::run_node_script(script_name, params, tx, config_env)
.await
.map_err(|e| e.to_string())?;
@@ -99,13 +102,15 @@ pub async fn run_nodejs_script(
pub async fn run_nodejs_script_source(
app: AppHandle,
window: Window,
app_config: tauri::State<'_, AppConfig>,
script_source: String,
params: Value,
) -> Result<Value, String> {
let (tx, rx) = mpsc::unbounded_channel::<PipelineEvent>();
let pump = spawn_event_pump(app, window, "<debug-source>".to_string(), rx);
let config_env = app_config.env_for_node().await;
let result = nodejs::run_node_script_source(script_source, params, tx)
let result = nodejs::run_node_script_source(script_source, params, tx, config_env)
.await
.map_err(|e| e.to_string())?;