Skip to content

Commit

Permalink
Fix: fix default theme in drak mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Rel1cx committed Apr 8, 2023
1 parent 48bb1d4 commit 1ce2e10
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 26 deletions.
6 changes: 2 additions & 4 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { isLocale } from './i18n/i18n-util'
import { getSettings, settings } from './lib/settings'

export const initI18n = async () => {
const locale = await getSettings('locale', DEFAULT_LANG, isLocale)

setLocale(locale)

const locale = await getSettings<Locales>('locale')
setLocale(locale.getWithDefault(DEFAULT_LANG))
return settings.onKeyChange('locale', (locale: Locales | null) => {
if (!locale || !isLocale(locale)) {
return
Expand Down
6 changes: 3 additions & 3 deletions src/lib/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Option } from '@swan-io/boxed'
import { Store } from 'tauri-plugin-store-api'

import { makeAsyncGetWithDefault } from './tools'

export const settings = new Store('.settings.dat')

export const getSettings = makeAsyncGetWithDefault(settings)
// eslint-disable-next-line etc/no-misused-generics
export const getSettings = async <T>(key: string) => Option.fromNullable(await settings.get<T>(key))
16 changes: 0 additions & 16 deletions src/lib/tools.ts
Original file line number Diff line number Diff line change
@@ -1,16 +0,0 @@
import { type AsyncGetProtocol } from '@/types'

export const makeAsyncGetWithDefault = (self: AsyncGetProtocol) => {
return async <T>(
key: string,
defaultValue: T,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
validator: (value: any) => value is T = (value): value is T => true
) => {
const value = await self.get(key)
if (value !== null && validator(value)) {
return value
}
return defaultValue
}
}
3 changes: 0 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
export type AsyncGetProtocol = {
get: (key: string) => Promise<unknown>
}

0 comments on commit 1ce2e10

Please sign in to comment.