Merge pull request #3391 from janhq/fix/jan-should-have-access-to-it-resource-folders
fix: Jan should have access to it resource folders
This commit is contained in:
commit
3de7eda813
2
.gitignore
vendored
2
.gitignore
vendored
@ -39,3 +39,5 @@ extensions/*-extension/bin/vulkaninfo
|
|||||||
|
|
||||||
# Turborepo
|
# Turborepo
|
||||||
.turbo
|
.turbo
|
||||||
|
electron/test-data
|
||||||
|
electron/test-results
|
||||||
|
|||||||
@ -77,8 +77,8 @@ export class App implements Processor {
|
|||||||
port: args?.port,
|
port: args?.port,
|
||||||
isCorsEnabled: args?.isCorsEnabled,
|
isCorsEnabled: args?.isCorsEnabled,
|
||||||
isVerboseEnabled: args?.isVerboseEnabled,
|
isVerboseEnabled: args?.isVerboseEnabled,
|
||||||
schemaPath: join(await appResourcePath(), 'docs', 'openapi', 'jan.yaml'),
|
schemaPath: join(appResourcePath(), 'docs', 'openapi', 'jan.yaml'),
|
||||||
baseDir: join(await appResourcePath(), 'docs', 'openapi'),
|
baseDir: join(appResourcePath(), 'docs', 'openapi'),
|
||||||
prefix: args?.prefix,
|
prefix: args?.prefix,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ export class Extension implements Processor {
|
|||||||
* @returns An array of paths to the base extensions.
|
* @returns An array of paths to the base extensions.
|
||||||
*/
|
*/
|
||||||
async baseExtensions() {
|
async baseExtensions() {
|
||||||
const baseExtensionPath = join(await appResourcePath(), 'pre-install')
|
const baseExtensionPath = join(appResourcePath(), 'pre-install')
|
||||||
return readdirSync(baseExtensionPath)
|
return readdirSync(baseExtensionPath)
|
||||||
.filter((file) => extname(file) === '.tgz')
|
.filter((file) => extname(file) === '.tgz')
|
||||||
.map((file) => join(baseExtensionPath, file))
|
.map((file) => join(baseExtensionPath, file))
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { AppConfiguration, SettingComponentProps } from '../../types'
|
import { AppConfiguration, SettingComponentProps } from '../../types'
|
||||||
import { join } from 'path'
|
import { join, resolve } from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import childProcess from 'child_process'
|
import childProcess from 'child_process'
|
||||||
@ -10,7 +10,10 @@ const configurationFileName = 'settings.json'
|
|||||||
// TODO: do not default the os.homedir
|
// TODO: do not default the os.homedir
|
||||||
const defaultJanDataFolder = join(os?.homedir() || '', 'jan')
|
const defaultJanDataFolder = join(os?.homedir() || '', 'jan')
|
||||||
const defaultAppConfig: AppConfiguration = {
|
const defaultAppConfig: AppConfiguration = {
|
||||||
data_folder: defaultJanDataFolder,
|
data_folder:
|
||||||
|
process.env.CI === 'e2e'
|
||||||
|
? process.env.APP_CONFIG_PATH ?? resolve('./test-data')
|
||||||
|
: defaultJanDataFolder,
|
||||||
quick_ask: false,
|
quick_ask: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +23,7 @@ const defaultAppConfig: AppConfiguration = {
|
|||||||
* @returns {AppConfiguration} The app configurations.
|
* @returns {AppConfiguration} The app configurations.
|
||||||
*/
|
*/
|
||||||
export const getAppConfigurations = (): AppConfiguration => {
|
export const getAppConfigurations = (): AppConfiguration => {
|
||||||
|
if (process.env.CI === 'e2e') return defaultAppConfig
|
||||||
// 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()
|
||||||
|
|||||||
@ -11,16 +11,13 @@ export function normalizeFilePath(path: string): string {
|
|||||||
return path.replace(/^(file:[\\/]+)([^:\s]+)$/, '$2')
|
return path.replace(/^(file:[\\/]+)([^:\s]+)$/, '$2')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function appResourcePath(): Promise<string> {
|
/**
|
||||||
let electron: any = undefined
|
* App resources path
|
||||||
|
* Returns string - The current application directory.
|
||||||
|
*/
|
||||||
|
export function appResourcePath() {
|
||||||
try {
|
try {
|
||||||
const moduleName = 'electron'
|
const electron = require('electron')
|
||||||
electron = await import(moduleName)
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Electron is not available')
|
|
||||||
}
|
|
||||||
|
|
||||||
// electron
|
// electron
|
||||||
if (electron && electron.protocol) {
|
if (electron && electron.protocol) {
|
||||||
let appPath = join(electron.app.getAppPath(), '..', 'app.asar.unpacked')
|
let appPath = join(electron.app.getAppPath(), '..', 'app.asar.unpacked')
|
||||||
@ -31,14 +28,24 @@ export async function appResourcePath(): Promise<string> {
|
|||||||
}
|
}
|
||||||
return appPath
|
return appPath
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Electron is not available')
|
||||||
|
}
|
||||||
|
|
||||||
// server
|
// server
|
||||||
return join(global.core.appPath(), '../../..')
|
return join(global.core.appPath(), '../../..')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validatePath(path: string) {
|
export function validatePath(path: string) {
|
||||||
const janDataFolderPath = getJanDataFolderPath()
|
const appDataFolderPath = getJanDataFolderPath()
|
||||||
|
const resourcePath = appResourcePath()
|
||||||
|
const applicationSupportPath = global.core?.appPath() ?? resourcePath
|
||||||
const absolutePath = resolve(__dirname, path)
|
const absolutePath = resolve(__dirname, path)
|
||||||
if (!absolutePath.startsWith(janDataFolderPath)) {
|
if (
|
||||||
|
![appDataFolderPath, resourcePath, applicationSupportPath].some((whiteListedPath) =>
|
||||||
|
absolutePath.startsWith(whiteListedPath)
|
||||||
|
)
|
||||||
|
) {
|
||||||
throw new Error(`Invalid path: ${absolutePath}`)
|
throw new Error(`Invalid path: ${absolutePath}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,11 +11,7 @@ import {
|
|||||||
lstatSync,
|
lstatSync,
|
||||||
} from 'fs'
|
} from 'fs'
|
||||||
import Store from 'electron-store'
|
import Store from 'electron-store'
|
||||||
import {
|
import { getJanDataFolderPath, appResourcePath } from '@janhq/core/node'
|
||||||
getJanExtensionsPath,
|
|
||||||
getJanDataFolderPath,
|
|
||||||
appResourcePath,
|
|
||||||
} from '@janhq/core/node'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrates the extensions & themes.
|
* Migrates the extensions & themes.
|
||||||
@ -43,9 +39,9 @@ async function migrateThemes() {
|
|||||||
if (!existsSync(join(getJanDataFolderPath(), 'themes')))
|
if (!existsSync(join(getJanDataFolderPath(), 'themes')))
|
||||||
mkdirSync(join(getJanDataFolderPath(), 'themes'), { recursive: true })
|
mkdirSync(join(getJanDataFolderPath(), 'themes'), { recursive: true })
|
||||||
|
|
||||||
const themes = readdirSync(join(await appResourcePath(), 'themes'))
|
const themes = readdirSync(join(appResourcePath(), 'themes'))
|
||||||
for (const theme of themes) {
|
for (const theme of themes) {
|
||||||
const themePath = join(await appResourcePath(), 'themes', theme)
|
const themePath = join(appResourcePath(), 'themes', theme)
|
||||||
if (existsSync(themePath) && !lstatSync(themePath).isDirectory()) {
|
if (existsSync(themePath) && !lstatSync(themePath).isDirectory()) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import { PropsWithChildren } from 'react'
|
|||||||
|
|
||||||
import { Metadata } from 'next'
|
import { Metadata } from 'next'
|
||||||
|
|
||||||
import 'katex/dist/katex.min.css'
|
|
||||||
import '@/styles/main.scss'
|
import '@/styles/main.scss'
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
|
|||||||
@ -5,6 +5,7 @@
|
|||||||
@import 'tailwindcss/utilities';
|
@import 'tailwindcss/utilities';
|
||||||
|
|
||||||
@import '@janhq/joi/dist/main.css';
|
@import '@janhq/joi/dist/main.css';
|
||||||
|
@import 'katex/dist/katex.min.css';
|
||||||
|
|
||||||
@import './base/global.scss';
|
@import './base/global.scss';
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user