mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
auto-refresh menu, no-clusters page + navigation fixes
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
1 parent
408f64c184
commit
fe06643a8e
13 files changed
+109
-90
No files matched your search
@@ -6,7 +6,7 @@ import { bundledKubectl, Kubectl } from "./kubectl"
|
||||
import logger from "./logger"
|
||||
|
||||
export interface KubeAuthProxyResponse {
|
||||
data: string; // stream=stdout
|
||||
data: string;
|
||||
error?: boolean; // stream=stderr
|
||||
}
|
||||
|
||||
|
||||
+30
-26
@@ -1,5 +1,6 @@
|
||||
import type { WindowManager } from "./window-manager";
|
||||
import { app, BrowserWindow, dialog, Menu, MenuItem, MenuItemConstructorOptions, shell, webContents } from "electron"
|
||||
import { autorun } from "mobx";
|
||||
import { broadcastIpc } from "../common/ipc";
|
||||
import { appName, isMac, issuesTrackerUrl, isWindows, slackUrl } from "../common/vars";
|
||||
import { clusterStore } from "../common/cluster-store";
|
||||
@@ -7,20 +8,26 @@ import { addClusterURL } from "../renderer/components/+add-cluster/add-cluster.r
|
||||
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
||||
import { whatsNewURL } from "../renderer/components/+whats-new/whats-new.route";
|
||||
import { clusterSettingsURL } from "../renderer/components/+cluster-settings/cluster-settings.route";
|
||||
import logger from "./logger";
|
||||
|
||||
export function initMenu(windowManager: WindowManager) {
|
||||
const menuItems: MenuItemConstructorOptions[] = [];
|
||||
autorun(() => {
|
||||
logger.debug(`[MENU]: refreshing menu, cluster=${clusterStore.activeClusterId}`);
|
||||
buildMenu(windowManager);
|
||||
});
|
||||
}
|
||||
|
||||
function buildMenu(windowManager: WindowManager) {
|
||||
const hasClusters = clusterStore.hasClusters();
|
||||
const activeClusterId = clusterStore.activeClusterId;
|
||||
const clusterView = windowManager.getClusterView(activeClusterId);
|
||||
|
||||
function navigate(url: string) {
|
||||
const activeClusterId = clusterStore.activeClusterId;
|
||||
const view = windowManager.getClusterView(activeClusterId);
|
||||
if (view) {
|
||||
broadcastIpc({
|
||||
channel: "menu:navigate",
|
||||
webContentId: view.id,
|
||||
args: [url],
|
||||
});
|
||||
}
|
||||
broadcastIpc({
|
||||
channel: "menu:navigate",
|
||||
webContentId: clusterView ? clusterView.id : undefined /*no-clusters*/,
|
||||
args: [url],
|
||||
});
|
||||
}
|
||||
|
||||
function macOnly(menuItems: MenuItemConstructorOptions[]): MenuItemConstructorOptions[] {
|
||||
@@ -28,8 +35,7 @@ export function initMenu(windowManager: WindowManager) {
|
||||
return menuItems;
|
||||
}
|
||||
|
||||
// "File" submenu
|
||||
menuItems.push({
|
||||
const fileMenu: MenuItemConstructorOptions = {
|
||||
label: isMac ? app.getName() : "File",
|
||||
submenu: [
|
||||
{
|
||||
@@ -38,12 +44,12 @@ export function initMenu(windowManager: WindowManager) {
|
||||
navigate(addClusterURL())
|
||||
}
|
||||
},
|
||||
{
|
||||
...(hasClusters ? [{
|
||||
label: 'Cluster Settings',
|
||||
click() {
|
||||
navigate(clusterSettingsURL())
|
||||
}
|
||||
},
|
||||
}] : []),
|
||||
{ type: 'separator' },
|
||||
{
|
||||
label: 'Preferences',
|
||||
@@ -62,10 +68,9 @@ export function initMenu(windowManager: WindowManager) {
|
||||
{ type: 'separator' },
|
||||
{ role: 'quit' }
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
// "Edit" submenu
|
||||
menuItems.push({
|
||||
const editMenu: MenuItemConstructorOptions = {
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{ role: 'undo' },
|
||||
@@ -78,10 +83,9 @@ export function initMenu(windowManager: WindowManager) {
|
||||
{ type: 'separator' },
|
||||
{ role: 'selectAll' },
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
// "View" submenu
|
||||
menuItems.push({
|
||||
const viewMenu: MenuItemConstructorOptions = {
|
||||
label: 'View',
|
||||
submenu: [
|
||||
{
|
||||
@@ -113,10 +117,9 @@ export function initMenu(windowManager: WindowManager) {
|
||||
{ type: 'separator' },
|
||||
{ role: 'togglefullscreen' }
|
||||
]
|
||||
})
|
||||
};
|
||||
|
||||
// "Help" submenu
|
||||
menuItems.push({
|
||||
const helpMenu: MenuItemConstructorOptions = {
|
||||
role: 'help',
|
||||
submenu: [
|
||||
{
|
||||
@@ -162,8 +165,9 @@ export function initMenu(windowManager: WindowManager) {
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
};
|
||||
|
||||
const menu = Menu.buildFromTemplate(menuItems);
|
||||
Menu.setApplicationMenu(menu);
|
||||
Menu.setApplicationMenu(Menu.buildFromTemplate([
|
||||
fileMenu, editMenu, viewMenu, helpMenu
|
||||
]));
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { autorun, reaction } from "mobx";
|
||||
import { reaction } from "mobx";
|
||||
import { BrowserWindow, shell } from "electron"
|
||||
import windowStateKeeper from "electron-window-state"
|
||||
import type { ClusterId } from "../common/cluster-store";
|
||||
@@ -29,8 +29,12 @@ export class WindowManager {
|
||||
|
||||
// Manage reactive state
|
||||
this.disposers.push(
|
||||
// show and hide "no-clusters" window when necessary
|
||||
autorun(this.handleNoClustersView),
|
||||
// auto-show/hide "no-clusters" window when necessary
|
||||
reaction(() => clusterStore.hasClusters(), hasClusters => {
|
||||
this.handleNoClustersView({ activate: !hasClusters });
|
||||
}, {
|
||||
fireImmediately: true
|
||||
}),
|
||||
|
||||
// auto-show active cluster window and subscribe for push-events
|
||||
reaction(() => clusterStore.activeClusterId, this.activateView, {
|
||||
@@ -48,10 +52,12 @@ export class WindowManager {
|
||||
);
|
||||
}
|
||||
|
||||
protected handleNoClustersView = async () => {
|
||||
this.noClustersWindow = this.initClusterView(null);
|
||||
await this.noClustersWindow.loadURL(`http://no-clusters.localhost:${this.proxyPort}`).catch(Function);
|
||||
if (!clusterStore.hasClusters()) {
|
||||
protected handleNoClustersView = async ({ activate = false } = {}) => {
|
||||
if (!this.noClustersWindow) {
|
||||
this.noClustersWindow = this.initClusterView(null);
|
||||
await this.noClustersWindow.loadURL(`http://no-clusters.localhost:${this.proxyPort}`);
|
||||
}
|
||||
if (activate) {
|
||||
this.activeView = this.noClustersWindow;
|
||||
this.noClustersWindow.show();
|
||||
this.hideSplash();
|
||||
@@ -69,8 +75,8 @@ export class WindowManager {
|
||||
resizable: false,
|
||||
show: false,
|
||||
});
|
||||
await this.splashWindow.loadURL("static://splash.html");
|
||||
}
|
||||
await this.splashWindow.loadURL("static://splash.html").catch(Function)
|
||||
this.splashWindow.show();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user