1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

remove windowManager from extension api

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
Jari Kolehmainen 2020-11-11 11:43:04 +02:00
parent 469b723469
commit 5393cf4ec9
10 changed files with 56 additions and 33 deletions

View File

@ -9,13 +9,10 @@
* [Util](modules/_core_api_utils_.md) * [Util](modules/_core_api_utils_.md)
* [Component](modules/_renderer_api_components_.md) * [Component](modules/_renderer_api_components_.md)
* [K8sApi](modules/_renderer_api_k8s_api_.md) * [K8sApi](modules/_renderer_api_k8s_api_.md)
* [Navigation](modules/_renderer_api_navigation_.md) * [Navigation](modules/_core_api_navigation_.md)
## Classes ## Classes
* [LensMainExtension](classes/lensmainextension.md) * [LensMainExtension](classes/lensmainextension.md)
* [LensRendererExtension](classes/lensrendererextension.md) * [LensRendererExtension](classes/lensrendererextension.md)
## Variables
* [windowManager](README.md#windowmanager)

View File

@ -1,4 +1,4 @@
import { LensMainExtension, windowManager } from "@k8slens/extensions"; import { LensMainExtension, Navigation } from "@k8slens/extensions";
import { supportPageURL } from "./src/support.route"; import { supportPageURL } from "./src/support.route";
export default class SupportPageMainExtension extends LensMainExtension { export default class SupportPageMainExtension extends LensMainExtension {
@ -7,7 +7,7 @@ export default class SupportPageMainExtension extends LensMainExtension {
parentId: "help", parentId: "help",
label: "Support", label: "Support",
click() { click() {
windowManager.navigate(supportPageURL()); Navigation.navigate(supportPageURL());
} }
} }
] ]

View File

@ -2,22 +2,19 @@
export * from "../lens-main-extension" export * from "../lens-main-extension"
export * from "../lens-renderer-extension" export * from "../lens-renderer-extension"
import type { WindowManager } from "../../main/window-manager";
// APIs // APIs
import * as App from "./app" import * as App from "./app"
import * as EventBus from "./event-bus" import * as EventBus from "./event-bus"
import * as Store from "./stores" import * as Store from "./stores"
import * as Util from "./utils" import * as Util from "./utils"
import * as ClusterFeature from "./cluster-feature" import * as ClusterFeature from "./cluster-feature"
import * as Navigation from "./navigation"
// TODO: allow to expose windowManager.navigate() as Navigation.navigate() in runtime
export let windowManager: WindowManager;
export { export {
App, App,
EventBus, EventBus,
ClusterFeature, ClusterFeature,
Navigation,
Store, Store,
Util, Util,
} }

View File

@ -0,0 +1,14 @@
import { ipcMain } from "electron";
import { WindowManager } from "../../main/window-manager";
import { navigate as navRenderer } from "../../renderer/navigation";
export { hideDetails, showDetails, getDetailsUrl } from "../../renderer/navigation"
export { RouteProps } from "react-router"
export { IURLParams } from "../../common/utils/buildUrl";
export async function navigate(location: string) {
if (ipcMain) {
await WindowManager.getInstance<WindowManager>().navigate(location)
} else {
navRenderer(location)
}
}

View File

@ -3,10 +3,8 @@
// APIs // APIs
import * as Component from "./components" import * as Component from "./components"
import * as K8sApi from "./k8s-api" import * as K8sApi from "./k8s-api"
import * as Navigation from "./navigation"
export { export {
Component, Component,
K8sApi, K8sApi,
Navigation,
} }

View File

@ -1,3 +0,0 @@
export { navigate, hideDetails, showDetails, getDetailsUrl } from "../../renderer/navigation"
export { RouteProps } from "react-router"
export { IURLParams } from "../../common/utils/buildUrl";

View File

