fix: migration wrong directory (#3278)

* fix: migration wrong directory

* reload model after migration

Signed-off-by: James <namnh0122@gmail.com>

---------

Signed-off-by: James <namnh0122@gmail.com>
This commit is contained in:
NamH 2024-08-06 17:15:24 +07:00 committed by GitHub
parent 44a6401000
commit 7fb1354287
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 18 additions and 8 deletions

View File

@ -231,7 +231,10 @@ export function handleAppIPCs() {
const destinationFolderPath = join(configration.data_folder, 'models') const destinationFolderPath = join(configration.data_folder, 'models')
if (!existsSync(destinationFolderPath)) mkdirSync(destinationFolderPath) if (!existsSync(destinationFolderPath)) mkdirSync(destinationFolderPath)
console.log('destinationFolderPath', destinationFolderPath)
console.log(
`Syncing model from ${allModelFolders} to ${destinationFolderPath}`
)
const reflect = require('@alumna/reflect') const reflect = require('@alumna/reflect')
for (const modelName of allModelFolders) { for (const modelName of allModelFolders) {
@ -305,7 +308,6 @@ export function handleAppIPCs() {
src: modelFolderPath, src: modelFolderPath,
dest: destinationPath, dest: destinationPath,
recursive: true, recursive: true,
exclude: ['model.json'],
delete: false, delete: false,
overwrite: true, overwrite: true,
errorOnExist: false, errorOnExist: false,

View File

@ -64,6 +64,7 @@ const host = '127.0.0.1'
app app
.whenReady() .whenReady()
.then(setupCore)
.then(() => { .then(() => {
if (!gotTheLock) { if (!gotTheLock) {
app.quit() app.quit()
@ -119,7 +120,6 @@ app
log.info(`stdout: ${stdout}`) log.info(`stdout: ${stdout}`)
}) })
}) })
.then(setupCore)
.then(createUserSpace) .then(createUserSpace)
.then(migrate) .then(migrate)
.then(setupMenu) .then(setupMenu)

View File

@ -4,7 +4,6 @@ import { join } from 'path'
import { AppConfiguration } from '@janhq/core/node' import { AppConfiguration } from '@janhq/core/node'
import os from 'os' import os from 'os'
const configurationFileName = 'settings.json' const configurationFileName = 'settings.json'
const defaultJanDataFolder = join(os.homedir(), 'jan') const defaultJanDataFolder = join(os.homedir(), 'jan')
@ -60,6 +59,7 @@ export const getAppConfigurations = (): AppConfiguration => {
// Retrieve Application Support folder path // Retrieve Application Support folder path
// Fallback to user home directory if not found // Fallback to user home directory if not found
const configurationFile = getConfigurationFilePath() const configurationFile = getConfigurationFilePath()
console.debug('getAppConfiguration file path', configurationFile)
if (!existsSync(configurationFile)) { if (!existsSync(configurationFile)) {
// create default app config if we don't have one // create default app config if we don't have one
@ -74,6 +74,7 @@ export const getAppConfigurations = (): AppConfiguration => {
const appConfigurations: AppConfiguration = JSON.parse( const appConfigurations: AppConfiguration = JSON.parse(
readFileSync(configurationFile, 'utf-8') readFileSync(configurationFile, 'utf-8')
) )
console.debug('app config', JSON.stringify(appConfigurations))
return appConfigurations return appConfigurations
} catch (err) { } catch (err) {
console.error( console.error(
@ -86,7 +87,7 @@ export const getAppConfigurations = (): AppConfiguration => {
const getConfigurationFilePath = () => const getConfigurationFilePath = () =>
join( join(
global.core?.appPath() || global.core?.appPath() ||
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'], process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'],
configurationFileName configurationFileName
) )

View File

@ -11,6 +11,8 @@ import Spinner from '@/containers/Loader/Spinner'
import useMigratingData from '@/hooks/useMigratingData' import useMigratingData from '@/hooks/useMigratingData'
import useModels from '@/hooks/useModels'
import { didShowMigrationWarningAtom } from '@/helpers/atoms/AppConfig.atom' import { didShowMigrationWarningAtom } from '@/helpers/atoms/AppConfig.atom'
export const showMigrationModalAtom = atom<boolean>(false) export const showMigrationModalAtom = atom<boolean>(false)
@ -29,6 +31,7 @@ const ModalMigrations = () => {
useState<MigrationState>('idle') useState<MigrationState>('idle')
const [modelMigrationState, setModelMigrationState] = const [modelMigrationState, setModelMigrationState] =
useState<MigrationState>('idle') useState<MigrationState>('idle')
const { getModels } = useModels()
const getStepTitle = () => { const getStepTitle = () => {
switch (step) { switch (step) {
@ -71,7 +74,8 @@ const ModalMigrations = () => {
setStep(2) setStep(2)
await migratingModels() await migratingModels()
await migrationThreadsAndMessages() await migrationThreadsAndMessages()
}, [migratingModels, migrationThreadsAndMessages]) getModels()
}, [migratingModels, migrationThreadsAndMessages, getModels])
const onDismiss = useCallback(() => { const onDismiss = useCallback(() => {
setStep(1) setStep(1)

View File

@ -43,10 +43,13 @@ const DataMigration: React.FC = () => {
<div className="flex w-full flex-col items-start justify-between gap-4 border-b border-[hsla(var(--app-border))] py-4 first:pt-0 last:border-none sm:flex-row"> <div className="flex w-full flex-col items-start justify-between gap-4 border-b border-[hsla(var(--app-border))] py-4 first:pt-0 last:border-none sm:flex-row">
<div className="flex-shrink-0 space-y-1"> <div className="flex-shrink-0 space-y-1">
<div className="flex gap-x-2"> <div className="flex gap-x-2">
<h6 className="font-semibold capitalize">Clear logs</h6> <h6 className="font-semibold capitalize">
Migrate data from old version of Jan app
</h6>
</div> </div>
<p className="font-medium leading-relaxed text-[hsla(var(--text-secondary))]"> <p className="font-medium leading-relaxed text-[hsla(var(--text-secondary))]">
Clear all logs from Jan app. Migrate multiple times can cause duplicate threads, please consider
using the remove threads button to clean up existing threads data
</p> </p>
</div> </div>
<div className="flex flex-row gap-x-2"> <div className="flex flex-row gap-x-2">