From 69888fb1e03a2bbdcfa0f47d37fa377f4599d445 Mon Sep 17 00:00:00 2001 From: Renaud Heluin Date: Fri, 30 Aug 2024 17:27:36 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20quand=20le=20`lastWorkDir`=20n'est=20pl?= =?UTF-8?q?us=20pr=C3=A9sent=20dans=20store,=20faire=20un=20fall=20back=20?= =?UTF-8?q?sur=20homeDir=20#51?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/handlers/initHandlers/getWorkDir.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/electron-app/ecoindex-app/src/main/handlers/initHandlers/getWorkDir.ts b/electron-app/ecoindex-app/src/main/handlers/initHandlers/getWorkDir.ts index 9ef45ee..6abe036 100644 --- a/electron-app/ecoindex-app/src/main/handlers/initHandlers/getWorkDir.ts +++ b/electron-app/ecoindex-app/src/main/handlers/initHandlers/getWorkDir.ts @@ -3,6 +3,7 @@ import { IpcMainEvent, IpcMainInvokeEvent } from 'electron' import { ConfigData } from '../../../class/ConfigData' import Store from 'electron-store' import { channels } from '../../../shared/constants' +import fs from 'node:fs' import { getMainLog } from '../../main' import { getMainWindow } from '../../../shared/memory' import os from 'node:os' @@ -19,6 +20,13 @@ export const initGetWorkDir = (_event: IpcMainEvent | IpcMainInvokeEvent) => { store.set(`lastWorkDir`, homedir) lastWorkDir = homedir } + try { + fs.accessSync(lastWorkDir as string) + } catch (error) { + store.set(`lastWorkDir`, homedir) + lastWorkDir = homedir + mainLog.info(`lastWorkDir unknown, fall back to homeDir`, lastWorkDir) + } return new Promise((resolve, reject) => { try {