feat: ensure all events are loaded before create window

This commit is contained in:
Zamitto 2025-01-29 09:50:59 -03:00
parent 94a13991fa
commit f62c3f9c37
2 changed files with 13 additions and 14 deletions

View File

@ -9,6 +9,7 @@ import resources from "@locales";
import { PythonRPC } from "./services/python-rpc";
import { Aria2 } from "./services/aria2";
import { db, levelKeys } from "./level";
import { loadState } from "./main";
const { autoUpdater } = updater;
@ -57,7 +58,7 @@ app.whenReady().then(async () => {
return net.fetch(url.pathToFileURL(decodeURI(filePath)).toString());
});
await import("./main");
await loadState();
const language = await db.get<string, string>(levelKeys.language, {
valueEncoding: "utf-8",

View File

@ -21,7 +21,17 @@ import {
import { Auth, User, type UserPreferences } from "@types";
import { knexClient } from "./knex-client";
export const loadState = async (userPreferences: UserPreferences | null) => {
export const loadState = async () => {
const userPreferences = await migrateFromSqlite().then(async () => {
await db.put<string, boolean>(levelKeys.sqliteMigrationDone, true, {
valueEncoding: "json",
});
return db.get<string, UserPreferences>(levelKeys.userPreferences, {
valueEncoding: "json",
});
});
await import("./events");
Aria2.spawn();
@ -192,15 +202,3 @@ const migrateFromSqlite = async () => {
migrateUser,
]);
};
migrateFromSqlite().then(async () => {
await db.put<string, boolean>(levelKeys.sqliteMigrationDone, true, {
valueEncoding: "json",
});
db.get<string, UserPreferences>(levelKeys.userPreferences, {
valueEncoding: "json",
}).then((userPreferences) => {
loadState(userPreferences);
});
});