12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- const {app, Tray, Menu} = require('electron');
- const path = require('path');
- const window = require('../../../helper/window');
- const tray = {};
- tray.openApp = function () {
- if (appIcon) {
- appIcon.destroy();
- // Re create the main window on dashboard page and close the invisible window
- const newWindow = window.new(path.join(__dirname, '../../renderer/page/dashboard/dashboard.html'));
- mainWindow.close();
- mainWindow = newWindow;
- }
- };
- tray.closeApp = function () {
- if (appIcon) {
- appIcon.destroy();
- app.quit();
- }
- }
- tray.active = function () {
- appIcon = new Tray(path.join(__dirname, '../asset/tray.png'));
- appIcon.setToolTip('Electronotes');
- appIcon.setContextMenu(menu);
- // Hide app
- const invisibleWindow = window.hidden(); // Create invisible window to avoid closing the app when all window are closed
- mainWindow.close();
- mainWindow = invisibleWindow;
- // Left click => open app
- appIcon.on('click', (event) => {
- tray.openApp();
- });
- };
- module.exports = tray;
- /* --- Var and event --- */
- let appIcon = null;
- app.on('quit', () => {
- if (appIcon) {
- appIcon.destroy();
- }
- });
- const template = [
- {
- label: 'Ouvrir',
- click: tray.openApp,
- },
- {
- label: 'Quitter',
- click: tray.closeApp
- }
- ];
- const menu = Menu.buildFromTemplate(template);
|