From 4087cf025e3c195ec5e527683c5c2c32cea3b98a Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 28 Jul 2020 11:42:57 +0300 Subject: [PATCH] fix: infinite spinner with no-clusters view Signed-off-by: Roman --- src/common/cluster-store.ts | 6 +++++- src/common/vars.ts | 3 +++ src/main/lens-proxy.ts | 4 ++-- src/main/window-manager.ts | 3 ++- src/renderer/components/cluster-manager/cluster-manager.tsx | 5 +++-- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/cluster-store.ts b/src/common/cluster-store.ts index d046e98b8b..9fc1da019a 100644 --- a/src/common/cluster-store.ts +++ b/src/common/cluster-store.ts @@ -4,7 +4,7 @@ import filenamify from "filenamify"; import { app, ipcRenderer } from "electron"; import { copyFile, ensureDir, unlink } from "fs-extra"; import { action, computed, observable, toJS } from "mobx"; -import { appProto } from "./vars"; +import { appProto, noClustersHost } from "./vars"; import { BaseStore } from "./base-store"; import { Cluster, ClusterState } from "../main/cluster"; import migrations from "../migrations/cluster-store" @@ -200,6 +200,10 @@ export class ClusterStore extends BaseStore { export const clusterStore = ClusterStore.getInstance(); +export function isNoClustersView() { + return location.hostname === noClustersHost +} + export function getHostedClusterId() { return location.hostname.split(".")[0]; } diff --git a/src/common/vars.ts b/src/common/vars.ts index 6ad061bf3a..871ef89416 100644 --- a/src/common/vars.ts +++ b/src/common/vars.ts @@ -22,6 +22,9 @@ export const rendererDir = path.join(contextDir, "src/renderer"); export const htmlTemplate = path.resolve(rendererDir, "template.html"); export const sassCommonVars = path.resolve(rendererDir, "components/vars.scss"); +// System pages +export const noClustersHost = "no-clusters.localhost" + // Apis export const apiPrefix = "/api" // local router apis export const apiKubePrefix = "/api-kube" // k8s cluster apis diff --git a/src/main/lens-proxy.ts b/src/main/lens-proxy.ts index 7951ad2162..42646a929e 100644 --- a/src/main/lens-proxy.ts +++ b/src/main/lens-proxy.ts @@ -7,7 +7,7 @@ import { openShell } from "./node-shell-session"; import { Router } from "./router" import { ClusterManager } from "./cluster-manager" import { ContextHandler } from "./context-handler"; -import { apiKubePrefix } from "../common/vars"; +import { apiKubePrefix, noClustersHost } from "../common/vars"; import logger from "./logger" export class LensProxy { @@ -117,7 +117,7 @@ export class LensProxy { } protected async handleRequest(proxy: httpProxy, req: http.IncomingMessage, res: http.ServerResponse) { - if (req.headers.host.split(":")[0] === "no-clusters.localhost") { + if (req.headers.host.split(":")[0] === noClustersHost) { this.router.handleStaticFile(req.url, res); return; } diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 8057602f48..03e71f8e09 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -3,6 +3,7 @@ import { BrowserWindow, shell } from "electron" import windowStateKeeper from "electron-window-state" import type { ClusterId } from "../common/cluster-store"; import { clusterStore } from "../common/cluster-store"; +import { noClustersHost } from "../common/vars"; import logger from "./logger"; export class WindowManager { @@ -53,7 +54,7 @@ export class WindowManager { protected handleNoClustersView = async ({ activate = false } = {}) => { if (!this.noClustersWindow) { this.noClustersWindow = this.initClusterView(null); - await this.noClustersWindow.loadURL(`http://no-clusters.localhost:${this.proxyPort}`); + await this.noClustersWindow.loadURL(`http://${noClustersHost}:${this.proxyPort}`); } if (activate) { this.activeView = this.noClustersWindow; diff --git a/src/renderer/components/cluster-manager/cluster-manager.tsx b/src/renderer/components/cluster-manager/cluster-manager.tsx index 0cd2a3070e..10eddb2e24 100644 --- a/src/renderer/components/cluster-manager/cluster-manager.tsx +++ b/src/renderer/components/cluster-manager/cluster-manager.tsx @@ -9,7 +9,7 @@ import { cssNames, IClassName } from "../../utils"; import { Terminal } from "../dock/terminal"; import { i18nStore } from "../../i18n"; import { themeStore } from "../../theme.store"; -import { clusterStore, getHostedClusterId } from "../../../common/cluster-store"; +import { clusterStore, getHostedClusterId, isNoClustersView } from "../../../common/cluster-store"; import { CubeSpinner } from "../spinner"; interface Props { @@ -30,7 +30,8 @@ export class ClusterManager extends React.Component { @computed get isInactive() { const { activeCluster, activeClusterId } = clusterStore; const isActivatedBefore = activeCluster?.initialized; - return !isActivatedBefore && activeClusterId !== getHostedClusterId(); + if (isNoClustersView() || isActivatedBefore) return; + return activeClusterId !== getHostedClusterId(); } render() {