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

Tray icon #833 -- part 1

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-09-29 19:09:05 +03:00
parent c542ad0348
commit f88aa2f22e
3 changed files with 33 additions and 1 deletions

View File

@ -89,6 +89,10 @@
"to": "static/", "to": "static/",
"filter": "!**/main.js" "filter": "!**/main.js"
}, },
{
"from": "build/icon.png",
"to": "static/icon.png"
},
"LICENSE" "LICENSE"
], ],
"linux": { "linux": {

View File

@ -2,7 +2,7 @@
import "../common/system-ca" import "../common/system-ca"
import "../common/prometheus-providers" import "../common/prometheus-providers"
import { app, dialog } from "electron" import { app, dialog, Tray } from "electron"
import { appName } from "../common/vars"; import { appName } from "../common/vars";
import path from "path" import path from "path"
import { LensProxy } from "./lens-proxy" import { LensProxy } from "./lens-proxy"
@ -13,6 +13,7 @@ import { shellSync } from "./shell-sync"
import { getFreePort } from "./port" import { getFreePort } from "./port"
import { mangleProxyEnv } from "./proxy-env" import { mangleProxyEnv } from "./proxy-env"
import { registerFileProtocol } from "../common/register-protocol"; import { registerFileProtocol } from "../common/register-protocol";
import { setupTrayIcon } from "./tray";
import { clusterStore } from "../common/cluster-store" import { clusterStore } from "../common/cluster-store"
import { userStore } from "../common/user-store"; import { userStore } from "../common/user-store";
import { workspaceStore } from "../common/workspace-store"; import { workspaceStore } from "../common/workspace-store";
@ -28,6 +29,7 @@ if (!process.env.CICD) {
let windowManager: WindowManager; let windowManager: WindowManager;
let clusterManager: ClusterManager; let clusterManager: ClusterManager;
let proxyServer: LensProxy; let proxyServer: LensProxy;
let trayIcon: Tray;
mangleProxyEnv() mangleProxyEnv()
if (app.commandLine.getSwitchValue("proxy-server") !== "") { if (app.commandLine.getSwitchValue("proxy-server") !== "") {
@ -75,6 +77,7 @@ async function main() {
// create window manager and open app // create window manager and open app
windowManager = new WindowManager(proxyPort); windowManager = new WindowManager(proxyPort);
trayIcon = await setupTrayIcon();
} }
app.on("ready", main); app.on("ready", main);

25
src/main/tray.ts Normal file
View File

@ -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;
}