mirror of
				https://github.com/Mastermindzh/tidal-hifi.git
				synced 2025-11-04 02:39:13 +01:00 
			
		
		
		
	Implement minimized action to hide the application on close (#60)
* Implement minimzed action to hide the application on close instead of closing it. * Add close event on the tray icon * Add all items in the menu (not only Show/Close app) * Changes on mainWindow. Toggle instead of Open/Close pair button
This commit is contained in:
		@@ -15,6 +15,7 @@ const store = new Store({
 | 
			
		||||
      port: 47836,
 | 
			
		||||
    },
 | 
			
		||||
    trayIcon: true,
 | 
			
		||||
    minimizeOnClose : false,
 | 
			
		||||
    mpris: false,
 | 
			
		||||
    enableCustomHotkeys: false,
 | 
			
		||||
    enableDiscord: false,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
const { Tray } = require("electron");
 | 
			
		||||
const { getMenu } = require("./menu");
 | 
			
		||||
const { Tray, app } = require("electron");
 | 
			
		||||
const { Menu } = require("electron");
 | 
			
		||||
const { getMenu, mainMenu } = require("./menu");
 | 
			
		||||
const { store, settings } = require("./settings");
 | 
			
		||||
const trayModule = {};
 | 
			
		||||
let tray;
 | 
			
		||||
 | 
			
		||||
@@ -7,16 +9,41 @@ trayModule.addTray = function (options = { icon: "" }) {
 | 
			
		||||
  tray = new Tray(options.icon);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
trayModule.refreshTray = function () {
 | 
			
		||||
trayModule.refreshTray = function (mainWindow) {
 | 
			
		||||
  if (!tray) {
 | 
			
		||||
    trayModule.addTray();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  tray.on("click", function (e) {
 | 
			
		||||
    // do nothing on click
 | 
			
		||||
    if (mainWindow) {
 | 
			
		||||
      mainWindow.show();
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  tray.setToolTip("Tidal-hifi");
 | 
			
		||||
  tray.setContextMenu(getMenu());
 | 
			
		||||
  
 | 
			
		||||
  if (mainWindow && store.get(settings.minimizeOnClose)) {
 | 
			
		||||
    tray.setContextMenu(
 | 
			
		||||
      Menu.buildFromTemplate([
 | 
			
		||||
        {
 | 
			
		||||
          label: "Toggle Window",
 | 
			
		||||
          click: function () {
 | 
			
		||||
            mainWindow.isVisible() ? mainWindow.hide() : mainWindow.show();
 | 
			
		||||
          },
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          label: "Quit",
 | 
			
		||||
          click: function () {
 | 
			
		||||
            mainWindow.destroy();
 | 
			
		||||
            app.quit();
 | 
			
		||||
          },
 | 
			
		||||
        },      
 | 
			
		||||
        ...mainMenu, //we add menu items from the other context
 | 
			
		||||
      ])
 | 
			
		||||
    );
 | 
			
		||||
  } else {
 | 
			
		||||
    tray.setContextMenu(getMenu());
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
module.exports = trayModule;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user