mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-14 09:49:58 -05:00
Fix: Remove Rust Read-Store-Files for Native TS (#97)
This commit is contained in:
@@ -81,20 +81,3 @@ pub fn get_auto_backup_dir(app: tauri::AppHandle) -> String {
|
||||
let _ = std::fs::create_dir_all(&dir);
|
||||
dir.to_string_lossy().into_owned()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn read_store_files(app: tauri::AppHandle, names: Vec<String>) -> Vec<(String, String)> {
|
||||
let base = app
|
||||
.path()
|
||||
.app_local_data_dir()
|
||||
.unwrap_or_else(|_| PathBuf::from("."));
|
||||
|
||||
names
|
||||
.into_iter()
|
||||
.map(|name| {
|
||||
let content = std::fs::read_to_string(base.join(&name))
|
||||
.unwrap_or_else(|_| "{}".to_string());
|
||||
(name, content)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -107,7 +107,6 @@ pub fn run() {
|
||||
commands::backup::import_app_data,
|
||||
commands::backup::auto_backup_app_data,
|
||||
commands::backup::get_auto_backup_dir,
|
||||
commands::backup::read_store_files,
|
||||
commands::storage::load_store,
|
||||
commands::storage::save_store,
|
||||
commands::storage::store_credential,
|
||||
|
||||
+19
-24
@@ -1,24 +1,27 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import {
|
||||
saveSettings,
|
||||
saveLibrary,
|
||||
saveUpdates,
|
||||
loadSettings, saveSettings,
|
||||
loadLibrary, saveLibrary,
|
||||
loadUpdates, saveUpdates,
|
||||
} from "$lib/core/persistence/persist";
|
||||
|
||||
const STORE_FILES = ["settings.json", "library.json", "updates.json"] as const;
|
||||
async function collectStoreFiles(): Promise<{ name: string; bytes: Uint8Array }[]> {
|
||||
const [settings, library, updates] = await Promise.all([
|
||||
loadSettings(),
|
||||
loadLibrary(),
|
||||
loadUpdates(),
|
||||
]);
|
||||
|
||||
const enc = new TextEncoder();
|
||||
return [
|
||||
{ name: "settings.json", bytes: enc.encode(JSON.stringify(settings)) },
|
||||
{ name: "library.json", bytes: enc.encode(JSON.stringify(library)) },
|
||||
{ name: "updates.json", bytes: enc.encode(JSON.stringify(updates)) },
|
||||
];
|
||||
}
|
||||
|
||||
export async function exportAppData(): Promise<void> {
|
||||
const entries: [string, string][] = await invoke("read_store_files", {
|
||||
names: [...STORE_FILES],
|
||||
});
|
||||
|
||||
const zip = buildZip(
|
||||
entries.map(([name, content]) => ({
|
||||
name,
|
||||
bytes: new TextEncoder().encode(content),
|
||||
}))
|
||||
);
|
||||
|
||||
const zip = buildZip(await collectStoreFiles());
|
||||
await invoke("export_app_data", { bytes: Array.from(zip) });
|
||||
}
|
||||
|
||||
@@ -60,15 +63,7 @@ export async function importAppData(): Promise<void> {
|
||||
|
||||
export async function autoBackupAppData(): Promise<void> {
|
||||
try {
|
||||
const entries: [string, string][] = await invoke("read_store_files", {
|
||||
names: [...STORE_FILES],
|
||||
});
|
||||
const zip = buildZip(
|
||||
entries.map(([name, content]) => ({
|
||||
name,
|
||||
bytes: new TextEncoder().encode(content),
|
||||
}))
|
||||
);
|
||||
const zip = buildZip(await collectStoreFiles());
|
||||
await invoke("auto_backup_app_data", { bytes: Array.from(zip) });
|
||||
} catch (e) {
|
||||
console.warn("[moku] auto-backup failed:", e);
|
||||
|
||||
Reference in New Issue
Block a user