Skip to content

Commit

Permalink
fix: migration wrong directory (#3278)
Browse files Browse the repository at this point in the history
* fix: migration wrong directory

* reload model after migration

Signed-off-by: James <[email protected]>

---------

Signed-off-by: James <[email protected]>
  • Loading branch information
namchuai authored Aug 6, 2024
1 parent 44a6401 commit 7fb1354
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions electron/handlers/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ export function handleAppIPCs() {
const destinationFolderPath = join(configration.data_folder, 'models')

if (!existsSync(destinationFolderPath)) mkdirSync(destinationFolderPath)
console.log('destinationFolderPath', destinationFolderPath)

console.log(
`Syncing model from ${allModelFolders} to ${destinationFolderPath}`
)
const reflect = require('@alumna/reflect')

for (const modelName of allModelFolders) {
Expand Down Expand Up @@ -305,7 +308,6 @@ export function handleAppIPCs() {
src: modelFolderPath,
dest: destinationPath,
recursive: true,
exclude: ['model.json'],
delete: false,
overwrite: true,
errorOnExist: false,
Expand Down
2 changes: 1 addition & 1 deletion electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const host = '127.0.0.1'

app
.whenReady()
.then(setupCore)
.then(() => {
if (!gotTheLock) {
app.quit()
Expand Down Expand Up @@ -119,7 +120,6 @@ app
log.info(`stdout: ${stdout}`)
})
})
.then(setupCore)
.then(createUserSpace)
.then(migrate)
.then(setupMenu)
Expand Down
5 changes: 3 additions & 2 deletions electron/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { join } from 'path'
import { AppConfiguration } from '@janhq/core/node'
import os from 'os'


const configurationFileName = 'settings.json'

const defaultJanDataFolder = join(os.homedir(), 'jan')
Expand Down Expand Up @@ -60,6 +59,7 @@ export const getAppConfigurations = (): AppConfiguration => {
// Retrieve Application Support folder path
// Fallback to user home directory if not found
const configurationFile = getConfigurationFilePath()
console.debug('getAppConfiguration file path', configurationFile)

if (!existsSync(configurationFile)) {
// create default app config if we don't have one
Expand All @@ -74,6 +74,7 @@ export const getAppConfigurations = (): AppConfiguration => {
const appConfigurations: AppConfiguration = JSON.parse(
readFileSync(configurationFile, 'utf-8')
)
console.debug('app config', JSON.stringify(appConfigurations))
return appConfigurations
} catch (err) {
console.error(
Expand All @@ -86,7 +87,7 @@ export const getAppConfigurations = (): AppConfiguration => {
const getConfigurationFilePath = () =>
join(
global.core?.appPath() ||
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'],
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'],
configurationFileName
)

Expand Down
6 changes: 5 additions & 1 deletion web/containers/Providers/ModalMigrations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Spinner from '@/containers/Loader/Spinner'

import useMigratingData from '@/hooks/useMigratingData'

import useModels from '@/hooks/useModels'

import { didShowMigrationWarningAtom } from '@/helpers/atoms/AppConfig.atom'

export const showMigrationModalAtom = atom<boolean>(false)
Expand All @@ -29,6 +31,7 @@ const ModalMigrations = () => {
useState<MigrationState>('idle')
const [modelMigrationState, setModelMigrationState] =
useState<MigrationState>('idle')
const { getModels } = useModels()

const getStepTitle = () => {
switch (step) {
Expand Down Expand Up @@ -71,7 +74,8 @@ const ModalMigrations = () => {
setStep(2)
await migratingModels()
await migrationThreadsAndMessages()
}, [migratingModels, migrationThreadsAndMessages])
getModels()
}, [migratingModels, migrationThreadsAndMessages, getModels])

const onDismiss = useCallback(() => {
setStep(1)
Expand Down
7 changes: 5 additions & 2 deletions web/screens/Settings/Advanced/components/DataMigration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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-shrink-0 space-y-1">
<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>
<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>
</div>
<div className="flex flex-row gap-x-2">
Expand Down

0 comments on commit 7fb1354

Please sign in to comment.