1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix not being able to install extensions sometimes

- Specifically, when there are remnants of a previous install of the
  extension which caused the code to be confused and enter the wrong
  branch

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-02-02 08:46:11 -05:00
parent 11c78414a0
commit 6c12b56bf0

View File

@ -12,7 +12,7 @@ import { Button } from "../../button";
import type { ExtensionLoader } from "../../../../extensions/extension-loader";
import type { LensExtensionId } from "../../../../extensions/lens-extension";
import React from "react";
import fse from "fs-extra";
import { remove as removeDir } from "fs-extra";
import { shell } from "electron";
import type { InstallRequestValidated } from "./create-temp-files-and-validate/create-temp-files-and-validate";
import type { InstallRequest } from "./install-request";
@ -80,17 +80,12 @@ export const attemptInstall =
}
const extensionFolder = getExtensionDestFolder(name);
const folderExists = await fse.pathExists(extensionFolder);
const installedExtensionsion = extensionLoader.getExtension(validatedRequest.id);
if (!folderExists) {
// install extension if not yet exists
await unpackExtension(validatedRequest, dispose);
} else {
const {
manifest: { version: oldVersion },
} = extensionLoader.getExtension(validatedRequest.id);
if (installedExtensionsion) {
const { version: oldVersion } = installedExtensionsion.manifest;
// otherwise confirmation required (re-install / update)
// confirm to uninstall old version before installing new version
const removeNotification = Notifications.info(
<div className="InstallingExtensionNotification flex gaps align-center">
<div className="flex column gaps">
@ -130,5 +125,11 @@ export const attemptInstall =
onClose: dispose,
},
);
} else {
// clean up old data if still around
await removeDir(extensionFolder);
// install extension if not yet exists
await unpackExtension(validatedRequest, dispose);
}
};