fonction disconnect
This commit is contained in:
parent
a3542a48e9
commit
a16e984ecd
@ -181,3 +181,40 @@ async function createBackUp() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(window as any).createBackUp = createBackUp;
|
(window as any).createBackUp = createBackUp;
|
||||||
|
|
||||||
|
async function disconnect() {
|
||||||
|
console.log('Disconnecting...');
|
||||||
|
try {
|
||||||
|
localStorage.clear();
|
||||||
|
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
const request = indexedDB.deleteDatabase('4nk');
|
||||||
|
request.onsuccess = () => {
|
||||||
|
console.log('IndexedDB deleted successfully');
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
request.onerror = () => reject(request.error);
|
||||||
|
request.onblocked = () => {
|
||||||
|
console.log('Database deletion was blocked');
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const registrations = await navigator.serviceWorker.getRegistrations();
|
||||||
|
await Promise.all(registrations.map(registration => registration.unregister()));
|
||||||
|
console.log('Service worker unregistered');
|
||||||
|
|
||||||
|
navigate('home');
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = window.location.origin;
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error during disconnect:', error);
|
||||||
|
// force reload
|
||||||
|
window.location.href = window.location.origin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(window as any).disconnect = disconnect;
|
@ -5,12 +5,15 @@ export function cleanSubscriptions(): void {
|
|||||||
for (const sub of subscriptions) {
|
for (const sub of subscriptions) {
|
||||||
const el = sub.element;
|
const el = sub.element;
|
||||||
const eventHandler = sub.eventHandler;
|
const eventHandler = sub.eventHandler;
|
||||||
el.removeEventListener(sub.event, eventHandler);
|
if (el) {
|
||||||
|
el.removeEventListener(sub.event, eventHandler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
subscriptions = [];
|
subscriptions = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function addSubscription(element: Element | Document, event: any, eventHandler: EventListenerOrEventListenerObject): void {
|
export function addSubscription(element: Element | Document, event: any, eventHandler: EventListenerOrEventListenerObject): void {
|
||||||
|
if (!element) return;
|
||||||
subscriptions.push({ element, event, eventHandler });
|
subscriptions.push({ element, event, eventHandler });
|
||||||
element.addEventListener(event, eventHandler);
|
element.addEventListener(event, eventHandler);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user