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:
parent
469b723469
commit
5393cf4ec9
@ -9,13 +9,10 @@
|
||||
* [Util](modules/_core_api_utils_.md)
|
||||
* [Component](modules/_renderer_api_components_.md)
|
||||
* [K8sApi](modules/_renderer_api_k8s_api_.md)
|
||||
* [Navigation](modules/_renderer_api_navigation_.md)
|
||||
* [Navigation](modules/_core_api_navigation_.md)
|
||||
|
||||
## Classes
|
||||
|
||||
* [LensMainExtension](classes/lensmainextension.md)
|
||||
* [LensRendererExtension](classes/lensrendererextension.md)
|
||||
|
||||
## Variables
|
||||
|
||||
* [windowManager](README.md#windowmanager)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { LensMainExtension, windowManager } from "@k8slens/extensions";
|
||||
import { LensMainExtension, Navigation } from "@k8slens/extensions";
|
||||
import { supportPageURL } from "./src/support.route";
|
||||
|
||||
export default class SupportPageMainExtension extends LensMainExtension {
|
||||
@ -7,7 +7,7 @@ export default class SupportPageMainExtension extends LensMainExtension {
|
||||
parentId: "help",
|
||||
label: "Support",
|
||||
click() {
|
||||
windowManager.navigate(supportPageURL());
|
||||
Navigation.navigate(supportPageURL());
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
@ -2,22 +2,19 @@
|
||||
export * from "../lens-main-extension"
|
||||
export * from "../lens-renderer-extension"
|
||||
|
||||
import type { WindowManager } from "../../main/window-manager";
|
||||
|
||||
// APIs
|
||||
import * as App from "./app"
|
||||
import * as EventBus from "./event-bus"
|
||||
import * as Store from "./stores"
|
||||
import * as Util from "./utils"
|
||||
import * as ClusterFeature from "./cluster-feature"
|
||||
|
||||
// TODO: allow to expose windowManager.navigate() as Navigation.navigate() in runtime
|
||||
export let windowManager: WindowManager;
|
||||
import * as Navigation from "./navigation"
|
||||
|
||||
export {
|
||||
App,
|
||||
EventBus,
|
||||
ClusterFeature,
|
||||
Navigation,
|
||||
Store,
|
||||
Util,
|
||||
}
|
||||
|
||||
14
src/extensions/core-api/navigation.ts
Normal file
14
src/extensions/core-api/navigation.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
@ -3,10 +3,8 @@
|
||||
// APIs
|
||||
import * as Component from "./components"
|
||||
import * as K8sApi from "./k8s-api"
|
||||
import * as Navigation from "./navigation"
|
||||
|
||||
export {
|
||||
Component,
|
||||
K8sApi,
|
||||
Navigation,
|
||||
}
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
export { navigate, hideDetails, showDetails, getDetailsUrl } from "../../renderer/navigation"
|
||||
export { RouteProps } from "react-router"
|
||||
export { IURLParams } from "../../common/utils/buildUrl";
|
||||
@ -78,7 +78,7 @@ app.on("ready", async () => {
|
||||
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
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
@ -16,7 +16,7 @@ import { isDevelopment } from "../common/vars";
|
||||
export let tray: Tray;
|
||||
|
||||
// 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 {
|
||||
return path.resolve(
|
||||
|
||||
@ -7,8 +7,9 @@ import { extensionLoader } from "../extensions/extension-loader";
|
||||
import { appEventBus } from "../common/event-bus"
|
||||
import { initMenu } from "./menu";
|
||||
import { initTray } from "./tray";
|
||||
import { Singleton } from "../common/utils";
|
||||
|
||||
export class WindowManager {
|
||||
export class WindowManager extends Singleton {
|
||||
protected mainWindow: BrowserWindow;
|
||||
protected splashWindow: BrowserWindow;
|
||||
protected windowState: windowStateKeeper.State;
|
||||
@ -17,6 +18,7 @@ export class WindowManager {
|
||||
@observable activeClusterId: ClusterId;
|
||||
|
||||
constructor(protected proxyPort: number) {
|
||||
super();
|
||||
this.bindEvents();
|
||||
this.initMenu();
|
||||
this.initTray();
|
||||
|
||||
@ -3,13 +3,24 @@
|
||||
import { ipcRenderer } from "electron";
|
||||
import { matchPath } from "react-router";
|
||||
import { reaction } from "mobx";
|
||||
import { createObservableHistory } from "mobx-observable-history";
|
||||
import { createBrowserHistory, createMemoryHistory, LocationDescriptor } from "history";
|
||||
import { createObservableHistory, IObservableHistory } from "mobx-observable-history";
|
||||
import { createBrowserHistory, createMemoryHistory, LocationDescriptor, History } from "history";
|
||||
import logger from "../main/logger";
|
||||
import { clusterViewRoute, IClusterViewRouteParams } from "./components/cluster-manager/cluster-view.route";
|
||||
|
||||
export const history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory();
|
||||
export const navigation = createObservableHistory(history);
|
||||
let history: History
|
||||
let navigation: IObservableHistory
|
||||
|
||||
if (ipcRenderer) {
|
||||
history = typeof window !== "undefined" ? createBrowserHistory() : createMemoryHistory();
|
||||
navigation = createObservableHistory(history);
|
||||
}
|
||||
|
||||
export {
|
||||
history,
|
||||
navigation
|
||||
}
|
||||
|
||||
|
||||
export function navigate(location: LocationDescriptor) {
|
||||
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) {
|
||||
navigation.searchParams.merge({
|
||||
details: path,
|
||||
@ -67,6 +81,9 @@ export function showDetails(path: string, resetSelected = true) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide details. Works only in renderer.
|
||||
*/
|
||||
export function hideDetails() {
|
||||
showDetails(null)
|
||||
}
|
||||
@ -99,14 +116,15 @@ if (process.isMainFrame) {
|
||||
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)
|
||||
ipcRenderer.on("menu:navigate", (event, location: LocationDescriptor) => {
|
||||
logger.info(`[IPC]: ${event.type} ${JSON.stringify(location)}`, event);
|
||||
navigate(location);
|
||||
});
|
||||
|
||||
// Reload dashboard window
|
||||
ipcRenderer.on("menu:reload", () => {
|
||||
location.reload();
|
||||
});
|
||||
// Reload dashboard window
|
||||
ipcRenderer.on("menu:reload", () => {
|
||||
location.reload();
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user