|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { invoke } from '@tauri-apps/api/core'; |
|
|
import { open } from '@tauri-apps/plugin-dialog'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type ConfigSection = 'global' | 'view'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export type ConfigKey = |
|
|
|
|
|
| 'app_owner' |
|
|
| 'audio_lib_path' |
|
|
| 'extra_lib_search_path' |
|
|
| 'custom_font_path' |
|
|
| 'auto_lookup_clipboard' |
|
|
| 'monitor_clipboard' |
|
|
| 'auto_lookup_selection' |
|
|
| 'hotkey_letter' |
|
|
| 'hotkey_modifier' |
|
|
| 'use_popover_for_lookup' |
|
|
| 'last_main_profile_id' |
|
|
|
|
|
| 'gui_language' |
|
|
| 'appearance_mode' |
|
|
| 'font_face' |
|
|
| 'font_color' |
|
|
| 'background_color' |
|
|
| 'auto_resize_image'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getAppConfig = async (): Promise<any> => { |
|
|
return await invoke('config_get_app_config'); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getConfigValue = async <T = any>( |
|
|
section: ConfigSection, |
|
|
key: ConfigKey |
|
|
): Promise<T> => { |
|
|
return await invoke('config_get_value', { section, key }); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const setConfigValue = async <T = any>( |
|
|
section: ConfigSection, |
|
|
key: ConfigKey, |
|
|
value: T |
|
|
): Promise<void> => { |
|
|
await invoke('config_set_value', { section, key, value }); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getGlobalSettings = async (): Promise<any> => { |
|
|
return await invoke('config_get_global_settings'); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const getViewSettings = async (): Promise<any> => { |
|
|
return await invoke('config_get_view_settings'); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const updateViewSettings = async (settings: any): Promise<void> => { |
|
|
await invoke('config_update_view_settings', { settings }); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const saveAppConfig = async (): Promise<void> => { |
|
|
await invoke('config_save_app_config'); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const reloadAppConfig = async (): Promise<void> => { |
|
|
await invoke('config_reload_app_config'); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const reloadResources = async (): Promise<void> => { |
|
|
await invoke('config_reload_resources'); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const selectDirectory = async (title?: string, defaultPath?: string): Promise<string | null> => { |
|
|
const result = await open({ |
|
|
directory: true, |
|
|
multiple: false, |
|
|
title: title || '选择目录', |
|
|
defaultPath: defaultPath, |
|
|
}); |
|
|
|
|
|
return result as string | null; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const listFontsInDirectory = async (path: string): Promise<string[]> => { |
|
|
return await invoke('config_list_fonts_in_directory', { path }); |
|
|
}; |
|
|
|
|
|
|