@ -78,7 +78,7 @@ app.on("ready", async () => {
app.exit(); app.exit();
} }
LensExtensionsApi.windowManager = windowManager = new WindowManager(proxyPort); windowManager = WindowManager.getInstance<WindowManager>(proxyPort);
extensionLoader.init(await extensionManager.load()); // call after windowManager to see splash earlier extensionLoader.init(await extensionManager.load()); // call after windowManager to see splash earlier
setTimeout(() => { setTimeout(() => {

View File

@ -16,7 +16,7 @@ import { isDevelopment } from "../common/vars";
export let tray: Tray; export let tray: Tray;
// refresh icon when MacOS dark/light theme has changed // refresh icon when MacOS dark/light theme has changed
nativeTheme.on("updated", () => tray?.setImage(getTrayIcon())); nativeTheme?.on("updated", () => tray?.setImage(getTrayIcon()));
export function getTrayIcon(isDark = nativeTheme.shouldUseDarkColors): string { export function getTrayIcon(isDark = nativeTheme.shouldUseDarkColors): string {
return path.resolve( return path.resolve(

View File

@ -7,8 +7,9 @@ import { extensionLoader } from "../extensions/extension-loader";
import { appEventBus } from "../common/event-bus" import { appEventBus } from "../common/event-bus"
import { initMenu } from "./menu"; import { initMenu } from "./menu";
import { initTray } from "./tray"; import { initTray } from "./tray";
import { Singleton } from "../common/utils";
export class WindowManager { export class WindowManager extends Singleton {
protected mainWindow: BrowserWindow; protected mainWindow: BrowserWindow;
protected splashWindow: BrowserWindow; protected splashWindow: BrowserWindow;
protected windowState: windowStateKeeper.State; protected windowState: windowStateKeeper.State;
@ -17,6 +18,7 @@ export class WindowManager {
@observable activeClusterId: ClusterId; @observable activeClusterId: ClusterId;
constructor(protected proxyPort: number) { constructor(protected proxyPort: number) {
super();
this.bindEvents(); this.bindEvents();
this.initMenu(); this.initMenu();
this.initTray(); this.initTray();

View File

@ -3,13 +3,24 @@
import { ipcRenderer } from "electron"; import { ipcRenderer } from "electron";
import { matchPath } from "react-router"; import { matchPath } from "react-router";
import { reaction } from "mobx"; import { reaction } from "mobx";
import { createObservableHistory } from "mobx-observable-history"; import { createObservableHistory, IObservableHistory } from "mobx-observable-history";
import { createBrowserHistory, createMemoryHistory, LocationDescriptor } from "history"; import { createBrowserHistory, createMemoryHistory, LocationDescriptor, History } from "history";
import logger from "../main/logger"; import logger from "../main/logger";
import { clusterViewRoute, IClusterViewRouteParams } from "./components/cluster-manager/cluster-view.route"; import { clusterViewRoute, IClusterViewRouteParams } from "./components/cluster-manager/cluster-view.route";
export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory(); let history: History
export const navigation = createObservableHistory(history); let navigation: IObservableHistory
if (ipcRenderer) {
history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory();
navigation = createObservableHistory(history);
}
export {
history,
navigation
}
export function navigate(location: LocationDescriptor) { export function navigate(location: LocationDescriptor) {
const currentLocation = navigation.getPath(); const currentLocation = navigation.getPath();
@ -60,6 +71,9 @@ export function getDetailsUrl(details: string) {
}); });
} }
/**
* Show details. Works only in renderer.
*/
export function showDetails(path: string, resetSelected = true) { export function showDetails(path: string, resetSelected = true) {
navigation.searchParams.merge({ navigation.searchParams.merge({
details: path, details: path,
@ -67,6 +81,9 @@ export function showDetails(path: string, resetSelected = true) {
}) })
} }
/**
* Hide details. Works only in renderer.
*/
export function hideDetails() { export function hideDetails() {
showDetails(null) showDetails(null)
} }
@ -99,14 +116,15 @@ if (process.isMainFrame) {
fireImmediately: true fireImmediately: true
}) })
} }
if (ipcRenderer) {
// Handle navigation via IPC (e.g. from top menu)
ipcRenderer.on("menu:navigate", (event, location: LocationDescriptor) => {
logger.info(`[IPC]: ${event.type} ${JSON.stringify(location)}`, event);
navigate(location);
});
// Handle navigation via IPC (e.g. from top menu) // Reload dashboard window
ipcRenderer.on("menu:navigate", (event, location: LocationDescriptor) => { ipcRenderer.on("menu:reload", () => {
logger.info(`[IPC]: ${event.type} ${JSON.stringify(location)}`, event); location.reload();
navigate(location); });
}); }
// Reload dashboard window
ipcRenderer.on("menu:reload", () => {
location.reload();
});