chore: plugin and app version dependency (#469)

This commit is contained in:
Louis 2023-10-26 16:51:42 +07:00 committed by GitHub
parent 81a9992610
commit 966ffa47aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -51,7 +51,7 @@ const BottomBar = () => {
<div className="flex gap-x-2">
<SystemItem name="CPU:" value={`${cpu}%`} />
<SystemItem name="Mem:" value={`${ram}%`} />
<p className="text-xs font-semibold">Jan {appVersion?.version ?? ''}</p>
<p className="text-xs font-semibold">Jan v{appVersion?.version ?? ''}</p>
</div>
</div>
)

View File

@ -11,6 +11,7 @@ import {
} from '@/../../electron/core/plugin-manager/execution/index'
import { executeSerial } from '@services/pluginService'
import { DataService } from '@janhq/core'
import useGetAppVersion from '@hooks/useGetAppVersion'
const PluginCatalog = () => {
// const [search, setSearch] = useState<string>('')
@ -20,23 +21,41 @@ const PluginCatalog = () => {
const [isLoading, setIsLoading] = useState<boolean>(false)
const experimentRef = useRef(null)
const fileInputRef = useRef<HTMLInputElement | null>(null)
const { version } = useGetAppVersion()
/**
* Loads the plugin catalog module from a CDN and sets it as the plugin catalog state.
*/
useEffect(() => {
if (!version) return
// Load plugin manifest from plugin if any
if (extensionPoints.get(DataService.GetPluginManifest)) {
executeSerial(DataService.GetPluginManifest).then((data) => {
setPluginCatalog(data)
setPluginCatalog(
data.filter(
(e: any) =>
!e.requiredVersion ||
e.requiredVersion.replace(/[.^]/g, '') <=
version.replaceAll('.', '')
)
)
})
} else {
// Fallback to app default manifest
import(
/* webpackIgnore: true */ PLUGIN_CATALOG + `?t=${Date.now()}`
).then((data) => setPluginCatalog(data.default))
).then((data) =>
setPluginCatalog(
data.default.filter(
(e: any) =>
!e.requiredVersion ||
e.requiredVersion.replace(/[.^]/g, '') <=
version.replaceAll('.', '')
)
)
)
}
}, [])
}, [version])
/**
* Fetches the active plugins and their preferences from the `plugins` and `preferences` modules.