diff --git a/package.json b/package.json index 53488e932d..56385fc9fd 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,10 @@ "to": "static/", "filter": "!**/main.js" }, + { + "from": "build/icon.png", + "to": "static/icon.png" + }, "LICENSE" ], "linux": { diff --git a/src/main/index.ts b/src/main/index.ts index e4fd246467..638305b7b6 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -2,7 +2,7 @@ import "../common/system-ca" import "../common/prometheus-providers" -import { app, dialog } from "electron" +import { app, dialog, Tray } from "electron" import { appName } from "../common/vars"; import path from "path" import { LensProxy } from "./lens-proxy" @@ -13,6 +13,7 @@ import { shellSync } from "./shell-sync" import { getFreePort } from "./port" import { mangleProxyEnv } from "./proxy-env" import { registerFileProtocol } from "../common/register-protocol"; +import { setupTrayIcon } from "./tray"; import { clusterStore } from "../common/cluster-store" import { userStore } from "../common/user-store"; import { workspaceStore } from "../common/workspace-store"; @@ -28,6 +29,7 @@ if (!process.env.CICD) { let windowManager: WindowManager; let clusterManager: ClusterManager; let proxyServer: LensProxy; +let trayIcon: Tray; mangleProxyEnv() if (app.commandLine.getSwitchValue("proxy-server") !== "") { @@ -75,6 +77,7 @@ async function main() { // create window manager and open app windowManager = new WindowManager(proxyPort); + trayIcon = await setupTrayIcon(); } app.on("ready", main); diff --git a/src/main/tray.ts b/src/main/tray.ts new file mode 100644 index 0000000000..05b23a5f27 --- /dev/null +++ b/src/main/tray.ts @@ -0,0 +1,25 @@ +import path from "path" +import { app, Menu, nativeImage, Tray } from "electron" +import { isDevelopment } from "../common/vars"; +import packageInfo from "../../package.json" + +export async function setupTrayIcon() { + await app.whenReady(); + + const iconPath = path.resolve(__static, isDevelopment ? "../build" : "", "icon.png"); + + // todo: https://www.electronjs.org/docs/api/native-image#high-resolution-image + const icon = nativeImage.createFromPath(iconPath).resize({ width: 16, height: 16 }); + + const appTray = new Tray(icon); + appTray.setToolTip(packageInfo.description) + appTray.setIgnoreDoubleClickEvents(true) + + const trayMenu = Menu.buildFromTemplate([ + { label: 'Item1', type: 'radio' }, + { label: 'Item2', type: 'radio' } + ]); + + appTray.setContextMenu(trayMenu); + return appTray; +}