diff --git a/backend/src/db.ts b/backend/src/db.ts index 399e93e..3f19c78 100644 --- a/backend/src/db.ts +++ b/backend/src/db.ts @@ -7,52 +7,52 @@ import { join } from "path"; export let FTS5Enabled = true; export const initializeDB = () => { - logger.info("Checking fts"); - const ftstest = db.query(`pragma compile_options;`); - const result = ftstest.all() as { compile_options: string }[]; - if (result.find((o) => o["compile_options"].includes("ENABLE_FTS5"))) { - logger.info("FTS5 is enabled"); - } else { - logger.info("FTS5 is not enabled. Attempting to load..."); - try { - db.loadExtension('./fts5'); - } catch (e) { - logger.warn("Failed to load FTS5 extension. Disabling FTS5"); - FTS5Enabled = false; - } + logger.info("Checking fts"); + const ftstest = db.query(`pragma compile_options;`); + const result = ftstest.all() as { compile_options: string }[]; + if (result.find((o) => o["compile_options"].includes("ENABLE_FTS5"))) { + logger.info("FTS5 is enabled"); + } else { + logger.info("FTS5 is not enabled. Attempting to load..."); + try { + db.loadExtension('./fts5'); + } catch (e) { + logger.warn("Failed to load FTS5 extension. Disabling FTS5"); + FTS5Enabled = false; } + } - return FTS5Enabled; + return FTS5Enabled; } export const migrate = async () => { - logger.info(`Checking for migrations...`); - const result = db.query(`SELECT name FROM sqlite_master WHERE type='table' AND name='meta'`); - if (result.all().length === 0) { - logger.info(`Creating meta table...`); - db.run(`CREATE TABLE meta (version INTEGER)`); - db.run(`INSERT INTO meta (version) VALUES (0)`); - } + logger.info(`Checking for migrations...`); + const result = db.query(`SELECT name FROM sqlite_master WHERE type='table' AND name='meta'`); + if (result.all().length === 0) { + logger.info(`Creating meta table...`); + db.run(`CREATE TABLE meta (version INTEGER)`); + db.run(`INSERT INTO meta (version) VALUES (0)`); + } - const version = db.query(`SELECT version FROM meta`).get() as { version: number }; - logger.info(`Migration version: ${version.version}`); - // we are in bun.js. use its API's to read the file list. - logger.info(`Searching for migrations in ${join(__dirname, "migrations")}`); - const files = await readdir(join(__dirname, "migrations")); - - for (const file of files) { - const [fileVersion, ...rest] = file.split("_"); - logger.info(`Found migration ${fileVersion}`); - if (fileVersion && Number(fileVersion) > version.version) { - logger.info(`Running migration ${file}`); - const sql = new TextDecoder().decode(await readFile(join(__dirname, `migrations/${file}`))); - db.run(sql); - const query = db.query(`UPDATE meta SET version = $version`); - const res = query.run( {$version: Number(fileVersion)}) - logger.info(`Migration ${file} done`); - } + const version = db.query(`SELECT version FROM meta`).get() as { version: number }; + logger.info(`Migration version: ${version.version}`); + // we are in bun.js. use its API's to read the file list. + logger.info(`Searching for migrations in ${join(__dirname, "migrations")}`); + const files = await readdir(join(__dirname, "migrations")); + + for (const file of files) { + const [fileVersion, ...rest] = file.split("_"); + logger.info(`Found migration ${fileVersion}`); + if (fileVersion && Number(fileVersion) > version.version) { + logger.info(`Running migration ${file}`); + const sql = new TextDecoder().decode(await readFile(join(__dirname, `migrations/${file}`))); + db.run(sql); + const query = db.query(`UPDATE meta SET version = $version`); + const res = query.run({ $version: Number(fileVersion) }) + logger.info(`Migration ${file} done`); } - logger.info(`Migrations done`); + } + logger.info(`Migrations done`); } logger.info(`Loading database at ${DB_PATH}`); diff --git a/frontend/src/dialogs/merge-dialog.ts b/frontend/src/dialogs/merge-dialog.ts index 7b04f3b..4fdb13b 100644 --- a/frontend/src/dialogs/merge-dialog.ts +++ b/frontend/src/dialogs/merge-dialog.ts @@ -8,7 +8,7 @@ import { showToast } from "../speech"; export class MergeDialog extends Dialog { private channelList: Dropdown; private mergeButton: Button; - private cancelButton: Button; + protected cancelButton: Button; public constructor() { super("Merge channels", false); diff --git a/frontend/src/dialogs/remove-dialog.ts b/frontend/src/dialogs/remove-dialog.ts index bf3f061..4399957 100644 --- a/frontend/src/dialogs/remove-dialog.ts +++ b/frontend/src/dialogs/remove-dialog.ts @@ -8,14 +8,14 @@ import { showToast } from "../speech"; export class RemoveDialog extends Dialog { private content: Text; private confirmButton: Button; - private cancelButton: Button; + protected cancelButton: Button; public constructor(channelId: string) { super("Remove channel", false); this.content = new Text("Are you sure you want to remove this channel?"); this.confirmButton = new Button("Remove"); this.confirmButton.setPosition(30, 30, 40, 30); - this.confirmButton.onClick(() => this.remove()); + this.confirmButton.onClick(() => this.doRemove()); this.cancelButton = new Button("Cancel"); this.cancelButton.setPosition(30, 70, 40, 30); this.cancelButton.onClick(() => this.cancel()); @@ -24,7 +24,7 @@ export class RemoveDialog extends Dialog { this.add(this.cancelButton); } - private async remove() { + private async doRemove() { try { const res = await API.deleteChannel(state.currentChannel!.id.toString()); state.removeChannel(state.currentChannel!); diff --git a/frontend/src/ui/dialog.ts b/frontend/src/ui/dialog.ts index eb5909e..bcaa135 100644 --- a/frontend/src/ui/dialog.ts +++ b/frontend/src/ui/dialog.ts @@ -6,8 +6,8 @@ export class Dialog extends UIWindow { private rejectPromise!: (reason?: any) => void; private promise: Promise; private dialogElement!: HTMLDialogElement; - private okButton?: Button; - private cancelButton?: Button; + protected okButton?: Button; + protected cancelButton?: Button; private previouslyFocusedElement!: HTMLElement;