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:
parent
ab77622e73
commit
05eebfa430
@ -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'
|
||||||
|
|||||||
@ -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:')
|
||||||
|
|||||||
@ -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) {
|
|
||||||
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) {
|
if (!keepCurrentFolder) {
|
||||||
|
// set the default jan data folder to user's home directory
|
||||||
const configuration: AppConfiguration = {
|
const configuration: AppConfiguration = {
|
||||||
data_folder: defaultJanDataFolder,
|
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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user