Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const electron = require("electron");
// app control, application life.BrowserWindow creates native browser window.
const { app, BrowserWindow } = require("electron");
const { app, dialog, BrowserWindow, Menu, Tray } = require("electron");

//Store Window size and position
const windowStateKeeper = require("electron-window-state");
Expand Down Expand Up @@ -58,9 +58,44 @@ function createWindow() {
})
);

// Build and set context menu
const appIcon = new Tray(path.join(__dirname, "images/icon.png"))
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show on Taskbar',
click: function () {
mainWindow.setSkipTaskbar(false);
}
},
{
label: 'Quit',
role: 'quit'
}
])

appIcon.setContextMenu(contextMenu);

// Open the DevTools.
// mainWindow.webContents.openDevTools()

mainWindow.on('show', function () {
appIcon.setToolTip('always');
});

mainWindow.on('close', function(event) {
const choice = dialog.showMessageBoxSync(mainWindow,
{
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: 'Would you like to exit to system tray?'
});
if (choice === 0) {
event.preventDefault();
mainWindow.setSkipTaskbar(true);
}
});

// Emitted when the window is closed.
mainWindow.on("closed", function () {
// Dereference the window object, usually you would store windows
Expand Down