refactor: deprecate the appVersion IPC and use the predefined VERSION from webpack (#1309)
## Description According to #1287, the web version will be updated accordingly. There is no need to use the electron app version anymore. It's to reduce the IPC dependency and reduce requests.
This commit is contained in:
parent
051dbcb937
commit
566a5a332f
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
export enum AppRoute {
|
export enum AppRoute {
|
||||||
appDataPath = 'appDataPath',
|
appDataPath = 'appDataPath',
|
||||||
appVersion = 'appVersion',
|
|
||||||
openExternalUrl = 'openExternalUrl',
|
openExternalUrl = 'openExternalUrl',
|
||||||
openAppDirectory = 'openAppDirectory',
|
openAppDirectory = 'openAppDirectory',
|
||||||
openFileExplore = 'openFileExplorer',
|
openFileExplore = 'openFileExplorer',
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export class ExtensionManager {
|
|||||||
|
|
||||||
const extensionsJson = join(extDir, "extensions.json");
|
const extensionsJson = join(extDir, "extensions.json");
|
||||||
if (!existsSync(extensionsJson))
|
if (!existsSync(extensionsJson))
|
||||||
writeFileSync(extensionsJson, "{}", "utf-8");
|
writeFileSync(extensionsJson, "{}");
|
||||||
|
|
||||||
this.extensionsPath = extDir;
|
this.extensionsPath = extDir;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -84,7 +84,6 @@ export function persistExtensions() {
|
|||||||
writeFileSync(
|
writeFileSync(
|
||||||
ExtensionManager.instance.getExtensionsFile(),
|
ExtensionManager.instance.getExtensionsFile(),
|
||||||
JSON.stringify(persistData),
|
JSON.stringify(persistData),
|
||||||
"utf-8"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,15 +7,6 @@ import { ExtensionManager, ModuleManager } from '@janhq/core/node'
|
|||||||
import { startServer, stopServer } from '@janhq/server'
|
import { startServer, stopServer } from '@janhq/server'
|
||||||
|
|
||||||
export function handleAppIPCs() {
|
export function handleAppIPCs() {
|
||||||
/**
|
|
||||||
* Returns the version of the app.
|
|
||||||
* @param _event - The IPC event object.
|
|
||||||
* @returns The version of the app.
|
|
||||||
*/
|
|
||||||
ipcMain.handle(AppRoute.appVersion, async (_event) => {
|
|
||||||
return app.getVersion()
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the "openAppDirectory" IPC message by opening the app's user data directory.
|
* Handles the "openAppDirectory" IPC message by opening the app's user data directory.
|
||||||
* The `shell.openPath` method is used to open the directory in the user's default file explorer.
|
* The `shell.openPath` method is used to open the directory in the user's default file explorer.
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import { MainViewState } from '@/constants/screens'
|
|||||||
import { useActiveModel } from '@/hooks/useActiveModel'
|
import { useActiveModel } from '@/hooks/useActiveModel'
|
||||||
|
|
||||||
import { useDownloadState } from '@/hooks/useDownloadState'
|
import { useDownloadState } from '@/hooks/useDownloadState'
|
||||||
import { useGetAppVersion } from '@/hooks/useGetAppVersion'
|
|
||||||
import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
|
import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
|
||||||
import useGetSystemResources from '@/hooks/useGetSystemResources'
|
import useGetSystemResources from '@/hooks/useGetSystemResources'
|
||||||
import { useMainViewState } from '@/hooks/useMainViewState'
|
import { useMainViewState } from '@/hooks/useMainViewState'
|
||||||
@ -24,7 +23,6 @@ const BottomBar = () => {
|
|||||||
const { activeModel, stateModel } = useActiveModel()
|
const { activeModel, stateModel } = useActiveModel()
|
||||||
const { ram, cpu } = useGetSystemResources()
|
const { ram, cpu } = useGetSystemResources()
|
||||||
const progress = useAtomValue(appDownloadProgress)
|
const progress = useAtomValue(appDownloadProgress)
|
||||||
const appVersion = useGetAppVersion()
|
|
||||||
const { downloadedModels } = useGetDownloadedModels()
|
const { downloadedModels } = useGetDownloadedModels()
|
||||||
const { setMainViewState } = useMainViewState()
|
const { setMainViewState } = useMainViewState()
|
||||||
const { downloadStates } = useDownloadState()
|
const { downloadStates } = useDownloadState()
|
||||||
@ -74,9 +72,8 @@ const BottomBar = () => {
|
|||||||
<div className="flex gap-x-2">
|
<div className="flex gap-x-2">
|
||||||
<SystemItem name="CPU:" value={`${cpu}%`} />
|
<SystemItem name="CPU:" value={`${cpu}%`} />
|
||||||
<SystemItem name="Mem:" value={`${ram}%`} />
|
<SystemItem name="Mem:" value={`${ram}%`} />
|
||||||
<span className="text-xs font-semibold ">
|
{/* VERSION is defined by webpack, please see next.config.js */}
|
||||||
Jan v{appVersion?.version ?? ''}
|
<span className="text-xs font-semibold ">Jan v{VERSION ?? ''}</span>
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,17 +0,0 @@
|
|||||||
import { useEffect, useState } from 'react'
|
|
||||||
|
|
||||||
export function useGetAppVersion() {
|
|
||||||
const [version, setVersion] = useState<string>('')
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getAppVersion()
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
const getAppVersion = () => {
|
|
||||||
window.core?.api?.appVersion().then((version: string | undefined) => {
|
|
||||||
setVersion(version ?? '')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return { version }
|
|
||||||
}
|
|
||||||
@ -7,8 +7,6 @@ import { Button } from '@janhq/uikit'
|
|||||||
|
|
||||||
import { FeatureToggleContext } from '@/context/FeatureToggle'
|
import { FeatureToggleContext } from '@/context/FeatureToggle'
|
||||||
|
|
||||||
import { useGetAppVersion } from '@/hooks/useGetAppVersion'
|
|
||||||
|
|
||||||
import { formatExtensionsName } from '@/utils/converter'
|
import { formatExtensionsName } from '@/utils/converter'
|
||||||
|
|
||||||
import { extensionManager } from '@/extension'
|
import { extensionManager } from '@/extension'
|
||||||
@ -17,7 +15,6 @@ const ExtensionCatalog = () => {
|
|||||||
const [activeExtensions, setActiveExtensions] = useState<any[]>([])
|
const [activeExtensions, setActiveExtensions] = useState<any[]>([])
|
||||||
const [extensionCatalog, setExtensionCatalog] = useState<any[]>([])
|
const [extensionCatalog, setExtensionCatalog] = useState<any[]>([])
|
||||||
const fileInputRef = useRef<HTMLInputElement | null>(null)
|
const fileInputRef = useRef<HTMLInputElement | null>(null)
|
||||||
const { version } = useGetAppVersion()
|
|
||||||
const { experimentalFeatureEnabed } = useContext(FeatureToggleContext)
|
const { experimentalFeatureEnabed } = useContext(FeatureToggleContext)
|
||||||
/**
|
/**
|
||||||
* Loads the extension catalog module from a CDN and sets it as the extension catalog state.
|
* Loads the extension catalog module from a CDN and sets it as the extension catalog state.
|
||||||
@ -26,7 +23,6 @@ const ExtensionCatalog = () => {
|
|||||||
if (!window.electronAPI) {
|
if (!window.electronAPI) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!version) return
|
|
||||||
|
|
||||||
// Get extension manifest
|
// Get extension manifest
|
||||||
import(/* webpackIgnore: true */ PLUGIN_CATALOG + `?t=${Date.now()}`).then(
|
import(/* webpackIgnore: true */ PLUGIN_CATALOG + `?t=${Date.now()}`).then(
|
||||||
@ -35,7 +31,7 @@ const ExtensionCatalog = () => {
|
|||||||
setExtensionCatalog(data.default)
|
setExtensionCatalog(data.default)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}, [experimentalFeatureEnabed, version])
|
}, [experimentalFeatureEnabed])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the active extensions and their preferences from the `extensions` and `preferences` modules.
|
* Fetches the active extensions and their preferences from the `extensions` and `preferences` modules.
|
||||||
|
|||||||
@ -13,11 +13,6 @@ export function openExternalUrl(url: string) {
|
|||||||
window?.open(url, '_blank')
|
window?.open(url, '_blank')
|
||||||
}
|
}
|
||||||
|
|
||||||
// Async function to get the application version
|
|
||||||
export async function appVersion() {
|
|
||||||
return Promise.resolve(VERSION)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Define API routes based on different route types
|
// Define API routes based on different route types
|
||||||
export const APIRoutes = [
|
export const APIRoutes = [
|
||||||
...Object.values(AppRoute).map((r) => ({ path: 'app', route: r })),
|
...Object.values(AppRoute).map((r) => ({ path: 'app', route: r })),
|
||||||
@ -55,5 +50,4 @@ export const restAPI = {
|
|||||||
}
|
}
|
||||||
}, {}),
|
}, {}),
|
||||||
openExternalUrl,
|
openExternalUrl,
|
||||||
appVersion,
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user