Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update legacy path #3328

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions electron/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { join } from 'path'
import { AppConfiguration } from '@janhq/core/node'
import os from 'os'
import { dump, load } from 'js-yaml'
import { app } from 'electron'

const configurationFileName = '.janrc'

Expand All @@ -15,7 +16,7 @@ const defaultAppConfig: AppConfiguration = {
cortexCppHost: '127.0.0.1',
cortexCppPort: 3940,
apiServerHost: '127.0.0.1',
apiServerPort: 1338
apiServerPort: 1338,
}

export async function createUserSpace(): Promise<void> {
Expand Down Expand Up @@ -90,11 +91,8 @@ export const getAppConfigurations = (): AppConfiguration => {

// Get configuration file path of the application
const getConfigurationFilePath = () => {
const homeDir = os.homedir();
const configPath = join(
homeDir,
configurationFileName,
);
const homeDir = os.homedir()
const configPath = join(homeDir, configurationFileName)
return configPath
}

Expand All @@ -117,21 +115,23 @@ export const updateAppConfiguration = (
* @returns {string} The data folder path.
*/
export const getJanDataFolderPath = (): string => {
return getAppConfigurations().dataFolderPath
return getAppConfigurations().dataFolderPath
}

// This is to support pulling legacy configs for migration purpose
export const legacyConfigs = () => {
const legacyConfigFilePath = join(
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME'] ?? '',
'settings.json'
)
const legacyConfigs = JSON.parse(readFileSync(legacyConfigFilePath, 'utf-8')) as any
const legacyConfigFilePath = join(app.getPath('userData'), 'settings.json')

const legacyConfigs = JSON.parse(
readFileSync(legacyConfigFilePath, 'utf-8')
) as any

console.debug('legacyConfigs', legacyConfigs)

return legacyConfigs
}

// This is to support pulling legacy data path for migration purpose
export const legacyDataPath = () => {
return legacyConfigs().data_path
return legacyConfigs().data_folder
}
Loading