Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to minimize electron app to tray icon

import {app, BrowserWindow, Tray, Menu} from 'electron';
import * as path from 'path';

let window;
let isQuiting;
let tray;

app.on('before-quit', function () {
  isQuiting = true;
});

app.on('ready', () => {
  tray = new Tray(path.join(__dirname, 'tray.png'));

  tray.setContextMenu(Menu.buildFromTemplate([
    {
      label: 'Show App', click: function () {
        window.show();
      }
    },
    {
      label: 'Quit', click: function () {
        isQuiting = true;
        app.quit();
      }
    }
  ]));

  window = new BrowserWindow({
    width: 850,
    height: 450,
    show: false,
  });

  window.on('close', function (event) {
    if (!isQuiting) {
      event.preventDefault();
      window.hide();
      event.returnValue = false;
    }
  });
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: encrypt decrypt in vanilla javascript 
Javascript :: input type email react js-validation 
Javascript :: get id of an element 
Javascript :: for of loop in es6 
Javascript :: variable for every user discord.js 
Javascript :: js iso date split 
Javascript :: multiply arrays javascript 
Javascript :: repeat an array multiple times in js 
Javascript :: react native paper modal background 
Javascript :: webpack error cannot find module 
Javascript :: react 18 
Javascript :: enzyme-adapter-react-17 
Javascript :: hello world in html using javascript 
Javascript :: text.toUpperCase is not a function 
Javascript :: adding background video angular 6 
Javascript :: javascript vector 
Javascript :: convert array to object 
Javascript :: string to regex javascript 
Javascript :: react 18 render 
Javascript :: js if else 
Javascript :: javascript how to take off a decimal 
Javascript :: how to iterate array in javascript 
Javascript :: how to loop trough an object java script 
Javascript :: binary tree implementation javascript 
Javascript :: else if javascript 
Javascript :: change href javascript 
Javascript :: javascript clear child elements 
Javascript :: array.reverse 
Javascript :: select li element with arrow keys (up and down) using javascript 
Javascript :: skip arguments in js 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =