signal-desktop/ts/shims/deleteAllData.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-08-24 20:57:34 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import * as log from '../logging/log';
2024-07-22 18:16:33 +00:00
import { DataWriter } from '../sql/Client';
import { deleteAllLogs } from '../util/deleteAllLogs';
import * as Errors from '../types/errors';
2021-08-24 20:57:34 +00:00
export async function deleteAllData(): Promise<void> {
2024-08-19 20:26:05 +00:00
try {
// This might fail if websocket closes before we receive the response, while
// still unlinking the device on the server.
await window.textsecure.server?.unlink();
} catch (error) {
log.error(
'Something went wrong unlinking device:',
Errors.toLogFormat(error)
);
}
2021-08-24 20:57:34 +00:00
try {
await deleteAllLogs();
2021-08-24 20:57:34 +00:00
log.info('deleteAllData: deleted all logs');
2021-08-24 20:57:34 +00:00
2024-07-22 18:16:33 +00:00
await DataWriter.removeAll();
2021-08-24 20:57:34 +00:00
log.info('deleteAllData: emptied database');
2021-08-24 20:57:34 +00:00
2024-07-22 18:16:33 +00:00
await DataWriter.close();
2021-08-24 20:57:34 +00:00
log.info('deleteAllData: closed database');
2021-08-24 20:57:34 +00:00
2024-07-22 18:16:33 +00:00
await DataWriter.removeDB();
2021-08-24 20:57:34 +00:00
log.info('deleteAllData: removed database');
2021-08-24 20:57:34 +00:00
2024-07-22 18:16:33 +00:00
await DataWriter.removeOtherData();
2021-08-24 20:57:34 +00:00
log.info('deleteAllData: removed all other data');
2021-08-24 20:57:34 +00:00
} catch (error) {
log.error(
2021-08-24 20:57:34 +00:00
'Something went wrong deleting all data:',
Errors.toLogFormat(error)
2021-08-24 20:57:34 +00:00
);
}
2023-11-06 21:19:23 +00:00
window.SignalContext.restartApp();
2021-08-24 20:57:34 +00:00
}