2022-07-04 14:39:22 +00:00
|
|
|
import * as fs from "fs";
|
2022-08-22 09:24:55 +00:00
|
|
|
import {app, Menu, Tray, nativeImage} from "electron";
|
|
|
|
import {mainWindow} from "./window";
|
2022-09-25 18:30:09 +00:00
|
|
|
import {getConfig, getConfigLocation, setWindowState, getDisplayVersion} from "./utils";
|
2022-03-04 17:53:18 +00:00
|
|
|
import * as path from "path";
|
2022-08-22 09:24:55 +00:00
|
|
|
import {createSettingsWindow} from "./settings/main";
|
2022-08-25 12:57:28 +00:00
|
|
|
export let tray: any = null;
|
2022-04-20 19:50:23 +00:00
|
|
|
app.whenReady().then(async () => {
|
2022-08-22 09:24:55 +00:00
|
|
|
let finishedSetup = await getConfig("doneSetup");
|
2022-07-11 17:13:52 +00:00
|
|
|
var trayIcon = (await getConfig("trayIcon")) ?? "ac_plug_colored";
|
|
|
|
let trayPath = nativeImage.createFromPath(path.join(__dirname, "../", `/assets/${trayIcon}.png`));
|
2022-09-25 18:30:09 +00:00
|
|
|
let trayVerIcon;
|
|
|
|
trayVerIcon = function () {
|
|
|
|
if (process.platform == "win32") {
|
|
|
|
return trayPath.resize({height: 16});
|
|
|
|
} else if (process.platform == "darwin") {
|
|
|
|
return trayPath.resize({height: 18});
|
|
|
|
} else if (process.platform == "linux") {
|
|
|
|
return trayPath.resize({height: 24});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-08 15:43:08 +00:00
|
|
|
if (process.platform == "darwin" && trayPath.getSize().height > 22) trayPath = trayPath.resize({height: 22});
|
|
|
|
|
2022-07-04 14:39:22 +00:00
|
|
|
if ((await getConfig("windowStyle")) == "basic") {
|
|
|
|
var clientName = (await getConfig("clientName")) ?? "ArmCord";
|
2022-07-11 17:13:52 +00:00
|
|
|
tray = new Tray(trayPath);
|
2022-07-04 14:39:22 +00:00
|
|
|
const contextMenu = function () {
|
|
|
|
if (finishedSetup == false) {
|
|
|
|
return Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: `Finish the setup first!`,
|
|
|
|
enabled: false
|
2022-10-08 15:43:08 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-04 14:39:22 +00:00
|
|
|
label: `Quit ${clientName}`,
|
|
|
|
click: async function () {
|
|
|
|
fs.unlink(await getConfigLocation(), (err) => {
|
2022-10-08 15:43:08 +00:00
|
|
|
if (err) throw err;
|
|
|
|
|
2022-07-04 14:39:22 +00:00
|
|
|
console.log('Closed during setup. "settings.json" was deleted');
|
|
|
|
app.quit();
|
2022-08-22 09:24:55 +00:00
|
|
|
});
|
2022-07-04 14:39:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: `Open ${clientName}`,
|
|
|
|
click: function () {
|
|
|
|
mainWindow.show();
|
|
|
|
}
|
2022-10-08 15:43:08 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-04 14:39:22 +00:00
|
|
|
label: `Quit ${clientName}`,
|
|
|
|
click: function () {
|
2022-08-22 09:24:55 +00:00
|
|
|
let [width, height] = mainWindow.getSize();
|
2022-09-25 18:30:09 +00:00
|
|
|
setWindowState({width: width, height: height, isMaximized: mainWindow.isMaximized()});
|
2022-07-04 14:39:22 +00:00
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
2022-03-04 17:53:18 +00:00
|
|
|
}
|
2022-08-22 09:24:55 +00:00
|
|
|
};
|
2022-04-20 19:50:23 +00:00
|
|
|
|
2022-07-04 14:39:22 +00:00
|
|
|
tray.setToolTip(clientName);
|
2022-04-20 19:50:23 +00:00
|
|
|
tray.setContextMenu(contextMenu);
|
|
|
|
} else {
|
2022-07-04 14:39:22 +00:00
|
|
|
var clientName = (await getConfig("clientName")) ?? "ArmCord";
|
2022-07-11 17:13:52 +00:00
|
|
|
tray = new Tray(trayPath);
|
2022-07-04 14:39:22 +00:00
|
|
|
if (finishedSetup == false) {
|
|
|
|
const contextMenu = Menu.buildFromTemplate([
|
|
|
|
{
|
|
|
|
label: `Finish the setup first!`,
|
|
|
|
enabled: false
|
2022-10-08 15:43:08 +00:00
|
|
|
},
|
|
|
|
{
|
2022-07-04 14:39:22 +00:00
|
|
|
label: `Quit ${clientName}`,
|
|
|
|
click: async function () {
|
|
|
|
fs.unlink(await getConfigLocation(), (err) => {
|
2022-10-08 15:43:08 +00:00
|
|
|
if (err) throw err;
|
|
|
|
|
2022-07-04 14:39:22 +00:00
|
|
|
console.log('Closed during setup. "settings.json" was deleted');
|
|
|
|
app.quit();
|
2022-08-22 09:24:55 +00:00
|
|
|
});
|
2022-07-04 14:39:22 +00:00
|
|
|
}
|
2022-04-20 19:50:23 +00:00
|
|
|
}
|
2022-07-04 14:39:22 +00:00
|
|
|
]);
|
2022-08-22 09:24:55 +00:00
|
|
|
tray.setContextMenu(contextMenu);
|
|
|
|
} else {
|
|
|
|
const contextMenu = Menu.buildFromTemplate([
|
|
|
|
{
|
2022-09-25 18:30:09 +00:00
|
|
|
label: `${clientName} ` + getDisplayVersion(),
|
|
|
|
icon: trayVerIcon(),
|
2022-08-22 09:24:55 +00:00
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "separator"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: `Open ${clientName}`,
|
|
|
|
click: function () {
|
|
|
|
mainWindow.show();
|
2022-07-04 14:39:22 +00:00
|
|
|
}
|
2022-08-22 09:24:55 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Open Settings",
|
|
|
|
click: function () {
|
|
|
|
createSettingsWindow();
|
|
|
|
}
|
2022-10-08 15:43:08 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-22 09:24:55 +00:00
|
|
|
label: "Support Discord Server",
|
|
|
|
click: function () {
|
|
|
|
mainWindow.show();
|
|
|
|
mainWindow.loadURL("https://discord.gg/TnhxcqynZ2");
|
|
|
|
}
|
2022-10-08 15:43:08 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-22 09:24:55 +00:00
|
|
|
type: "separator"
|
2022-10-08 15:43:08 +00:00
|
|
|
},
|
|
|
|
{
|
2022-08-22 09:24:55 +00:00
|
|
|
label: `Quit ${clientName}`,
|
|
|
|
click: function () {
|
|
|
|
app.quit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
tray.setContextMenu(contextMenu);
|
2022-07-04 14:39:22 +00:00
|
|
|
}
|
2022-10-08 15:43:08 +00:00
|
|
|
}
|
|
|
|
tray.setToolTip(clientName);
|
2022-08-22 09:24:55 +00:00
|
|
|
tray.on("click", function () {
|
|
|
|
mainWindow.show();
|
|
|
|
});
|
|
|
|
});
|