@@ -180,7 +184,7 @@ export const HomePage = () => {
{
plugin.updatable ?
-
+ installPlugin(plugin.name)} icon={} title="Update">
: } title={} onClick={() => uninstallPlugin(plugin.name)}/>
}
|
diff --git a/admin/src/store/store.ts b/admin/src/store/store.ts
index d662dfdf369f..d4cbe7786405 100644
--- a/admin/src/store/store.ts
+++ b/admin/src/store/store.ts
@@ -1,6 +1,7 @@
import {create} from "zustand";
import {Socket} from "socket.io-client";
import {PadSearchResult} from "../utils/PadSearch.ts";
+import {InstalledPlugin} from "../pages/Plugin.ts";
type ToastState = {
description?:string,
@@ -22,7 +23,9 @@ type StoreState = {
toastState: ToastState,
setToastState: (val: ToastState)=>void,
pads: PadSearchResult|undefined,
- setPads: (pads: PadSearchResult)=>void
+ setPads: (pads: PadSearchResult)=>void,
+ installedPlugins: InstalledPlugin[],
+ setInstalledPlugins: (plugins: InstalledPlugin[])=>void
}
@@ -43,5 +46,7 @@ export const useStore = create
()((set) => ({
success: false
},
pads: undefined,
- setPads: (pads)=>set({pads})
+ setPads: (pads)=>set({pads}),
+ installedPlugins: [],
+ setInstalledPlugins: (plugins)=>set({installedPlugins: plugins})
}));
diff --git a/src/node/hooks/express/adminplugins.ts b/src/node/hooks/express/adminplugins.ts
index b5049a6e1ef4..4dcb8a0abcb9 100644
--- a/src/node/hooks/express/adminplugins.ts
+++ b/src/node/hooks/express/adminplugins.ts
@@ -6,10 +6,10 @@ import {QueryType} from "../../types/QueryType";
import {getAvailablePlugins, install, search, uninstall} from "../../../static/js/pluginfw/installer";
import {PackageData} from "../../types/PackageInfo";
-
-const pluginDefs = require('../../../static/js/pluginfw/plugin_defs');
import semver from 'semver';
import log4js from 'log4js';
+
+const pluginDefs = require('../../../static/js/pluginfw/plugin_defs');
const logger = log4js.getLogger('adminPlugins');
@@ -20,10 +20,28 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
const {session: {user: {is_admin: isAdmin} = {}} = {}} = socket.conn.request;
if (!isAdmin) return;
- socket.on('getInstalled', (query:string) => {
+ const checkPluginForUpdates = async () => {
+ const results = await getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
+ return Object.keys(pluginDefs.plugins).filter((plugin) => {
+ if (!results[plugin]) return false;
+
+ const latestVersion = results[plugin].version;
+ const currentVersion = pluginDefs.plugins[plugin].package.version;
+
+ return semver.gt(latestVersion, currentVersion);
+ })
+ }
+
+ socket.on('getInstalled', async (query: string) => {
// send currently installed plugins
const installed =
- Object.keys(pluginDefs.plugins).map((plugin) => pluginDefs.plugins[plugin].package);
+ Object.keys(pluginDefs.plugins).map((plugin) => pluginDefs.plugins[plugin].package);
+
+ const updatable = await checkPluginForUpdates();
+
+ installed.forEach((plugin) => {
+ plugin.updatable = updatable.includes(plugin.name);
+ })
socket.emit('results:installed', {installed});
});
@@ -31,16 +49,7 @@ exports.socketio = (hookName:string, args:ArgsExpressType, cb:Function) => {
socket.on('checkUpdates', async () => {
// Check plugins for updates
try {
- const results = await getAvailablePlugins(/* maxCacheAge:*/ 60 * 10);
-
- const updatable = Object.keys(pluginDefs.plugins).filter((plugin) => {
- if (!results[plugin]) return false;
-
- const latestVersion = results[plugin].version;
- const currentVersion = pluginDefs.plugins[plugin].package.version;
-
- return semver.gt(latestVersion, currentVersion);
- });
+ const updatable = checkPluginForUpdates();
socket.emit('results:updatable', {updatable});
} catch (err) {