From 012ef0419f28b5a04285aed1fb16de2459da9018 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 21 Jul 2020 20:45:57 +0300 Subject: [PATCH] window-manager: better handling no-clusters state Signed-off-by: Roman --- src/common/user-store.ts | 1 + src/main/window-manager.ts | 28 +++++++++++-------- .../cluster-manager/clusters-menu.scss | 2 +- src/renderer/config.store.ts | 2 -- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/common/user-store.ts b/src/common/user-store.ts index 705cdae23f..40f41ff356 100644 --- a/src/common/user-store.ts +++ b/src/common/user-store.ts @@ -5,6 +5,7 @@ import migrations from "../migrations/user-store" import { getAppVersion } from "./utils/app-version"; import { tracker } from "./tracker"; +// todo: merge with common/user-store.ts // fixme: detect new contexts from .kube/config since last open export interface UserStoreModel { diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index d96599eb1a..de775747dd 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -9,9 +9,10 @@ import logger from "./logger"; export class WindowManager { protected activeView: BrowserWindow; + protected splashWindow: BrowserWindow; + protected noClustersWindow: BrowserWindow; protected views = new Map(); protected disposers: CallableFunction[] = []; - protected splashWindow: BrowserWindow; protected windowState: windowStateKeeper.State; constructor(protected proxyPort: number) { @@ -34,7 +35,7 @@ export class WindowManager { // Manage reactive state this.disposers.push( // auto-show active cluster window and subscribe for push-events - reaction(() => clusterStore.activeClusterId, clusterId => this.activateView(clusterId), { + reaction(() => clusterStore.activeClusterId, this.activateView, { fireImmediately: true, }), @@ -43,26 +44,31 @@ export class WindowManager { removedClusters.forEach(cluster => { this.destroyView(cluster.id); }); + }, { + delay: 25, // fix: destroy later and allow to use view's state in next activateView() }), // handle no-clusters view autorun(() => { - if (!clusterStore.clusters.size) { - this.initNoClustersView(); + if (!clusterStore.hasClusters()) { + this.handleNoClustersView(); } }) ); } - protected async initNoClustersView() { - this.activeView = this.initView(undefined); - await this.activeView.loadURL(`http://no-clusters.localhost:${this.proxyPort}`); - this.activeView.show(); + protected async handleNoClustersView() { + if (!this.noClustersWindow) { + this.noClustersWindow = this.initView(undefined); + await this.noClustersWindow.loadURL(`http://no-clusters.localhost:${this.proxyPort}`); + } + this.activeView = this.noClustersWindow; + this.noClustersWindow.show(); this.hideSplash(); } async showSplash() { - await this.splashWindow.loadURL("static://splash.html") + await this.splashWindow.loadURL("static://splash.html").catch(() => null) this.splashWindow.show(); } @@ -74,7 +80,7 @@ export class WindowManager { return this.views.get(clusterId); } - async activateView(clusterId: ClusterId): Promise { + activateView = async (clusterId: ClusterId): Promise => { const cluster = clusterStore.getById(clusterId); if (!cluster) { return; @@ -90,8 +96,8 @@ export class WindowManager { isLoadedBefore: isLoadedBefore, }); if (prevActiveView !== view) { - cluster.activate(); // refresh + reconnect when required this.activeView = view; + cluster.activate(); // refresh + reconnect when required if (!isLoadedBefore) { await when(() => cluster.initialized); await view.loadURL(cluster.webContentUrl); diff --git a/src/renderer/components/cluster-manager/clusters-menu.scss b/src/renderer/components/cluster-manager/clusters-menu.scss index 37a361d43e..8e1733a725 100644 --- a/src/renderer/components/cluster-manager/clusters-menu.scss +++ b/src/renderer/components/cluster-manager/clusters-menu.scss @@ -42,7 +42,7 @@ margin: var(--flex-gap) 0; &:empty { - display: none; + margin-bottom: 0; } } diff --git a/src/renderer/config.store.ts b/src/renderer/config.store.ts index ffc21c25d7..05d881dbf3 100755 --- a/src/renderer/config.store.ts +++ b/src/renderer/config.store.ts @@ -3,8 +3,6 @@ import { observable, when } from "mobx"; import { autobind, interval } from "./utils"; import { apiBase } from "./api"; -// todo: remove, merge with common/user-store.ts - @autobind() export class ConfigStore { protected updater = interval(60, this.load);