refactor: last project may not exist

This commit is contained in:
Carlos Valente
2024-07-02 16:50:52 +02:00
committed by Carlos Valente
parent d94c1d4252
commit c944e77bc1
2 changed files with 4 additions and 4 deletions
@@ -4,7 +4,7 @@ import { JSONFile } from 'lowdb/node';
import { appStatePath, isTest } from '../../setup/index.js'; import { appStatePath, isTest } from '../../setup/index.js';
interface Config { interface Config {
lastLoadedProject: string; lastLoadedProject?: string;
} }
/** /**
@@ -19,7 +19,7 @@ class AppState {
constructor(appStatePath: string) { constructor(appStatePath: string) {
this.pathToFile = appStatePath; this.pathToFile = appStatePath;
const adapter = new JSONFile<Config>(this.pathToFile); const adapter = new JSONFile<Config>(this.pathToFile);
this.config = new Low<Config>(adapter, null); this.config = new Low<Config>(adapter, {});
} }
private async init() { private async init() {
@@ -41,7 +41,7 @@ class AppState {
return lastLoaded === projectName; return lastLoaded === projectName;
} }
async getLastLoadedProject(): Promise<string> { async getLastLoadedProject(): Promise<string | undefined> {
const data = await this.get(); const data = await this.get();
return data.lastLoadedProject; return data.lastLoadedProject;
} }
@@ -56,7 +56,7 @@ export async function getProjectList(): Promise<ProjectFileListResponse> {
return { return {
files, files,
lastLoadedProject: removeFileExtension(lastLoadedProject), lastLoadedProject: lastLoadedProject ? removeFileExtension(lastLoadedProject) : '',
}; };
} }