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:
Louis 2024-01-04 11:22:24 +07:00 committed by GitHub
parent 051dbcb937
commit 566a5a332f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 4 additions and 45 deletions

View File

@ -4,7 +4,6 @@
*/
export enum AppRoute {
appDataPath = 'appDataPath',
appVersion = 'appVersion',
openExternalUrl = 'openExternalUrl',
openAppDirectory = 'openAppDirectory',
openFileExplore = 'openFileExplorer',

View File

@ -47,7 +47,7 @@ export class ExtensionManager {
const extensionsJson = join(extDir, "extensions.json");
if (!existsSync(extensionsJson))
writeFileSync(extensionsJson, "{}", "utf-8");
writeFileSync(extensionsJson, "{}");
this.extensionsPath = extDir;
} catch (error) {

View File

@ -84,7 +84,6 @@ export function persistExtensions() {
writeFileSync(
ExtensionManager.instance.getExtensionsFile(),
JSON.stringify(persistData),
"utf-8"
);
}

View File

@ -7,15 +7,6 @@ import { ExtensionManager, ModuleManager } from '@janhq/core/node'
import { startServer, stopServer } from '@janhq/server'
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.
* The `shell.openPath` method is used to open the directory in the user's default file explorer.

View File

@ -15,7 +15,6 @@ import { MainViewState } from '@/constants/screens'
import { useActiveModel } from '@/hooks/useActiveModel'
import { useDownloadState } from '@/hooks/useDownloadState'
import { useGetAppVersion } from '@/hooks/useGetAppVersion'
import { useGetDownloadedModels } from '@/hooks/useGetDownloadedModels'
import useGetSystemResources from '@/hooks/useGetSystemResources'
import { useMainViewState } from '@/hooks/useMainViewState'
@ -24,7 +23,6 @@ const BottomBar = () => {
const { activeModel, stateModel } = useActiveModel()
const { ram, cpu } = useGetSystemResources()
const progress = useAtomValue(appDownloadProgress)
const appVersion = useGetAppVersion()
const { downloadedModels } = useGetDownloadedModels()
const { setMainViewState } = useMainViewState()
const { downloadStates } = useDownloadState()
@ -74,9 +72,8 @@ const BottomBar = () => {
<div className="flex gap-x-2">
<SystemItem name="CPU:" value={`${cpu}%`} />
<SystemItem name="Mem:" value={`${ram}%`} />
<span className="text-xs font-semibold ">
Jan v{appVersion?.version ?? ''}
</span>
{/* VERSION is defined by webpack, please see next.config.js */}
<span className="text-xs font-semibold ">Jan v{VERSION ?? ''}</span>
</div>
</div>
)

View File

@ -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 }
}

View File

@ -7,8 +7,6 @@ import { Button } from '@janhq/uikit'
import { FeatureToggleContext } from '@/context/FeatureToggle'
import { useGetAppVersion } from '@/hooks/useGetAppVersion'
import { formatExtensionsName } from '@/utils/converter'
import { extensionManager } from '@/extension'
@ -17,7 +15,6 @@ const ExtensionCatalog = () => {
const [activeExtensions, setActiveExtensions] = useState<any[]>([])
const [extensionCatalog, setExtensionCatalog] = useState<any[]>([])
const fileInputRef = useRef<HTMLInputElement | null>(null)
const { version } = useGetAppVersion()
const { experimentalFeatureEnabed } = useContext(FeatureToggleContext)
/**
* 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) {
return
}
if (!version) return
// Get extension manifest
import(/* webpackIgnore: true */ PLUGIN_CATALOG + `?t=${Date.now()}`).then(
@ -35,7 +31,7 @@ const ExtensionCatalog = () => {
setExtensionCatalog(data.default)
}
)
}, [experimentalFeatureEnabed, version])
}, [experimentalFeatureEnabed])
/**
* Fetches the active extensions and their preferences from the `extensions` and `preferences` modules.

View File

@ -13,11 +13,6 @@ export function openExternalUrl(url: string) {
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
export const APIRoutes = [
...Object.values(AppRoute).map((r) => ({ path: 'app', route: r })),
@ -55,5 +50,4 @@ export const restAPI = {
}
}, {}),
openExternalUrl,
appVersion,
}