mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-11-22 21:42:46 +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:
parent
aa562c4a30
commit
6608330ed3
@ -26,6 +26,7 @@ const settings = {
|
|||||||
width: "windowBounds.width",
|
width: "windowBounds.width",
|
||||||
height: "windowBounds.height",
|
height: "windowBounds.height",
|
||||||
},
|
},
|
||||||
|
minimizeOnClose: "minimizeOnClose",
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = settings;
|
module.exports = settings;
|
||||||
|
@ -56,6 +56,14 @@ function createWindow(options = {}) {
|
|||||||
// run stuff after first load
|
// run stuff after first load
|
||||||
mainWindow.webContents.once("did-finish-load", () => {});
|
mainWindow.webContents.once("did-finish-load", () => {});
|
||||||
|
|
||||||
|
mainWindow.on("close", function (event) {
|
||||||
|
if (!app.isQuiting && store.get(settings.minimizeOnClose)) {
|
||||||
|
event.preventDefault();
|
||||||
|
mainWindow.hide();
|
||||||
|
refreshTray(mainWindow);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
mainWindow.on("closed", function () {
|
mainWindow.on("closed", function () {
|
||||||
closeSettingsWindow();
|
closeSettingsWindow();
|
||||||
|
@ -21,6 +21,7 @@ function refreshSettings() {
|
|||||||
mpris.checked = store.get(settings.mpris);
|
mpris.checked = store.get(settings.mpris);
|
||||||
enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys);
|
enableCustomHotkeys.checked = store.get(settings.enableCustomHotkeys);
|
||||||
enableDiscord.checked = store.get(settings.enableDiscord);
|
enableDiscord.checked = store.get(settings.enableDiscord);
|
||||||
|
minimizeOnClose.checked = store.get(settings.minimizeOnClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -80,6 +81,7 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
port = get("port");
|
port = get("port");
|
||||||
menuBar = get("menuBar");
|
menuBar = get("menuBar");
|
||||||
trayIcon = get("trayIcon");
|
trayIcon = get("trayIcon");
|
||||||
|
minimizeOnClose = get("minimizeOnClose");
|
||||||
mpris = get("mprisCheckbox");
|
mpris = get("mprisCheckbox");
|
||||||
enableCustomHotkeys = get("enableCustomHotkeys");
|
enableCustomHotkeys = get("enableCustomHotkeys");
|
||||||
enableDiscord = get("enableDiscord");
|
enableDiscord = get("enableDiscord");
|
||||||
@ -95,4 +97,5 @@ window.addEventListener("DOMContentLoaded", () => {
|
|||||||
addInputListener(mpris, settings.mpris);
|
addInputListener(mpris, settings.mpris);
|
||||||
addInputListener(enableCustomHotkeys, settings.enableCustomHotkeys);
|
addInputListener(enableCustomHotkeys, settings.enableCustomHotkeys);
|
||||||
addInputListener(enableDiscord, settings.enableDiscord);
|
addInputListener(enableDiscord, settings.enableDiscord);
|
||||||
|
addInputListener(minimizeOnClose, settings.minimizeOnClose);
|
||||||
});
|
});
|
||||||
|
@ -80,6 +80,16 @@
|
|||||||
<span class="slider round"></span>
|
<span class="slider round"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="option">
|
||||||
|
<h4>Minimize on Close</h4>
|
||||||
|
<p>
|
||||||
|
Minimize window on close instead <br />
|
||||||
|
</p>
|
||||||
|
<label class="switch">
|
||||||
|
<input id="minimizeOnClose" type="checkbox">
|
||||||
|
<span class="slider round"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div class="option">
|
<div class="option">
|
||||||
<h4>Hotkeys</h4>
|
<h4>Hotkeys</h4>
|
||||||
<p>
|
<p>
|
||||||
|
@ -15,6 +15,7 @@ const store = new Store({
|
|||||||
port: 47836,
|
port: 47836,
|
||||||
},
|
},
|
||||||
trayIcon: true,
|
trayIcon: true,
|
||||||
|
minimizeOnClose : false,
|
||||||
mpris: false,
|
mpris: false,
|
||||||
enableCustomHotkeys: false,
|
enableCustomHotkeys: false,
|
||||||
enableDiscord: false,
|
enableDiscord: false,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
const { Tray } = require("electron");
|
const { Tray, app } = require("electron");
|
||||||
const { getMenu } = require("./menu");
|
const { Menu } = require("electron");
|
||||||
|
const { getMenu, mainMenu } = require("./menu");
|
||||||
|
const { store, settings } = require("./settings");
|
||||||
const trayModule = {};
|
const trayModule = {};
|
||||||
let tray;
|
let tray;
|
||||||
|
|
||||||
@ -7,16 +9,41 @@ trayModule.addTray = function (options = { icon: "" }) {
|
|||||||
tray = new Tray(options.icon);
|
tray = new Tray(options.icon);
|
||||||
};
|
};
|
||||||
|
|
||||||
trayModule.refreshTray = function () {
|
trayModule.refreshTray = function (mainWindow) {
|
||||||
if (!tray) {
|
if (!tray) {
|
||||||
trayModule.addTray();
|
trayModule.addTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
tray.on("click", function (e) {
|
tray.on("click", function (e) {
|
||||||
// do nothing on click
|
if (mainWindow) {
|
||||||
|
mainWindow.show();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tray.setToolTip("Tidal-hifi");
|
tray.setToolTip("Tidal-hifi");
|
||||||
|
|
||||||
|
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());
|
tray.setContextMenu(getMenu());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = trayModule;
|
module.exports = trayModule;
|
||||||
|
Loading…
Reference in New Issue
Block a user