From 455820a9cf9cb78d0cb80da8deaeccc2269070c5 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Fri, 9 Jul 2021 17:43:36 -0700 Subject: [PATCH] Fix "delete and restart" after database error --- main.js | 2 +- ts/sql/main.ts | 7 +++++++ ts/sql/mainWorker.ts | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 3d57cc3879..c738eafee5 100644 --- a/main.js +++ b/main.js @@ -1318,7 +1318,7 @@ app.on('ready', async () => { `Database startup error:\n\n${redactAll(sqlError.stack)}` ); } else { - await sql.sqlCall('removeDB', []); + await sql.removeDB(); removeUserConfig(); app.relaunch(); } diff --git a/ts/sql/main.ts b/ts/sql/main.ts index 1d50c2760f..4dbf6bcdb7 100644 --- a/ts/sql/main.ts +++ b/ts/sql/main.ts @@ -22,6 +22,9 @@ export type WorkerRequest = | { readonly type: 'close'; } + | { + readonly type: 'removeDB'; + } | { readonly type: 'sqlCall'; readonly method: string; @@ -117,6 +120,10 @@ export class MainSQL { await this.onExit; } + public async removeDB(): Promise { + await this.send({ type: 'removeDB' }); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any public async sqlCall(method: string, args: ReadonlyArray): Promise { if (this.onReady) { diff --git a/ts/sql/mainWorker.ts b/ts/sql/mainWorker.ts index 41dcb689dc..699da8862d 100644 --- a/ts/sql/mainWorker.ts +++ b/ts/sql/mainWorker.ts @@ -39,6 +39,13 @@ port.on('message', async ({ seq, request }: WrappedWorkerRequest) => { return; } + if (request.type === 'removeDB') { + await db.removeDB(); + + respond(seq, undefined, undefined); + return; + } + if (request.type === 'sqlCall') { // eslint-disable-next-line @typescript-eslint/no-explicit-any const method = (db as any)[request.method];