mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
parent
eee7febfc3
commit
162b4108dd
@ -1,7 +1,7 @@
|
|||||||
import { autoUpdater } from "electron-updater"
|
import { autoUpdater } from "electron-updater"
|
||||||
import logger from "./logger"
|
import logger from "./logger"
|
||||||
|
|
||||||
export default class AppUpdater {
|
export class AppUpdater {
|
||||||
static defaultUpdateIntervalMs = 1000 * 60 * 60 * 24 // once a day
|
static defaultUpdateIntervalMs = 1000 * 60 * 60 * 24 // once a day
|
||||||
|
|
||||||
static checkForUpdates() {
|
static checkForUpdates() {
|
||||||
|
|||||||
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
import "../common/system-ca"
|
import "../common/system-ca"
|
||||||
import "../common/prometheus-providers"
|
import "../common/prometheus-providers"
|
||||||
import { app, dialog, Tray } from "electron"
|
import { app, dialog } 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"
|
||||||
import { WindowManager } from "./window-manager";
|
import { WindowManager } from "./window-manager";
|
||||||
import { ClusterManager } from "./cluster-manager";
|
import { ClusterManager } from "./cluster-manager";
|
||||||
import AppUpdater from "./app-updater"
|
import { AppUpdater } from "./app-updater"
|
||||||
import { shellSync } from "./shell-sync"
|
import { shellSync } from "./shell-sync"
|
||||||
import { getFreePort } from "./port"
|
import { getFreePort } from "./port"
|
||||||
import { mangleProxyEnv } from "./proxy-env"
|
import { mangleProxyEnv } from "./proxy-env"
|
||||||
@ -28,7 +28,6 @@ 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") !== "") {
|
||||||
|
|||||||
@ -3,29 +3,30 @@ import sharp from "sharp";
|
|||||||
import packageInfo from "../../package.json"
|
import packageInfo from "../../package.json"
|
||||||
import { app, dialog, Menu, nativeImage, Tray } from "electron"
|
import { app, dialog, Menu, nativeImage, Tray } from "electron"
|
||||||
import { isDevelopment, isMac } from "../common/vars";
|
import { isDevelopment, isMac } from "../common/vars";
|
||||||
import { WindowManager } from "./window-manager";
|
import { autorun } from "mobx";
|
||||||
import { showAbout } from "./menu";
|
import { showAbout } from "./menu";
|
||||||
import AppUpdater from "./app-updater";
|
import { AppUpdater } from "./app-updater";
|
||||||
|
import { WindowManager } from "./window-manager";
|
||||||
|
import { clusterStore } from "../common/cluster-store";
|
||||||
|
import { workspaceStore } from "../common/workspace-store";
|
||||||
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
import { preferencesURL } from "../renderer/components/+preferences/preferences.route";
|
||||||
|
import { clusterViewURL } from "../renderer/components/cluster-manager/cluster-view.route";
|
||||||
|
import logger from "./logger";
|
||||||
|
|
||||||
|
// note: instance of Tray should be saved somewhere, otherwise it disappears
|
||||||
|
export let tray: Tray;
|
||||||
|
|
||||||
export const trayIcon = isDevelopment
|
export const trayIcon = isDevelopment
|
||||||
? path.resolve(__static, "../src/renderer/components/icon/logo-lens.svg")
|
? path.resolve(__static, "../src/renderer/components/icon/logo-lens.svg")
|
||||||
: path.resolve(__static, "logo.svg") // electron-builder's extraResources
|
: path.resolve(__static, "logo.svg") // electron-builder's extraResources
|
||||||
|
|
||||||
export async function setupTrayIcon(windowManager: WindowManager) {
|
export function initTray(windowManager: WindowManager) {
|
||||||
await app.whenReady();
|
return autorun(() => buildTrayMenu(windowManager), {
|
||||||
|
delay: 100
|
||||||
const iconSize = isMac ? 16 : 32; // todo: verify on windows/linux
|
})
|
||||||
const pngIcon = await sharp(trayIcon).png().toBuffer();
|
}
|
||||||
const icon = nativeImage.createFromBuffer(pngIcon).resize({
|
|
||||||
width: iconSize,
|
|
||||||
height: iconSize
|
|
||||||
});
|
|
||||||
|
|
||||||
const appTray = new Tray(icon)
|
|
||||||
appTray.setToolTip(packageInfo.description)
|
|
||||||
appTray.setIgnoreDoubleClickEvents(true);
|
|
||||||
|
|
||||||
|
export async function buildTrayMenu(windowManager: WindowManager) {
|
||||||
// note: browserWindow not available within menuItem.click() as argument[1] when app is not focused / hidden
|
// note: browserWindow not available within menuItem.click() as argument[1] when app is not focused / hidden
|
||||||
const trayMenu = Menu.buildFromTemplate([
|
const trayMenu = Menu.buildFromTemplate([
|
||||||
{
|
{
|
||||||
@ -42,6 +43,25 @@ export async function setupTrayIcon(windowManager: WindowManager) {
|
|||||||
windowManager.navigate(preferencesURL());
|
windowManager.navigate(preferencesURL());
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: "Clusters",
|
||||||
|
submenu: workspaceStore.workspacesList.map(workspace => {
|
||||||
|
const clusters = clusterStore.getByWorkspaceId(workspace.id);
|
||||||
|
return {
|
||||||
|
label: workspace.name,
|
||||||
|
toolTip: workspace.description,
|
||||||
|
submenu: clusters.map(({ id: clusterId, contextName: label }) => {
|
||||||
|
return {
|
||||||
|
label,
|
||||||
|
click() {
|
||||||
|
windowManager.bringToTop();
|
||||||
|
windowManager.navigate(clusterViewURL({ params: { clusterId } }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: "Check for updates",
|
label: "Check for updates",
|
||||||
async click() {
|
async click() {
|
||||||
@ -57,6 +77,25 @@ export async function setupTrayIcon(windowManager: WindowManager) {
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
appTray.setContextMenu(trayMenu);
|
// note: all "await"-s must be defined *AFTER* getting observables for proper mobx reactions
|
||||||
return appTray;
|
await app.whenReady();
|
||||||
|
logger.info('[TRAY]: building tray icon and menu');
|
||||||
|
|
||||||
|
const iconSize = isMac ? 16 : 32; // todo: verify on windows/linux
|
||||||
|
const pngIcon = await sharp(trayIcon).png().toBuffer();
|
||||||
|
const icon = nativeImage.createFromBuffer(pngIcon).resize({
|
||||||
|
width: iconSize,
|
||||||
|
height: iconSize
|
||||||
|
});
|
||||||
|
|
||||||
|
if (tray) {
|
||||||
|
tray.destroy(); // remove old tray on update
|
||||||
|
}
|
||||||
|
|
||||||
|
tray = new Tray(icon)
|
||||||
|
tray.setToolTip(packageInfo.description)
|
||||||
|
tray.setIgnoreDoubleClickEvents(true);
|
||||||
|
tray.setContextMenu(trayMenu);
|
||||||
|
|
||||||
|
return tray;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +1,15 @@
|
|||||||
import type { ClusterId } from "../common/cluster-store";
|
import type { ClusterId } from "../common/cluster-store";
|
||||||
import { clusterStore } from "../common/cluster-store";
|
import { clusterStore } from "../common/cluster-store";
|
||||||
import { BrowserWindow, dialog, ipcMain, shell, Tray, webContents } from "electron"
|
import { BrowserWindow, dialog, ipcMain, shell, webContents } from "electron"
|
||||||
import windowStateKeeper from "electron-window-state"
|
import windowStateKeeper from "electron-window-state"
|
||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import { initMenu } from "./menu";
|
import { initMenu } from "./menu";
|
||||||
import { setupTrayIcon } from "./tray";
|
import { initTray } from "./tray";
|
||||||
|
|
||||||
export class WindowManager {
|
export class WindowManager {
|
||||||
public mainView: BrowserWindow;
|
public mainView: BrowserWindow;
|
||||||
protected splashWindow: BrowserWindow;
|
protected splashWindow: BrowserWindow;
|
||||||
protected windowState: windowStateKeeper.State;
|
protected windowState: windowStateKeeper.State;
|
||||||
protected trayIcon: Tray;
|
|
||||||
|
|
||||||
@observable activeClusterId: ClusterId;
|
@observable activeClusterId: ClusterId;
|
||||||
|
|
||||||
@ -55,7 +54,7 @@ export class WindowManager {
|
|||||||
|
|
||||||
async initMenus() {
|
async initMenus() {
|
||||||
initMenu(this);
|
initMenu(this);
|
||||||
this.trayIcon = await setupTrayIcon(this);
|
initTray(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bringToTop() {
|
bringToTop() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user