Skip to content

Commit

Permalink
refactor: deprecate the appVersion IPC and use the predefined VERSION…
Browse files Browse the repository at this point in the history
… from webpack (janhq#1309)

## Description
According to janhq#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.
  • Loading branch information
louis-jan authored Jan 4, 2024
1 parent 051dbcb commit 566a5a3
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 45 deletions.
1 change: 0 additions & 1 deletion core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
export enum AppRoute {
appDataPath = 'appDataPath',
appVersion = 'appVersion',
openExternalUrl = 'openExternalUrl',
openAppDirectory = 'openAppDirectory',
openFileExplore = 'openFileExplorer',
Expand Down
2 changes: 1 addition & 1 deletion core/src/node/extension/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion core/src/node/extension/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export function persistExtensions() {
writeFileSync(
ExtensionManager.instance.getExtensionsFile(),
JSON.stringify(persistData),
"utf-8"
);
}

Expand Down
9 changes: 0 additions & 9 deletions electron/handlers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 2 additions & 5 deletions web/containers/Layout/BottomBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand Down Expand Up @@ -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>
)
Expand Down
17 changes: 0 additions & 17 deletions web/hooks/useGetAppVersion.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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.
Expand All @@ -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(
Expand All @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions web/services/restService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })),
Expand Down Expand Up @@ -55,5 +50,4 @@ export const restAPI = {
}
}, {}),
openExternalUrl,
appVersion,
}

0 comments on commit 566a5a3

Please sign in to comment.