mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import * as storageHelper from 'utils/storageHelper'
|
|
|
|
export type Config = {
|
|
sideBarWidth: number
|
|
shortcut: string | undefined
|
|
access_token: string | undefined
|
|
compressSingletonFolder: boolean
|
|
copyFileButton: boolean
|
|
copySnippetButton: boolean
|
|
intelligentToggle: boolean | null // `null` stands for intelligent, boolean for sidebar open status
|
|
icons: 'rich' | 'dim' | 'native'
|
|
}
|
|
|
|
export enum configKeys {
|
|
sideBarWidth = 'sideBarWidth',
|
|
shortcut = 'shortcut',
|
|
accessToken = 'access_token',
|
|
compressSingletonFolder = 'compressSingletonFolder',
|
|
copyFileButton = 'copyFileButton',
|
|
copySnippetButton = 'copySnippetButton',
|
|
intelligentToggle = 'intelligentToggle',
|
|
icons = 'icons',
|
|
}
|
|
|
|
export const defaultConfigs: Config = {
|
|
sideBarWidth: 260,
|
|
shortcut: undefined,
|
|
access_token: undefined,
|
|
compressSingletonFolder: true,
|
|
copyFileButton: true,
|
|
copySnippetButton: true,
|
|
intelligentToggle: null,
|
|
icons: 'rich',
|
|
}
|
|
|
|
const configKeyArray = Object.values(configKeys)
|
|
|
|
function applyDefaultConfigs(configs: Config) {
|
|
return configKeyArray.reduce((applied, configKey) => {
|
|
const key = configKey as keyof Config
|
|
Object.assign(applied, { [key]: key in configs ? configs[key] : defaultConfigs[key] })
|
|
return applied
|
|
}, {} as Config)
|
|
}
|
|
|
|
export async function get(): Promise<Config> {
|
|
return applyDefaultConfigs(await storageHelper.get(configKeyArray))
|
|
}
|
|
|
|
export async function set(partialConfig: Partial<Config>) {
|
|
return await storageHelper.set(partialConfig)
|
|
}
|