Fix dialogs
parent
ccdaa571d8
commit
d9a7282929
|
@ -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}`);
|
||||
|
|
|
@ -8,7 +8,7 @@ import { showToast } from "../speech";
|
|||
export class MergeDialog extends Dialog<boolean> {
|
||||
private channelList: Dropdown;
|
||||
private mergeButton: Button;
|
||||
private cancelButton: Button;
|
||||
protected cancelButton: Button;
|
||||
|
||||
public constructor() {
|
||||
super("Merge channels", false);
|
||||
|
|
|
@ -8,14 +8,14 @@ import { showToast } from "../speech";
|
|||
export class RemoveDialog extends Dialog<boolean> {
|
||||
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<boolean> {
|
|||
this.add(this.cancelButton);
|
||||
}
|
||||
|
||||
private async remove() {
|
||||
private async doRemove() {
|
||||
try {
|
||||
const res = await API.deleteChannel(state.currentChannel!.id.toString());
|
||||
state.removeChannel(state.currentChannel!);
|
||||
|
|
|
@ -6,8 +6,8 @@ export class Dialog<T> extends UIWindow {
|
|||
private rejectPromise!: (reason?: any) => void;
|
||||
private promise: Promise<T>;
|
||||
private dialogElement!: HTMLDialogElement;
|
||||
private okButton?: Button;
|
||||
private cancelButton?: Button;
|
||||
protected okButton?: Button;
|
||||
protected cancelButton?: Button;
|
||||
|
||||
private previouslyFocusedElement!: HTMLElement;
|
||||
|
||||
|
|
Loading…
Reference in New Issue