Skip to content

Commit

Permalink
fix: ios navigatin when passing background/foreground
Browse files Browse the repository at this point in the history
  • Loading branch information
phoebus-84 committed Nov 22, 2024
1 parent 313c0ba commit b2e7a2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 37 deletions.
25 changes: 25 additions & 0 deletions src/lib/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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));
}
};
39 changes: 2 additions & 37 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,11 +55,6 @@
App.addListener('appUrlOpen', async (data) => {
await gotoQrResult(data.url);
});
// App.addListener('appStateChange', (state) => {
// if (state.isActive) {
// forceNewRequestWithHttp();
// }
// });
});
onDestroy(() => {
controller.abort();
Expand Down
2 changes: 2 additions & 0 deletions src/routes/[[lang]]/(protected)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
}
Expand Down

0 comments on commit b2e7a2a

Please sign in to comment.