This commit is contained in:
+57
-2
@@ -1,6 +1,8 @@
|
||||
use rabby_core::{
|
||||
demo_dashboard, wallet_feature_summary, WalletDashboard, WalletFeatureStatus, Workspace,
|
||||
demo_dashboard, wallet_feature_summary, AppConfig, WalletDashboard, WalletFeatureStatus,
|
||||
Workspace,
|
||||
};
|
||||
use rabby_runtime::config_store::{ConfigStore, JsonFileConfigStore};
|
||||
use rabby_runtime::local_terminal::{LocalCommand, LocalCommandOutput, LocalTerminal};
|
||||
use rabby_runtime::wallet_vault::{EncryptedWalletVault, WalletVaultStatus};
|
||||
use serde::Serialize;
|
||||
@@ -75,6 +77,31 @@ fn resolve_vault_path(path: Option<String>) -> PathBuf {
|
||||
.unwrap_or_else(|| std::env::temp_dir().join("rabby-demo-wallet-vault.json"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn load_app_config(path: Option<String>) -> Result<AppConfig, String> {
|
||||
let config_path = resolve_config_path(path);
|
||||
if !config_path.exists() {
|
||||
return Ok(AppConfig::default_linux());
|
||||
}
|
||||
JsonFileConfigStore::new(config_path)
|
||||
.load()
|
||||
.map_err(|err| err.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn save_app_config(config: AppConfig, path: Option<String>) -> Result<AppConfig, String> {
|
||||
let config_path = resolve_config_path(path);
|
||||
JsonFileConfigStore::new(config_path)
|
||||
.save(&config)
|
||||
.map_err(|err| err.to_string())?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn resolve_config_path(path: Option<String>) -> PathBuf {
|
||||
path.map(PathBuf::from)
|
||||
.unwrap_or_else(|| std::env::temp_dir().join("rabby-app-config.json"))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
@@ -83,7 +110,9 @@ fn main() {
|
||||
wallet_dashboard,
|
||||
save_demo_wallet_vault,
|
||||
load_wallet_vault,
|
||||
run_local_command
|
||||
run_local_command,
|
||||
load_app_config,
|
||||
save_app_config
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("failed to run Rabby Tauri application");
|
||||
@@ -114,4 +143,30 @@ mod tests {
|
||||
assert_eq!(output.exit_code, 0);
|
||||
assert_eq!(output.stdout, "tauri-local");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_path_has_stable_file_name() {
|
||||
let path = resolve_config_path(None);
|
||||
assert_eq!(
|
||||
path.file_name().and_then(|value| value.to_str()),
|
||||
Some("rabby-app-config.json")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_and_load_app_config_round_trips_custom_theme() {
|
||||
let unique = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos();
|
||||
let path = std::env::temp_dir().join(format!("rabby-tauri-config-{unique}.json"));
|
||||
let mut config = AppConfig::default_linux();
|
||||
config.theme_id = "rabby-light".to_string();
|
||||
|
||||
save_app_config(config.clone(), Some(path.display().to_string())).unwrap();
|
||||
let loaded = load_app_config(Some(path.display().to_string())).unwrap();
|
||||
|
||||
assert_eq!(loaded.theme_id, "rabby-light");
|
||||
assert_eq!(loaded, config);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user