mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
window-manager: better handling no-clusters state
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
684c1ed068
commit
012ef0419f
@ -5,6 +5,7 @@ import migrations from "../migrations/user-store"
|
|||||||
import { getAppVersion } from "./utils/app-version";
|
import { getAppVersion } from "./utils/app-version";
|
||||||
import { tracker } from "./tracker";
|
import { tracker } from "./tracker";
|
||||||
|
|
||||||
|
// todo: merge with common/user-store.ts
|
||||||
// fixme: detect new contexts from .kube/config since last open
|
// fixme: detect new contexts from .kube/config since last open
|
||||||
|
|
||||||
export interface UserStoreModel {
|
export interface UserStoreModel {
|
||||||
|
|||||||
@ -9,9 +9,10 @@ import logger from "./logger";
|
|||||||
|
|
||||||
export class WindowManager {
|
export class WindowManager {
|
||||||
protected activeView: BrowserWindow;
|
protected activeView: BrowserWindow;
|
||||||
|
protected splashWindow: BrowserWindow;
|
||||||
|
protected noClustersWindow: BrowserWindow;
|
||||||
protected views = new Map<ClusterId, BrowserWindow>();
|
protected views = new Map<ClusterId, BrowserWindow>();
|
||||||
protected disposers: CallableFunction[] = [];
|
protected disposers: CallableFunction[] = [];
|
||||||
protected splashWindow: BrowserWindow;
|
|
||||||
protected windowState: windowStateKeeper.State;
|
protected windowState: windowStateKeeper.State;
|
||||||
|
|
||||||
constructor(protected proxyPort: number) {
|
constructor(protected proxyPort: number) {
|
||||||
@ -34,7 +35,7 @@ export class WindowManager {
|
|||||||
// Manage reactive state
|
// Manage reactive state
|
||||||
this.disposers.push(
|
this.disposers.push(
|
||||||
// auto-show active cluster window and subscribe for push-events
|
// auto-show active cluster window and subscribe for push-events
|
||||||
reaction(() => clusterStore.activeClusterId, clusterId => this.activateView(clusterId), {
|
reaction(() => clusterStore.activeClusterId, this.activateView, {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
@ -43,26 +44,31 @@ export class WindowManager {
|
|||||||
removedClusters.forEach(cluster => {
|
removedClusters.forEach(cluster => {
|
||||||
this.destroyView(cluster.id);
|
this.destroyView(cluster.id);
|
||||||
});
|
});
|
||||||
|
}, {
|
||||||
|
delay: 25, // fix: destroy later and allow to use view's state in next activateView()
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// handle no-clusters view
|
// handle no-clusters view
|
||||||
autorun(() => {
|
autorun(() => {
|
||||||
if (!clusterStore.clusters.size) {
|
if (!clusterStore.hasClusters()) {
|
||||||
this.initNoClustersView();
|
this.handleNoClustersView();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async initNoClustersView() {
|
protected async handleNoClustersView() {
|
||||||
this.activeView = this.initView(undefined);
|
if (!this.noClustersWindow) {
|
||||||
await this.activeView.loadURL(`http://no-clusters.localhost:${this.proxyPort}`);
|
this.noClustersWindow = this.initView(undefined);
|
||||||
this.activeView.show();
|
await this.noClustersWindow.loadURL(`http://no-clusters.localhost:${this.proxyPort}`);
|
||||||
|
}
|
||||||
|
this.activeView = this.noClustersWindow;
|
||||||
|
this.noClustersWindow.show();
|
||||||
this.hideSplash();
|
this.hideSplash();
|
||||||
}
|
}
|
||||||
|
|
||||||
async showSplash() {
|
async showSplash() {
|
||||||
await this.splashWindow.loadURL("static://splash.html")
|
await this.splashWindow.loadURL("static://splash.html").catch(() => null)
|
||||||
this.splashWindow.show();
|
this.splashWindow.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +80,7 @@ export class WindowManager {
|
|||||||
return this.views.get(clusterId);
|
return this.views.get(clusterId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async activateView(clusterId: ClusterId): Promise<number> {
|
activateView = async (clusterId: ClusterId): Promise<number> => {
|
||||||
const cluster = clusterStore.getById(clusterId);
|
const cluster = clusterStore.getById(clusterId);
|
||||||
if (!cluster) {
|
if (!cluster) {
|
||||||
return;
|
return;
|
||||||
@ -90,8 +96,8 @@ export class WindowManager {
|
|||||||
isLoadedBefore: isLoadedBefore,
|
isLoadedBefore: isLoadedBefore,
|
||||||
});
|
});
|
||||||
if (prevActiveView !== view) {
|
if (prevActiveView !== view) {
|
||||||
cluster.activate(); // refresh + reconnect when required
|
|
||||||
this.activeView = view;
|
this.activeView = view;
|
||||||
|
cluster.activate(); // refresh + reconnect when required
|
||||||
if (!isLoadedBefore) {
|
if (!isLoadedBefore) {
|
||||||
await when(() => cluster.initialized);
|
await when(() => cluster.initialized);
|
||||||
await view.loadURL(cluster.webContentUrl);
|
await view.loadURL(cluster.webContentUrl);
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
margin: var(--flex-gap) 0;
|
margin: var(--flex-gap) 0;
|
||||||
|
|
||||||
&:empty {
|
&:empty {
|
||||||
display: none;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,6 @@ import { observable, when } from "mobx";
|
|||||||
import { autobind, interval } from "./utils";
|
import { autobind, interval } from "./utils";
|
||||||
import { apiBase } from "./api";
|
import { apiBase } from "./api";
|
||||||
|
|
||||||
// todo: remove, merge with common/user-store.ts
|
|
||||||
|
|
||||||
@autobind()
|
@autobind()
|
||||||
export class ConfigStore {
|
export class ConfigStore {
|
||||||
protected updater = interval(60, this.load);
|
protected updater = interval(60, this.load);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user