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:
parent
deb0d85af0
commit
8797f0af6f
@ -27,6 +27,7 @@ export interface UserPreferences {
|
||||
downloadKubectlBinaries?: boolean;
|
||||
downloadBinariesPath?: string;
|
||||
kubectlBinariesPath?: string;
|
||||
trayEnabled?: boolean;
|
||||
}
|
||||
|
||||
export class UserStore extends BaseStore<UserStoreModel> {
|
||||
@ -59,6 +60,7 @@ export class UserStore extends BaseStore<UserStoreModel> {
|
||||
colorTheme: UserStore.defaultTheme,
|
||||
downloadMirror: "default",
|
||||
downloadKubectlBinaries: true, // Download kubectl binaries matching cluster version
|
||||
trayEnabled: true,
|
||||
};
|
||||
|
||||
get isNewVersion() {
|
||||
|
||||
@ -9,7 +9,7 @@ import { clusterSettingsURL } from "../renderer/components/+cluster-settings/clu
|
||||
import logger from "./logger";
|
||||
|
||||
export function initMenu(windowManager: WindowManager) {
|
||||
autorun(() => buildMenu(windowManager), {
|
||||
return autorun(() => buildMenu(windowManager), {
|
||||
delay: 100
|
||||
});
|
||||
}
|
||||
|
||||
@ -21,10 +21,14 @@ export const trayIcon = isDevelopment
|
||||
: path.resolve(__static, "logo.svg") // electron-builder's extraResources
|
||||
|
||||
export function initTray(windowManager: WindowManager) {
|
||||
return autorun(() => {
|
||||
const dispose = autorun(() => {
|
||||
const menu = createTrayMenu(windowManager);
|
||||
buildTray(menu);
|
||||
})
|
||||
return () => {
|
||||
tray?.destroy();
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
export async function buildTray(menu: Menu) {
|
||||
@ -36,10 +40,7 @@ export async function buildTray(menu: Menu) {
|
||||
height: iconSize
|
||||
});
|
||||
|
||||
if (tray) {
|
||||
tray.destroy(); // remove old tray on update
|
||||
}
|
||||
|
||||
tray?.destroy(); // remove previous tray first
|
||||
tray = new Tray(icon)
|
||||
tray.setToolTip(packageInfo.description)
|
||||
tray.setIgnoreDoubleClickEvents(true);
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import type { ClusterId } 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 windowStateKeeper from "electron-window-state"
|
||||
import { observable } from "mobx";
|
||||
import { initMenu } from "./menu";
|
||||
import { initTray } from "./tray";
|
||||
|
||||
@ -10,6 +11,7 @@ export class WindowManager {
|
||||
public mainView: BrowserWindow;
|
||||
protected splashWindow: BrowserWindow;
|
||||
protected windowState: windowStateKeeper.State;
|
||||
protected disposers: Record<string, Function> = {};
|
||||
|
||||
@observable activeClusterId: ClusterId;
|
||||
|
||||
@ -52,9 +54,17 @@ export class WindowManager {
|
||||
this.initMenus();
|
||||
}
|
||||
|
||||
async initMenus() {
|
||||
initMenu(this);
|
||||
initTray(this);
|
||||
protected async initMenus() {
|
||||
this.disposers.menuAutoUpdater = initMenu(this);
|
||||
this.disposers.trayAutoBind = reaction(() => userStore.preferences.trayEnabled, isEnabled => {
|
||||
if (isEnabled) {
|
||||
this.disposers.trayAutoUpdater = initTray(this);
|
||||
} else {
|
||||
this.disposers?.trayAutoUpdater();
|
||||
}
|
||||
}, {
|
||||
fireImmediately: true
|
||||
});
|
||||
}
|
||||
|
||||
bringToTop() {
|
||||
@ -120,5 +130,9 @@ export class WindowManager {
|
||||
this.windowState.unmanage();
|
||||
this.splashWindow.destroy();
|
||||
this.mainView.destroy();
|
||||
Object.entries(this.disposers).forEach(([name, dispose]) => {
|
||||
dispose();
|
||||
delete this.disposers[name]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,6 +194,16 @@ export class Preferences extends React.Component {
|
||||
<small className="hint">
|
||||
<Trans>Telemetry & usage data is collected to continuously improve the Lens experience.</Trans>
|
||||
</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>
|
||||
</div>
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user