add save config
This commit is contained in:
45
src/App.vue
45
src/App.vue
@@ -24,7 +24,7 @@ const toggleTheme = (val: string | number | boolean) => {
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
const savedTheme = localStorage.getItem('theme');
|
||||
if (savedTheme === 'dark' || (!savedTheme && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
|
||||
isDark.value = true;
|
||||
@@ -33,6 +33,8 @@ onMounted(() => {
|
||||
isDark.value = false;
|
||||
document.documentElement.classList.remove('dark');
|
||||
}
|
||||
|
||||
await loadConfig();
|
||||
});
|
||||
|
||||
// Preparation Data
|
||||
@@ -42,6 +44,45 @@ const selectedDate = ref<Date | null>(new Date());
|
||||
const currentDir = ref("");
|
||||
const videoNamePrefix = ref("");
|
||||
|
||||
// Configuration Types
|
||||
interface AppConfig {
|
||||
working_dir: string;
|
||||
template_dir: string;
|
||||
}
|
||||
|
||||
// Load/Save Config Logic
|
||||
const loadConfig = async () => {
|
||||
try {
|
||||
const config = await invoke<AppConfig>('load_config');
|
||||
if (config.working_dir) workingDir.value = config.working_dir;
|
||||
if (config.template_dir) templateDir.value = config.template_dir;
|
||||
} catch (e) {
|
||||
console.error("Failed to load config:", e);
|
||||
}
|
||||
}
|
||||
|
||||
const saveConfig = async () => {
|
||||
try {
|
||||
await invoke('save_config', {
|
||||
config: {
|
||||
working_dir: workingDir.value,
|
||||
template_dir: templateDir.value
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Failed to save config:", e);
|
||||
}
|
||||
}
|
||||
|
||||
// Watchers for Auto-Save
|
||||
watch(workingDir, () => {
|
||||
saveConfig();
|
||||
});
|
||||
|
||||
watch(templateDir, () => {
|
||||
saveConfig();
|
||||
});
|
||||
|
||||
// Actions
|
||||
const selectWorkingDir = async () => {
|
||||
const selected = await open({
|
||||
@@ -271,4 +312,4 @@ body {
|
||||
max-width: 800px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user