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

allow to disable tray from preferences

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-10-02 15:55:02 +03:00
parent deb0d85af0
commit 8797f0af6f
5 changed files with 37 additions and 10 deletions

View File

@ -27,6 +27,7 @@ export interface UserPreferences {
downloadKubectlBinaries?: boolean; downloadKubectlBinaries?: boolean;
downloadBinariesPath?: string; downloadBinariesPath?: string;
kubectlBinariesPath?: string; kubectlBinariesPath?: string;
trayEnabled?: boolean;
} }
export class UserStore extends BaseStore<UserStoreModel> { export class UserStore extends BaseStore<UserStoreModel> {
@ -59,6 +60,7 @@ export class UserStore extends BaseStore<UserStoreModel> {
colorTheme: UserStore.defaultTheme, colorTheme: UserStore.defaultTheme,
downloadMirror: "default", downloadMirror: "default",
downloadKubectlBinaries: true, // Download kubectl binaries matching cluster version downloadKubectlBinaries: true, // Download kubectl binaries matching cluster version
trayEnabled: true,
}; };
get isNewVersion() { get isNewVersion() {

View File

@ -9,7 +9,7 @@ import { clusterSettingsURL } from "../renderer/components/+cluster-settings/clu
import logger from "./logger"; import logger from "./logger";
export function initMenu(windowManager: WindowManager) { export function initMenu(windowManager: WindowManager) {
autorun(() => buildMenu(windowManager), { return autorun(() => buildMenu(windowManager), {
delay: 100 delay: 100
}); });
} }

View File

@ -21,10 +21,14 @@ export const trayIcon = isDevelopment
: path.resolve(__static, "logo.svg") // electron-builder's extraResources : path.resolve(__static, "logo.svg") // electron-builder's extraResources
export function initTray(windowManager: WindowManager) { export function initTray(windowManager: WindowManager) {
return autorun(() => { const dispose = autorun(() => {
const menu = createTrayMenu(windowManager); const menu = createTrayMenu(windowManager);
buildTray(menu); buildTray(menu);
}) })
return () => {
tray?.destroy();
dispose();
}
} }
export async function buildTray(menu: Menu) { export async function buildTray(menu: Menu) {
@ -36,10 +40,7 @@ export async function buildTray(menu: Menu) {
height: iconSize height: iconSize
}); });
if (tray) { tray?.destroy(); // remove previous tray first
tray.destroy(); // remove old tray on update
}
tray = new Tray(icon) tray = new Tray(icon)
tray.setToolTip(packageInfo.description) tray.setToolTip(packageInfo.description)
tray.setIgnoreDoubleClickEvents(true); tray.setIgnoreDoubleClickEvents(true);

View File

@ -1,8 +1,9 @@
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 { userStore } from "../common/user-store";
import { observable, reaction } from "mobx";
import { BrowserWindow, dialog, ipcMain, shell, 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 { initMenu } from "./menu"; import { initMenu } from "./menu";
import { initTray } from "./tray"; import { initTray } from "./tray";
@ -10,6 +11,7 @@ export class WindowManager {
public mainView: BrowserWindow; public mainView: BrowserWindow;
protected splashWindow: BrowserWindow; protected splashWindow: BrowserWindow;
protected windowState: windowStateKeeper.State; protected windowState: windowStateKeeper.State;
protected disposers: Record<string, Function> = {};
@observable activeClusterId: ClusterId; @observable activeClusterId: ClusterId;
@ -52,9 +54,17 @@ export class WindowManager {
this.initMenus(); this.initMenus();
} }
async initMenus() { protected async initMenus() {
initMenu(this); this.disposers.menuAutoUpdater = initMenu(this);
initTray(this); this.disposers.trayAutoBind = reaction(() => userStore.preferences.trayEnabled, isEnabled => {
if (isEnabled) {
this.disposers.trayAutoUpdater = initTray(this);
} else {
this.disposers?.trayAutoUpdater();
}
}, {
fireImmediately: true
});
} }
bringToTop() { bringToTop() {
@ -120,5 +130,9 @@ export class WindowManager {
this.windowState.unmanage(); this.windowState.unmanage();
this.splashWindow.destroy(); this.splashWindow.destroy();
this.mainView.destroy(); this.mainView.destroy();
Object.entries(this.disposers).forEach(([name, dispose]) => {
dispose();
delete this.disposers[name]
});
} }
} }

View File

@ -194,6 +194,16 @@ export class Preferences extends React.Component {
<small className="hint"> <small className="hint">
<Trans>Telemetry & usage data is collected to continuously improve the Lens experience.</Trans> <Trans>Telemetry & usage data is collected to continuously improve the Lens experience.</Trans>
</small> </small>
<h2><Trans>Tray icon</Trans></h2>
<Checkbox
label={<Trans>Enable tray icon</Trans>}
value={preferences.trayEnabled}
onChange={v => preferences.trayEnabled = v}
/>
<small className="hint">
<Trans>Adds OS-level tray icon and menu to get quick access to Lens</Trans>
</small>
</WizardLayout> </WizardLayout>
</div> </div>
); );