mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Update extension after ipc event
Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
parent
56d438878c
commit
578a6cec21
@ -2,4 +2,6 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
export const BundledExtensionsLoaded = "extension-loader:bundled-extensions-loaded";
|
||||
export const BundledExtensionsUpdated = "extension-loader:bundled-extensions-updated";
|
||||
export const UpdateBundledExtension = "extension-loader:update-bundled-extension";
|
||||
|
||||
@ -29,7 +29,7 @@ export class BundledVersionChecker implements LensExtensionLatestVersionChecker
|
||||
const json = await this.getJson(`${extensionUpdateUrl}/versions.json`);
|
||||
|
||||
if (!json || json.error || !json[manifest.name]) {
|
||||
logger.info(`[BUNDLED-EXTENSIONS-UPDATER]: No version found for ${manifest.name}.`);
|
||||
logger.info(`[EXTENSION-VERSION-CHECKER]: No version found for ${manifest.name}.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ import { EventEmitter } from "events";
|
||||
import { isEqual } from "lodash";
|
||||
import { action, computed, makeObservable, observable, observe, reaction, when } from "mobx";
|
||||
import path from "path";
|
||||
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle } from "../../common/ipc";
|
||||
import { broadcastMessage, ipcMainOn, ipcRendererOn, requestMain, ipcMainHandle, UpdateBundledExtension } from "../../common/ipc";
|
||||
import { Disposer, toJS } from "../../common/utils";
|
||||
import logger from "../../main/logger";
|
||||
import type { KubernetesCluster } from "../common-api/catalog";
|
||||
@ -288,7 +288,9 @@ export class ExtensionLoader {
|
||||
}
|
||||
});
|
||||
|
||||
this.checkForExtensionUpdate(extension);
|
||||
this.checkForExtensionUpdate(extension).then(() => {
|
||||
broadcastMessage(UpdateBundledExtension, extension.id)
|
||||
});
|
||||
|
||||
return removeItems;
|
||||
});
|
||||
|
||||
@ -3,14 +3,14 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { BundledExtensionsUpdated } from "../../../../common/ipc";
|
||||
import { UpdateBundledExtension } from "../../../../common/ipc";
|
||||
import { logger } from "../../../../extensions/common-api";
|
||||
import type { InstalledExtension } from "../../../../extensions/extension-discovery/extension-discovery";
|
||||
import { ExtensionUpdater, UpdaterDependencies } from "./extension-updater";
|
||||
|
||||
interface Dependencies extends UpdaterDependencies {
|
||||
extensions: InstalledExtension[];
|
||||
ipcRenderer: { send: (name: string) => void };
|
||||
ipcRenderer: { send: (name: string) => void, on: (channel: string, listener: (event: Electron.IpcRendererEvent, ...args: any[]) => any) => void };
|
||||
}
|
||||
|
||||
export class BundledExtensionsUpdater extends ExtensionUpdater {
|
||||
@ -18,16 +18,17 @@ export class BundledExtensionsUpdater extends ExtensionUpdater {
|
||||
super(dependencies);
|
||||
}
|
||||
|
||||
async updateAll() {
|
||||
logger.info("[EXTENSIONS-UPDATER]: Bundled extensions update started.");
|
||||
init() {
|
||||
this.dependencies.ipcRenderer.on(UpdateBundledExtension, async (event, extensionId: string) => {
|
||||
const extension = this.dependencies.extensions.find(extension => extension.id == extensionId);
|
||||
|
||||
const updates = this.dependencies.extensions.map(this.update);
|
||||
try {
|
||||
await Promise.allSettled(updates);
|
||||
} finally {
|
||||
this.dependencies.ipcRenderer.send(BundledExtensionsUpdated);
|
||||
}
|
||||
|
||||
logger.info("[EXTENSIONS-UPDATER]: Bundled extensions update finished.");
|
||||
if (extension?.isBundled && extension?.availableUpdate) {
|
||||
try {
|
||||
await this.update(extension);
|
||||
} catch (err) {
|
||||
logger.error(`Update failed for ${extension.manifest.name}`)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,7 @@ export class ExtensionUpdater {
|
||||
// TODO: actual install
|
||||
// this.dependencies.installFromInput(availableUpdate.input);
|
||||
}
|
||||
reject();
|
||||
reject("Update failed");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user