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 { readdirSync } from 'fs'
import { join, extname } from 'path' import { join, extname } from 'path'
import { ExtensionRoute } from '../../../api'
import { Processor } from './Processor' import { Processor } from './Processor'
import { ModuleManager } from '../../helper/module' import { ModuleManager } from '../../helper/module'
import { getJanExtensionsPath as getPath } from '../../helper' import { getJanExtensionsPath as getPath } from '../../helper'

View File

@ -7,7 +7,7 @@ export const setupReactDevTool = async () => {
'electron-devtools-installer' 'electron-devtools-installer'
) // Don't use import on top level, since the installer package is dev-only ) // Don't use import on top level, since the installer package is dev-only
try { try {
const name = installExtension(REACT_DEVELOPER_TOOLS) const name = await installExtension(REACT_DEVELOPER_TOOLS)
console.log(`Added Extension: ${name}`) console.log(`Added Extension: ${name}`)
} catch (err) { } catch (err) {
console.log('An error occurred while installing devtools:') console.log('An error occurred while installing devtools:')

View File

@ -26,29 +26,18 @@ export default function useFactoryReset() {
console.debug('appConfiguration: ', appConfiguration) console.debug('appConfiguration: ', appConfiguration)
const janDataFolderPath = appConfiguration!.data_folder const janDataFolderPath = appConfiguration!.data_folder
if (defaultJanDataFolder === janDataFolderPath) { if (!keepCurrentFolder) {
console.debug('Jan data folder is already at user home') // set the default jan data folder to user's home directory
} else { const configuration: AppConfiguration = {
// if jan data folder is not at user home, we update the app configuration to point to user home data_folder: defaultJanDataFolder,
if (!keepCurrentFolder) {
const configuration: AppConfiguration = {
data_folder: defaultJanDataFolder,
}
await window.core?.api?.updateAppConfiguration(configuration)
} }
await window.core?.api?.updateAppConfiguration(configuration)
} }
await fs.rmdirSync(janDataFolderPath, { recursive: true })
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 })
// reset the localStorage // reset the localStorage
localStorage.clear() localStorage.clear()
await window.core?.api?.relaunch() await window.core?.api?.relaunch()
} }