armcord/src/tray.ts

129 lines
4.8 KiB
TypeScript
Raw Normal View History

import * as fs from "fs";
2022-06-16 15:31:42 +00:00
import { app, Menu, Tray } from "electron";
import { mainWindow } from "./window";
import { getConfig, getConfigLocation, setWindowState } from "./utils";
2022-03-04 17:53:18 +00:00
import * as path from "path";
2022-06-16 15:31:42 +00:00
import { createSettingsWindow } from "./settings/main";
2022-04-20 19:50:23 +00:00
let tray: any = null;
app.whenReady().then(async () => {
let finishedSetup = (await getConfig("doneSetup"));
if ((await getConfig("windowStyle")) == "basic") {
var clientName = (await getConfig("clientName")) ?? "ArmCord";
var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored";
tray = new Tray(path.join(__dirname, "../", `/assets/${trayIcon}.png`));
const contextMenu = function () {
if (finishedSetup == false) {
return Menu.buildFromTemplate([
{
label: `Finish the setup first!`,
enabled: false
},
{
label: `Quit ${clientName}`,
click: async function () {
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: function () {
mainWindow.show();
}
},
{
label: `Quit ${clientName}`,
click: function () {
let [width, height] = mainWindow.getSize()
setWindowState({
width: width,
height: height,
isMaximized: mainWindow.isMaximized()
})
app.quit();
}
}
]);
2022-03-04 17:53:18 +00:00
}
}
2022-04-20 19:50:23 +00:00
tray.setToolTip(clientName);
2022-04-20 19:50:23 +00:00
tray.setContextMenu(contextMenu);
} else {
var clientName = (await getConfig("clientName")) ?? "ArmCord";
var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored";
2022-05-22 14:46:18 +00:00
tray = new Tray(path.join(__dirname, "../", `/assets/${trayIcon}.png`));
if (finishedSetup == false) {
const contextMenu = Menu.buildFromTemplate([
{
label: `Finish the setup first!`,
enabled: false
},
{
label: `Quit ${clientName}`,
click: async function () {
fs.unlink(await getConfigLocation(), (err) => {
if (err) throw err;
console.log('Closed during setup. "settings.json" was deleted');
app.quit();
});
}
2022-04-20 19:50:23 +00:00
}
]);
tray.setContextMenu(contextMenu);
} else {
const contextMenu = Menu.buildFromTemplate([
{
label: `${clientName} ` + app.getVersion(),
enabled: false
},
{
type: "separator"
},
{
2022-07-05 16:34:53 +00:00
label: `Open ${clientName}`,
click: function () {
mainWindow.show();
}
},
{
label: "Open Settings",
click: function () {
createSettingsWindow();
}
},
{
label: "Support Discord Server",
click: function () {
mainWindow.show();
mainWindow.loadURL("https://discord.gg/TnhxcqynZ2");
}
},
{
type: "separator"
},
{
label: `Quit ${clientName}`,
click: function () {
app.quit();
}
}
]);
tray.setContextMenu(contextMenu);
2022-03-04 17:53:18 +00:00
}
}
2022-03-04 17:53:18 +00:00
tray.setToolTip(clientName);
tray.on('click', function(){
mainWindow.show()
});
2022-04-20 19:50:23 +00:00
}
);