diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index a758cb95..84fc20be 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -1,4 +1,6 @@ +import { Directory, Filesystem } from '@capacitor/filesystem'; import type { Feedback } from './types'; +import { log } from '$lib/log'; export function toggleDarkMode() { document.body.classList.toggle('dark'); @@ -35,3 +37,26 @@ export function negativeFeedback(feedback: string, message?: string): Feedback { message }; } + + +export const clearHttpStorage = async () => { + try { + const result = await Filesystem.readdir({ + path: 'HTTPStorages/com.didroom.wallet/', + directory: Directory.Library + }); + + const httpStorageFiles = result.files.filter((file) => + file.name.includes('httpstorages.sqlite') + ); + + for (const file of httpStorageFiles) { + await Filesystem.deleteFile({ + path: `HTTPStorages/com.didroom.wallet/${file.name}`, + directory: Directory.Library + }); + } + } catch (error) { + log(String(error)); + } +}; diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index aa36a486..d6efb0a3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -18,43 +18,13 @@ import { gotoQrResult } from '$lib/components/organisms/scanner/tools'; import FingerPrint from '$lib/assets/lottieFingerPrint/FingerPrint.svelte'; import { m } from '$lib/i18n'; - import { Filesystem, Directory } from '@capacitor/filesystem'; + import { clearHttpStorage } from '$lib/utils'; - const clearHttpStorage = async () => { - try { - const result = await Filesystem.readdir({ - path: 'HTTPStorages/com.didroom.wallet/', - directory: Directory.Library - }); - const httpStorageFiles = result.files.filter((file) => - file.name.includes('httpstorages.sqlite') - ); - - for (const file of httpStorageFiles) { - await Filesystem.deleteFile({ - path: `HTTPStorages/com.didroom.wallet/${file.name}`, - directory: Directory.Library - }); - } - } catch (error) { - log(String(error)); - } - }; + $: clearHttpStorage(); - // const forceNewRequestWithHttp = async () => { - // try { - // const response = await CapacitorHttp.get({ - // url: 'https://staging.admin.didroom.com/api/health' - // }); - // console.log('Network request successful:', response); - // } catch (error) { - // console.error('Network request failed:', error); - // } - // }; - const controller = new AbortController(); const signal = controller.signal; @@ -85,11 +55,6 @@ App.addListener('appUrlOpen', async (data) => { await gotoQrResult(data.url); }); - // App.addListener('appStateChange', (state) => { - // if (state.isActive) { - // forceNewRequestWithHttp(); - // } - // }); }); onDestroy(() => { controller.abort(); diff --git a/src/routes/[[lang]]/(protected)/+layout.svelte b/src/routes/[[lang]]/(protected)/+layout.svelte index ea1d204f..2e9acb7e 100644 --- a/src/routes/[[lang]]/(protected)/+layout.svelte +++ b/src/routes/[[lang]]/(protected)/+layout.svelte @@ -5,6 +5,7 @@ import { goto, m, r } from '$lib/i18n'; import { onDestroy, onMount } from 'svelte'; import type { PluginListenerHandle } from '@capacitor/core'; + import { clearHttpStorage } from '$lib/utils/index.js'; export let data; let appStateChange: PluginListenerHandle; @@ -13,6 +14,7 @@ onMount(async () => { appStateChange = await App.addListener('appStateChange', async (state) => { + await clearHttpStorage(); if (!state.isActive && !(r('/user-settings') === window.location.pathname)) { await goto('/unlock'); }