101101const { safeInvoke, safeListen } = useTauri ()
102102const { t } = useI18n ()
103103const toast = useToast ()
104+ const { config : appConfig, loadConfig, updateClient } = useConfig ()
104105
105106const isRunning = ref (false )
106107const logs = ref <string []>([])
@@ -153,7 +154,7 @@ async function startFetch() {
153154 await safeInvoke (' start_client' , { url , interval })
154155 isRunning .value = true
155156 addLog (t (' client.remoteUrlLog' , { url }))
156- await saveConfig ()
157+ await syncToSharedConfig ()
157158 } catch (e : any ) {
158159 addLog (t (' client.fetchFail' , { error: e .toString () }))
159160 }
@@ -196,39 +197,33 @@ async function flushDns() {
196197
197198function onAutoFetchChange(val : boolean ) {
198199 config .autoFetch = val
199- saveConfig ()
200+ updateClient ({
201+ interval: Number (config .interval ),
202+ method: config .originMethod ,
203+ select_origin: config .selectOrigin ,
204+ custom_url: config .customUrl ,
205+ auto_fetch: config .autoFetch ,
206+ })
200207 toast .add ({ title: t (' client.autoFetchChanged' ), color: ' info' })
201208}
202209
203- async function saveConfig() {
204- try {
205- await safeInvoke (' save_config' , {
206- config: {
207- lang: ' zh-CN' ,
208- client: {
209- interval: Number (config .interval ),
210- method: config .originMethod ,
211- select_origin: config .selectOrigin ,
212- custom_url: config .customUrl ,
213- auto_fetch: config .autoFetch ,
214- },
215- server: { interval: 60 , port: 9898 },
216- },
217- })
218- } catch (_ ) { }
210+ async function syncToSharedConfig() {
211+ await updateClient ({
212+ interval: Number (config .interval ),
213+ method: config .originMethod ,
214+ select_origin: config .selectOrigin ,
215+ custom_url: config .customUrl ,
216+ auto_fetch: config .autoFetch ,
217+ })
219218}
220219
221- async function loadConfig() {
222- try {
223- const cfg: any = await safeInvoke (' load_config' )
224- if (cfg ) {
225- config .interval = cfg .client ?.interval ?? 60
226- config .originMethod = cfg .client ?.method ?? ' official'
227- config .selectOrigin = cfg .client ?.select_origin ?? ' FetchGithubHosts'
228- config .customUrl = cfg .client ?.custom_url ?? ' '
229- config .autoFetch = cfg .client ?.auto_fetch ?? false
230- }
231- } catch (_ ) { }
220+ function syncFromSharedConfig() {
221+ const c = appConfig .value .client
222+ config .interval = c .interval ?? 60
223+ config .originMethod = c .method ?? ' official'
224+ config .selectOrigin = c .select_origin ?? ' FetchGithubHosts'
225+ config .customUrl = c .custom_url ?? ' '
226+ config .autoFetch = c .auto_fetch ?? false
232227}
233228
234229onMounted (async () => {
@@ -237,6 +232,7 @@ onMounted(async () => {
237232 addLog (event .payload .message )
238233 })
239234 await loadConfig ()
235+ syncFromSharedConfig ()
240236 // Auto fetch on startup if enabled
241237 if (config .autoFetch ) {
242238 startFetch ()
0 commit comments