From 5788c443035679b876e6c59a2ba22324063ae052 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Wed, 2 Sep 2020 10:05:49 +0300 Subject: [PATCH] Reload active dashboard view (#783) Signed-off-by: Alex Andreev --- src/common/cluster-ipc.ts | 1 + src/main/menu.ts | 4 ++-- src/main/window-manager.ts | 13 +++++++++++-- .../cluster-manager/cluster-view.route.ts | 7 ++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/common/cluster-ipc.ts b/src/common/cluster-ipc.ts index e3024a69b0..e8f681cd7f 100644 --- a/src/common/cluster-ipc.ts +++ b/src/common/cluster-ipc.ts @@ -13,6 +13,7 @@ export const clusterIpc = { } }, }), + activate: createIpcChannel({ channel: "cluster:activate", handle: (clusterId: ClusterId) => { diff --git a/src/main/menu.ts b/src/main/menu.ts index f319b5a479..121967b6a4 100644 --- a/src/main/menu.ts +++ b/src/main/menu.ts @@ -155,14 +155,14 @@ export function buildMenu(windowManager: WindowManager) { label: 'Forward', accelerator: 'CmdOrCtrl+]', click() { - webContents.getFocusedWebContents()?.goForward(); + webContents.getFocusedWebContents()?.goForward() } }, { label: 'Reload', accelerator: 'CmdOrCtrl+R', click() { - webContents.getFocusedWebContents()?.reload(); + windowManager.reload({ channel: "menu:reload" }); } }, { role: 'toggleDevTools' }, diff --git a/src/main/window-manager.ts b/src/main/window-manager.ts index 166f512b70..99bb9da052 100644 --- a/src/main/window-manager.ts +++ b/src/main/window-manager.ts @@ -1,5 +1,5 @@ -import type { ClusterId } from "../common/cluster-store"; -import { BrowserWindow, dialog, ipcMain, shell, WebContents, webContents } from "electron" +import { ClusterId, clusterStore } from "../common/cluster-store"; +import { BrowserWindow, dialog, ipcMain, shell, webContents } from "electron" import windowStateKeeper from "electron-window-state" import { observable } from "mobx"; import { initMenu } from "./menu"; @@ -58,6 +58,15 @@ export class WindowManager { } } + reload({ channel }: { channel: string }) { + const frameId = clusterStore.getById(this.activeClusterId)?.frameId; + if (frameId) { + this.mainView.webContents.sendToFrame(frameId, channel); + } else { + webContents.getFocusedWebContents()?.reload(); + } + } + async showMain() { try { await this.showSplash(); diff --git a/src/renderer/components/cluster-manager/cluster-view.route.ts b/src/renderer/components/cluster-manager/cluster-view.route.ts index dae8f83323..d2e39cbb0c 100644 --- a/src/renderer/components/cluster-manager/cluster-view.route.ts +++ b/src/renderer/components/cluster-manager/cluster-view.route.ts @@ -33,8 +33,8 @@ export function getMatchedCluster() { return clusterStore.getById(getMatchedClusterId()) } -// Refresh global menu depending on active route's type (common/cluster view) if (ipcRenderer) { + // Refresh global menu depending on active route's type (common/cluster view) const isMainView = !getHostedClusterId(); if (isMainView) { reaction(() => getMatchedClusterId(), clusterId => { @@ -43,4 +43,9 @@ if (ipcRenderer) { fireImmediately: true }) } + + // Reload dashboard + ipcRenderer.on("menu:reload", () => { + location.reload(); + }); }