Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Adjusted precheck logic to also account for missing tables
Browse files Browse the repository at this point in the history
  • Loading branch information
coltoneshaw committed Dec 1, 2021
1 parent 3258f42 commit d6ee073
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/Database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function deleteAllData(profileID?: string): Promise<void> {
}
log.info('attempting to delete all database info for ' + profileID)

fsExtra.remove(path.join(appDataPath, 'databases', profileID + '.sqlite3'), err => {
await fsExtra.remove(path.join(appDataPath, 'databases', profileID + '.sqlite3'), err => {
if (err) return log.error('unable to delete database for ' + profileID + err)
log.info('database info deleted for ' + profileID)
})
Expand Down
4 changes: 1 addition & 3 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ ipcMain.handle('config-clear', () =>config.clear());



ipcMain.handle('query-database', (event, profileId:string, queryString) => {
return query(profileId, queryString)
});
ipcMain.handle('query-database', async (event, profileId:string, queryString) => await query(profileId, queryString) );

ipcMain.handle('update-database', (event, profileId:string, table, updateData): void => update(profileId, table, updateData));

Expand Down
7 changes: 5 additions & 2 deletions src/main/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { app, Menu, dialog, BrowserWindow } from 'electron';
const isMac = process.platform === 'darwin'
import log from 'electron-log';

import { deleteAllData } from '@/main/Database/database';
import { deleteAllData, checkOrMakeTables } from '@/main/Database/database';
import { setDefaultConfig, getProfileConfigAll, setProfileConfig } from '@/main/Config/config';

const { win } = require('@/main/main')
Expand Down Expand Up @@ -171,7 +171,10 @@ const template = [

// 2. Delete the database for everything pertaining to that profile
await deleteAllData(currentProfileConfig.id)
// 3. resync the database for the profile

// 3. create the new table
await checkOrMakeTables(currentProfileConfig.id)


const options = {
type: 'question',
Expand Down
19 changes: 15 additions & 4 deletions src/main/precheck.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
import { config } from "@/main/Config/config";
import { TconfigValues } from "@/types/config";
import { checkOrMakeTables } from "./Database/initializeDatabase";

const checkInvalidConfig = async () => {
const loadedConfig = config.store;
const currentProfile = loadedConfig?.current;
const checkInvalidConfig = async (currentProfile: string | undefined | 'default', loadedConfig: TconfigValues) => {

if(!currentProfile || currentProfile === 'default'){
const profileIds = Object.keys(loadedConfig.profiles);
config.set('current', profileIds[0])
}
}

const checkProfileDatabase = async (currentProfile: string) => {
await checkOrMakeTables(currentProfile)
}



export const preloadCheck = async () => {
await checkInvalidConfig()
const loadedConfig = config.store;
const currentProfile = loadedConfig?.current;

await checkInvalidConfig(currentProfile, loadedConfig)
await checkProfileDatabase(currentProfile)
}

0 comments on commit d6ee073

Please sign in to comment.