fix: factory reset not remove jan data folder (#2027)

* fix: factory reset not remove jan data folder

Signed-off-by: James <james@jan.ai>

* chore: prettier fix

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
Co-authored-by: Louis <louis@jan.ai>
This commit is contained in:
NamH 2024-02-15 16:38:29 +07:00 committed by GitHub
parent ab77622e73
commit 05eebfa430
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 20 deletions

View File

@ -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'

View File

@ -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:')

View File

@ -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) {
// 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()
}