Fix dialogs

main
Talon 2024-08-24 16:43:49 +02:00
parent ccdaa571d8
commit d9a7282929
4 changed files with 45 additions and 45 deletions

View File

@ -7,52 +7,52 @@ import { join } from "path";
export let FTS5Enabled = true; export let FTS5Enabled = true;
export const initializeDB = () => { export const initializeDB = () => {
logger.info("Checking fts"); logger.info("Checking fts");
const ftstest = db.query(`pragma compile_options;`); const ftstest = db.query(`pragma compile_options;`);
const result = ftstest.all() as { compile_options: string }[]; const result = ftstest.all() as { compile_options: string }[];
if (result.find((o) => o["compile_options"].includes("ENABLE_FTS5"))) { if (result.find((o) => o["compile_options"].includes("ENABLE_FTS5"))) {
logger.info("FTS5 is enabled"); logger.info("FTS5 is enabled");
} else { } else {
logger.info("FTS5 is not enabled. Attempting to load..."); logger.info("FTS5 is not enabled. Attempting to load...");
try { try {
db.loadExtension('./fts5'); db.loadExtension('./fts5');
} catch (e) { } catch (e) {
logger.warn("Failed to load FTS5 extension. Disabling FTS5"); logger.warn("Failed to load FTS5 extension. Disabling FTS5");
FTS5Enabled = false; FTS5Enabled = false;
}
} }
}
return FTS5Enabled; return FTS5Enabled;
} }
export const migrate = async () => { export const migrate = async () => {
logger.info(`Checking for migrations...`); logger.info(`Checking for migrations...`);
const result = db.query(`SELECT name FROM sqlite_master WHERE type='table' AND name='meta'`); const result = db.query(`SELECT name FROM sqlite_master WHERE type='table' AND name='meta'`);
if (result.all().length === 0) { if (result.all().length === 0) {
logger.info(`Creating meta table...`); logger.info(`Creating meta table...`);
db.run(`CREATE TABLE meta (version INTEGER)`); db.run(`CREATE TABLE meta (version INTEGER)`);
db.run(`INSERT INTO meta (version) VALUES (0)`); db.run(`INSERT INTO meta (version) VALUES (0)`);
} }
const version = db.query(`SELECT version FROM meta`).get() as { version: number }; const version = db.query(`SELECT version FROM meta`).get() as { version: number };
logger.info(`Migration version: ${version.version}`); logger.info(`Migration version: ${version.version}`);
// we are in bun.js. use its API's to read the file list. // we are in bun.js. use its API's to read the file list.
logger.info(`Searching for migrations in ${join(__dirname, "migrations")}`); logger.info(`Searching for migrations in ${join(__dirname, "migrations")}`);
const files = await readdir(join(__dirname, "migrations")); const files = await readdir(join(__dirname, "migrations"));
for (const file of files) { for (const file of files) {
const [fileVersion, ...rest] = file.split("_"); const [fileVersion, ...rest] = file.split("_");
logger.info(`Found migration ${fileVersion}`); logger.info(`Found migration ${fileVersion}`);
if (fileVersion && Number(fileVersion) > version.version) { if (fileVersion && Number(fileVersion) > version.version) {
logger.info(`Running migration ${file}`); logger.info(`Running migration ${file}`);
const sql = new TextDecoder().decode(await readFile(join(__dirname, `migrations/${file}`))); const sql = new TextDecoder().decode(await readFile(join(__dirname, `migrations/${file}`)));
db.run(sql); db.run(sql);
const query = db.query(`UPDATE meta SET version = $version`); const query = db.query(`UPDATE meta SET version = $version`);
const res = query.run( {$version: Number(fileVersion)}) const res = query.run({ $version: Number(fileVersion) })
logger.info(`Migration ${file} done`); logger.info(`Migration ${file} done`);
}
} }
logger.info(`Migrations done`); }
logger.info(`Migrations done`);
} }
logger.info(`Loading database at ${DB_PATH}`); logger.info(`Loading database at ${DB_PATH}`);

View File

@ -8,7 +8,7 @@ import { showToast } from "../speech";
export class MergeDialog extends Dialog<boolean> { export class MergeDialog extends Dialog<boolean> {
private channelList: Dropdown; private channelList: Dropdown;
private mergeButton: Button; private mergeButton: Button;
private cancelButton: Button; protected cancelButton: Button;
public constructor() { public constructor() {
super("Merge channels", false); super("Merge channels", false);

View File

@ -8,14 +8,14 @@ import { showToast } from "../speech";
export class RemoveDialog extends Dialog<boolean> { export class RemoveDialog extends Dialog<boolean> {
private content: Text; private content: Text;
private confirmButton: Button; private confirmButton: Button;
private cancelButton: Button; protected cancelButton: Button;
public constructor(channelId: string) { public constructor(channelId: string) {
super("Remove channel", false); super("Remove channel", false);
this.content = new Text("Are you sure you want to remove this channel?"); this.content = new Text("Are you sure you want to remove this channel?");
this.confirmButton = new Button("Remove"); this.confirmButton = new Button("Remove");
this.confirmButton.setPosition(30, 30, 40, 30); this.confirmButton.setPosition(30, 30, 40, 30);
this.confirmButton.onClick(() => this.remove()); this.confirmButton.onClick(() => this.doRemove());
this.cancelButton = new Button("Cancel"); this.cancelButton = new Button("Cancel");
this.cancelButton.setPosition(30, 70, 40, 30); this.cancelButton.setPosition(30, 70, 40, 30);
this.cancelButton.onClick(() => this.cancel()); this.cancelButton.onClick(() => this.cancel());
@ -24,7 +24,7 @@ export class RemoveDialog extends Dialog<boolean> {
this.add(this.cancelButton); this.add(this.cancelButton);
} }
private async remove() { private async doRemove() {
try { try {
const res = await API.deleteChannel(state.currentChannel!.id.toString()); const res = await API.deleteChannel(state.currentChannel!.id.toString());
state.removeChannel(state.currentChannel!); state.removeChannel(state.currentChannel!);

View File

@ -6,8 +6,8 @@ export class Dialog<T> extends UIWindow {
private rejectPromise!: (reason?: any) => void; private rejectPromise!: (reason?: any) => void;
private promise: Promise<T>; private promise: Promise<T>;
private dialogElement!: HTMLDialogElement; private dialogElement!: HTMLDialogElement;
private okButton?: Button; protected okButton?: Button;
private cancelButton?: Button; protected cancelButton?: Button;
private previouslyFocusedElement!: HTMLElement; private previouslyFocusedElement!: HTMLElement;