mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 17:29:55 -05:00
Fix: Remove Rust Read-Store-Files for Native TS (#97)
This commit is contained in:
@@ -80,21 +80,4 @@ pub fn get_auto_backup_dir(app: tauri::AppHandle) -> String {
|
|||||||
let dir = backup_dir(&app);
|
let dir = backup_dir(&app);
|
||||||
let _ = std::fs::create_dir_all(&dir);
|
let _ = std::fs::create_dir_all(&dir);
|
||||||
dir.to_string_lossy().into_owned()
|
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::import_app_data,
|
||||||
commands::backup::auto_backup_app_data,
|
commands::backup::auto_backup_app_data,
|
||||||
commands::backup::get_auto_backup_dir,
|
commands::backup::get_auto_backup_dir,
|
||||||
commands::backup::read_store_files,
|
|
||||||
commands::storage::load_store,
|
commands::storage::load_store,
|
||||||
commands::storage::save_store,
|
commands::storage::save_store,
|
||||||
commands::storage::store_credential,
|
commands::storage::store_credential,
|
||||||
|
|||||||
+19
-24
@@ -1,24 +1,27 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import {
|
import {
|
||||||
saveSettings,
|
loadSettings, saveSettings,
|
||||||
saveLibrary,
|
loadLibrary, saveLibrary,
|
||||||
saveUpdates,
|
loadUpdates, saveUpdates,
|
||||||
} from "$lib/core/persistence/persist";
|
} 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> {
|
export async function exportAppData(): Promise<void> {
|
||||||
const entries: [string, string][] = await invoke("read_store_files", {
|
const zip = buildZip(await collectStoreFiles());
|
||||||
names: [...STORE_FILES],
|
|
||||||
});
|
|
||||||
|
|
||||||
const zip = buildZip(
|
|
||||||
entries.map(([name, content]) => ({
|
|
||||||
name,
|
|
||||||
bytes: new TextEncoder().encode(content),
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
|
|
||||||
await invoke("export_app_data", { bytes: Array.from(zip) });
|
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> {
|
export async function autoBackupAppData(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const entries: [string, string][] = await invoke("read_store_files", {
|
const zip = buildZip(await collectStoreFiles());
|
||||||
names: [...STORE_FILES],
|
|
||||||
});
|
|
||||||
const zip = buildZip(
|
|
||||||
entries.map(([name, content]) => ({
|
|
||||||
name,
|
|
||||||
bytes: new TextEncoder().encode(content),
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
await invoke("auto_backup_app_data", { bytes: Array.from(zip) });
|
await invoke("auto_backup_app_data", { bytes: Array.from(zip) });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn("[moku] auto-backup failed:", e);
|
console.warn("[moku] auto-backup failed:", e);
|
||||||
|
|||||||
Reference in New Issue
Block a user