|
1 | 1 | import { register, unregisterAll } from '@tauri-apps/api/globalShortcut'
|
2 | 2 | import { appWindow } from '@tauri-apps/api/window'
|
3 | 3 | import { enable, disable } from 'tauri-plugin-autostart-api'
|
| 4 | +import { invoke } from '@tauri-apps/api/tauri' |
4 | 5 | import { nanoid } from 'nanoid'
|
5 | 6 | import type { ThemeMode, TokenUnit, Locales } from '@/types'
|
6 |
| -import { invoke } from '@tauri-apps/api/tauri' |
7 | 7 |
|
8 | 8 | export const useSettingsStore = defineStore(
|
9 | 9 | 'settingsStore',
|
@@ -53,7 +53,7 @@ export const useSettingsStore = defineStore(
|
53 | 53 | const showTime = ref(false)
|
54 | 54 |
|
55 | 55 | // 当前显示语言
|
56 |
| - const currentLang = ref<string | undefined>() |
| 56 | + const currentLang = ref<Locales>() |
57 | 57 | const { locale } = useI18n({ useScope: 'global' })
|
58 | 58 |
|
59 | 59 | // 绑定快捷键
|
@@ -86,9 +86,13 @@ export const useSettingsStore = defineStore(
|
86 | 86 |
|
87 | 87 | // 语言切换
|
88 | 88 | const setLanguage = async (lang?: Locales) => {
|
89 |
| - const systemLang = ((await invoke('get_user_language')) as string).split( |
| 89 | + let systemLang = ((await invoke('get_user_language')) as string).split( |
90 | 90 | '-'
|
91 |
| - )[0] as string |
| 91 | + )[0] as Locales |
| 92 | + |
| 93 | + if (!SUPPORT_LANGUAGE.includes(systemLang)) { |
| 94 | + systemLang = 'en' |
| 95 | + } |
92 | 96 |
|
93 | 97 | locale.value = lang || currentLang.value || systemLang
|
94 | 98 | }
|
@@ -137,7 +141,7 @@ export const useSettingsStore = defineStore(
|
137 | 141 |
|
138 | 142 | // 监听语言更改
|
139 | 143 | watch(locale, (val) => {
|
140 |
| - currentLang.value = val as string |
| 144 | + currentLang.value = val as Locales |
141 | 145 | })
|
142 | 146 |
|
143 | 147 | return {
|
|
0 commit comments