Simplify tray's code

This commit is contained in:
smartfrigde 2023-06-11 17:18:00 +02:00
parent dcc28fe381
commit 359f2174b7

View file

@ -27,56 +27,6 @@ app.whenReady().then(async () => {
if (process.platform == "darwin" && trayPath.getSize().height > 22) trayPath = trayPath.resize({height: 22});
if (await getConfig("tray")) {
let clientName = (await getConfig("clientName")) ?? "ArmCord";
if ((await getConfig("windowStyle")) == "basic") {
tray = new Tray(trayPath);
function contextMenu(): Electron.Menu {
if (finishedSetup == false) {
return Menu.buildFromTemplate([
{
label: `Finish the setup first!`,
enabled: false
},
{
label: `Quit ${clientName}`,
async click() {
fs.unlink(await getConfigLocation(), (err) => {
if (err) throw err;
console.log('Closed during setup. "settings.json" was deleted');
app.quit();
});
}
}
]);
} else {
return Menu.buildFromTemplate([
{
label: `Open ${clientName}`,
click() {
mainWindow.show();
}
},
{
label: `Quit ${clientName}`,
click() {
let [width, height] = mainWindow.getSize();
setWindowState({
width,
height,
isMaximized: mainWindow.isMaximized(),
x: mainWindow.getPosition()[0],
y: mainWindow.getPosition()[1]
});
app.quit();
}
}
]);
}
}
tray.setToolTip(clientName);
tray.setContextMenu(contextMenu);
} else {
tray = new Tray(trayPath);
if (finishedSetup == false) {
const contextMenu = Menu.buildFromTemplate([
@ -137,7 +87,6 @@ app.whenReady().then(async () => {
]);
tray.setContextMenu(contextMenu);
}
}
tray.setToolTip(clientName);
tray.on("click", function () {
mainWindow.show();