mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix some edge cases
- Clear the loading state in more places - Add loading animation when an extension is discovered by main Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
ab130b586e
commit
ad9767a4c6
5 files changed
+100
-74
No files matched your search
@@ -19,6 +19,7 @@ import { filesystemProvisionerStore } from "../main/extension-filesystem";
|
||||
import { App } from "./components/app";
|
||||
import { LensApp } from "./lens-app";
|
||||
import { themeStore } from "./theme.store";
|
||||
import { ExtensionInstallationStateStore } from "./components/+extensions/extension-install.store";
|
||||
|
||||
/**
|
||||
* If this is a development buid, wait a second to attach
|
||||
@@ -50,6 +51,7 @@ export async function bootstrap(App: AppComponent) {
|
||||
await attachChromeDebugger();
|
||||
rootElem.classList.toggle("is-mac", isMac);
|
||||
|
||||
ExtensionInstallationStateStore.bindIpcListeners();
|
||||
extensionLoader.init();
|
||||
extensionDiscovery.init();
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import { action, computed, observable } from "mobx";
|
||||
import logger from "../../../main/logger";
|
||||
import { disposer, Disposer } from "../../utils";
|
||||
import * as uuid from "uuid";
|
||||
import { broadcastMessage } from "../../../common/ipc";
|
||||
import { ipcRenderer } from "electron";
|
||||
|
||||
export enum ExtensionInstallationState {
|
||||
INSTALLING = "installing",
|
||||
@@ -15,6 +17,19 @@ const uninstallingExtensions = observable.set<string>();
|
||||
const preInstallIds = observable.set<string>();
|
||||
|
||||
export class ExtensionInstallationStateStore {
|
||||
private static InstallingFromMainChannel = "extension-installation-state-store:install";
|
||||
private static ClearInstallingFromMainChannel = "extension-installation-state-store:clear-install";
|
||||
|
||||
static bindIpcListeners() {
|
||||
ipcRenderer
|
||||
.on(ExtensionInstallationStateStore.InstallingFromMainChannel, (event, extId) => {
|
||||
ExtensionInstallationStateStore.setInstalling(extId);
|
||||
})
|
||||
.on(ExtensionInstallationStateStore.ClearInstallingFromMainChannel, (event, extId) => {
|
||||
ExtensionInstallationStateStore.clearInstalling(extId);
|
||||
});
|
||||
}
|
||||
|
||||
@action static reset() {
|
||||
logger.warn(`${Prefix}: resetting, may throw errors`);
|
||||
installingExtensions.clear();
|
||||
@@ -39,6 +54,22 @@ export class ExtensionInstallationStateStore {
|
||||
installingExtensions.add(extId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts that an extension is being installed by the main process
|
||||
* @param extId the ID of the extension
|
||||
*/
|
||||
static setInstallingFromMain(extId: string): void {
|
||||
broadcastMessage(ExtensionInstallationStateStore.InstallingFromMainChannel, extId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts that an extension is no longer being installed by the main process
|
||||
* @param extId the ID of the extension
|
||||
*/
|
||||
static clearInstallingFromMain(extId: string): void {
|
||||
broadcastMessage(ExtensionInstallationStateStore.ClearInstallingFromMainChannel, extId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the start of a pre-install phase of an extension installation. The
|
||||
* part of the installation before the tarball has been unpacked and the ID
|
||||
@@ -165,7 +196,7 @@ export class ExtensionInstallationStateStore {
|
||||
}
|
||||
|
||||
/**
|
||||
* The current number of extensions preinstallig
|
||||
* The current number of extensions preinstalling
|
||||
*/
|
||||
@computed static get preinstalling(): number {
|
||||
return preInstallIds.size;
|
||||
|
||||
@@ -59,7 +59,7 @@ async function uninstallExtension(extensionId: LensExtensionId, manifest: LensEx
|
||||
return true;
|
||||
} catch (error) {
|
||||
Notifications.error(
|
||||
<p>Uninstalling extension <b>{displayName}</b> has failed: <em>{error?.message ?? ""}</em></p>
|
||||
<p>Uninstalling extension <b>{displayName}</b> has failed: <em>{error?.message ?? error?.toString() ?? ""}</em></p>
|
||||
);
|
||||
|
||||
return false;
|
||||
@@ -174,7 +174,7 @@ async function createTempFilesAndValidate(request: InstallRequestPreloaded, { sh
|
||||
return null;
|
||||
}
|
||||
|
||||
async function unpackExtension(request: InstallRequestValidated, disposeDownloading: Disposer) {
|
||||
async function unpackExtension(request: InstallRequestValidated, disposeDownloading?: Disposer) {
|
||||
const { id, fileName, tempFile, manifest: { name, version } } = request;
|
||||
|
||||
ExtensionInstallationStateStore.setInstalling(id);
|
||||
@@ -238,13 +238,13 @@ async function requestInstall(request: InstallRequest, d?: Disposer): Promise<vo
|
||||
const loadedRequest = await preloadExtension(request);
|
||||
|
||||
if (!loadedRequest) {
|
||||
return;
|
||||
return dispose();
|
||||
}
|
||||
|
||||
const validatedRequest = await createTempFilesAndValidate(loadedRequest);
|
||||
|
||||
if (!validatedRequest) {
|
||||
return;
|
||||
return dispose();
|
||||
}
|
||||
|
||||
const { name, version, description } = validatedRequest.manifest;
|
||||
@@ -282,10 +282,18 @@ async function requestInstall(request: InstallRequest, d?: Disposer): Promise<vo
|
||||
<Button autoFocus label="Install" onClick={async () => {
|
||||
removeNotification();
|
||||
|
||||
await uninstallExtension(validatedRequest.id, validatedRequest.manifest)
|
||||
&& await unpackExtension(validatedRequest, dispose);
|
||||
if (await uninstallExtension(validatedRequest.id, validatedRequest.manifest)) {
|
||||
await unpackExtension(validatedRequest, dispose);
|
||||
} else {
|
||||
disposer();
|
||||
}
|
||||
}} />
|
||||
</div>
|
||||
</div>,
|
||||
{
|
||||
onClose() {
|
||||
disposer();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -456,10 +464,6 @@ export class Extensions extends React.Component {
|
||||
return (
|
||||
<>
|
||||
{...searchedForExtensions.map(this.renderExtension)}
|
||||
{
|
||||
ExtensionInstallationStateStore.anyPreInstallingOrInstalling
|
||||
&& <div className="spinner-wrapper"><Spinner /></div>
|
||||
}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -505,6 +509,7 @@ export class Extensions extends React.Component {
|
||||
primary
|
||||
label="Install"
|
||||
disabled={ExtensionInstallationStateStore.anyPreInstallingOrInstalling || !Extensions.installPathValidator.validate(installPath)}
|
||||
waiting={ExtensionInstallationStateStore.anyPreInstallingOrInstalling}
|
||||
onClick={() => installFromUrlOrPath(this.installPath)}
|
||||
/>
|
||||
<small className="hint">
|
||||
|
||||
Reference in new issue
Block a user