Added minimize to tray.
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
const path = require("path");
|
||||
const { app, BrowserWindow, ipcMain } = require("electron");
|
||||
const { app, BrowserWindow, Tray, Menu, ipcMain } = require("electron");
|
||||
const isDev = require("electron-is-dev");
|
||||
const settings = require("electron-settings");
|
||||
const ipcTypes = require("../src/ipc.types");
|
||||
const { StartWatcher } = require("./file-watcher/file-watcher");
|
||||
const { default: ipcTypes } = require("../src/ipc.types");
|
||||
|
||||
require("./ipc-main-handler");
|
||||
|
||||
@@ -23,13 +22,16 @@ if (require("electron-squirrel-startup")) {
|
||||
console.log(`${__dirname}/preload.js`);
|
||||
|
||||
let mainWindow;
|
||||
let tray = null;
|
||||
function createWindow() {
|
||||
makeSingleInstance();
|
||||
// Create the browser window.
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
title: "ImEX RPS",
|
||||
icon: path.join(__dirname, "../src/assets/logo192.png"),
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
enableRemoteModule: false,
|
||||
@@ -46,6 +48,23 @@ function createWindow() {
|
||||
: `file://${path.join(__dirname, "../build/index.html")}`
|
||||
);
|
||||
|
||||
// mainWindow.on("close", function (event) {
|
||||
// event.preventDefault();
|
||||
// mainWindow.hide();
|
||||
// tray = createTray();
|
||||
// });
|
||||
|
||||
mainWindow.on("minimize", function (event) {
|
||||
event.preventDefault();
|
||||
mainWindow.hide();
|
||||
tray = createTray();
|
||||
});
|
||||
|
||||
ipcMain.on(ipcTypes.quit, (event, arg) => {
|
||||
app.isQuiting = true;
|
||||
app.quit();
|
||||
});
|
||||
|
||||
// Open the DevTools.
|
||||
if (isDev) {
|
||||
mainWindow.webContents.openDevTools({
|
||||
@@ -67,7 +86,7 @@ app.whenReady().then(() => {
|
||||
.then((name) => console.log(`Added Extension: ${name}`))
|
||||
.catch((error) => console.log(`An error occurred: , ${error}`));
|
||||
}
|
||||
StartWatcher();
|
||||
|
||||
// ipcMain.on(ipcTypes.default.webcontent, (event, ...obj) => {
|
||||
// console.log("event", event);
|
||||
// mainWindow.webContents.send(event, obj);
|
||||
@@ -106,3 +125,29 @@ function makeSingleInstance() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function createTray() {
|
||||
let appIcon = new Tray(path.join(__dirname, "../src/assets/logo192.png"));
|
||||
const contextMenu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: "Show",
|
||||
click: function () {
|
||||
mainWindow.show();
|
||||
},
|
||||
},
|
||||
{
|
||||
label: "Exit",
|
||||
click: function () {
|
||||
app.isQuiting = true;
|
||||
app.quit();
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
appIcon.on("double-click", function (event) {
|
||||
mainWindow.show();
|
||||
});
|
||||
appIcon.setToolTip("ImEX RPS");
|
||||
appIcon.setContextMenu(contextMenu);
|
||||
return appIcon;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user