Skip to content

Commit

Permalink
add tray icon and hide dock icon
Browse files Browse the repository at this point in the history
  • Loading branch information
miaowing committed Jul 21, 2020
1 parent 27aed95 commit 11c5970
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Binary file added src/assets/trayTemplate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as packages from '../package.json';
import { NestRPC } from "electron-nest-rpc";
import { NestLogger } from "@nestcloud/logger";
import { resolve } from 'path';
import { initTray } from "./tray";

// require('update-electron-app')()

Expand All @@ -16,7 +17,11 @@ if (require('electron-squirrel-startup')) { // eslint-disable-line global-requir
app.quit();
}

app.dock.hide();

let willQuit = false;
// @ts-ignore
let tray;
let mainWindow;
let context: INestApplicationContext;

Expand Down Expand Up @@ -74,6 +79,7 @@ const createWindow = () => {
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);

initAppMenu(mainWindow);
tray = initTray(mainWindow);

mainWindow.once('ready-to-show', () => {
mainWindow.show()
Expand Down
24 changes: 24 additions & 0 deletions src/tray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Tray, BrowserWindow } from 'electron';
import { resolve } from "path";

export const initTray = (window: BrowserWindow) => {
const image = resolve(__dirname, '../../src/assets/trayTemplate.png');
const trayObj = new Tray(image);
trayObj.setToolTip('Dolphin');


trayObj.on('click', e => {
if (!window.isVisible()) {
e.preventDefault();
window.show();
} else {
window.moveTop();
}
});

trayObj.on('right-click', e => {
trayObj.popUpContextMenu();
});

return trayObj;
};

0 comments on commit 11c5970

Please sign in to comment.