From 05eebfa43002f4ad44b3b6f6b028b9d7df24eafd Mon Sep 17 00:00:00 2001 From: NamH Date: Thu, 15 Feb 2024 16:38:29 +0700 Subject: [PATCH] fix: factory reset not remove jan data folder (#2027) * fix: factory reset not remove jan data folder Signed-off-by: James * chore: prettier fix --------- Signed-off-by: James Co-authored-by: James Co-authored-by: Louis --- core/src/node/api/processors/extension.ts | 1 - electron/utils/dev.ts | 2 +- web/hooks/useFactoryReset.ts | 25 +++++++---------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/core/src/node/api/processors/extension.ts b/core/src/node/api/processors/extension.ts index 95dcd19d0..df5d2d945 100644 --- a/core/src/node/api/processors/extension.ts +++ b/core/src/node/api/processors/extension.ts @@ -1,7 +1,6 @@ import { readdirSync } from 'fs' import { join, extname } from 'path' -import { ExtensionRoute } from '../../../api' import { Processor } from './Processor' import { ModuleManager } from '../../helper/module' import { getJanExtensionsPath as getPath } from '../../helper' diff --git a/electron/utils/dev.ts b/electron/utils/dev.ts index fdec3b1d4..b2a492886 100644 --- a/electron/utils/dev.ts +++ b/electron/utils/dev.ts @@ -7,7 +7,7 @@ export const setupReactDevTool = async () => { 'electron-devtools-installer' ) // Don't use import on top level, since the installer package is dev-only try { - const name = installExtension(REACT_DEVELOPER_TOOLS) + const name = await installExtension(REACT_DEVELOPER_TOOLS) console.log(`Added Extension: ${name}`) } catch (err) { console.log('An error occurred while installing devtools:') diff --git a/web/hooks/useFactoryReset.ts b/web/hooks/useFactoryReset.ts index 56994d4c4..06a637572 100644 --- a/web/hooks/useFactoryReset.ts +++ b/web/hooks/useFactoryReset.ts @@ -26,29 +26,18 @@ export default function useFactoryReset() { console.debug('appConfiguration: ', appConfiguration) const janDataFolderPath = appConfiguration!.data_folder - if (defaultJanDataFolder === janDataFolderPath) { - console.debug('Jan data folder is already at user home') - } else { - // if jan data folder is not at user home, we update the app configuration to point to user home - if (!keepCurrentFolder) { - const configuration: AppConfiguration = { - data_folder: defaultJanDataFolder, - } - await window.core?.api?.updateAppConfiguration(configuration) + if (!keepCurrentFolder) { + // set the default jan data folder to user's home directory + const configuration: AppConfiguration = { + data_folder: defaultJanDataFolder, } + await window.core?.api?.updateAppConfiguration(configuration) } - - const modelPath = await joinPath([janDataFolderPath, 'models']) - const threadPath = await joinPath([janDataFolderPath, 'threads']) - - console.debug(`Removing models at ${modelPath}`) - await fs.rmdirSync(modelPath, { recursive: true }) - - console.debug(`Removing threads at ${threadPath}`) - await fs.rmdirSync(threadPath, { recursive: true }) + await fs.rmdirSync(janDataFolderPath, { recursive: true }) // reset the localStorage localStorage.clear() + await window.core?.api?.relaunch() }