Add a Tray Icon

This commit is contained in:
smartfridge 2021-05-05 10:16:24 +02:00
parent cd56cfa8eb
commit 1c55ed7335
4 changed files with 45 additions and 113 deletions

48
main.js
View file

@ -1,15 +1,15 @@
// Modules to control application life and create native browser window
const { app, BrowserWindow, session } = require('electron')
const { app, BrowserWindow, session, Tray, Menu } = require('electron')
const path = require('path')
require("v8-compile-cache");
require("./utils/updater");
let mainWindow
require("./menu.js")
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
icon: __dirname + '/discord.ico',
icon: __dirname + "/discord.ico",
title: "ArmCord",
frame: false,
webPreferences: {
preload: path.join(__dirname, "preload.js"),
@ -17,21 +17,59 @@ function createWindow() {
nodeIntegration: false,
},
});
var appIcon = new Tray(__dirname + "/discord.ico");
mainWindow.webContents.userAgent =
"Mozilla/5.0 (X12; TempleOS MIPS) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; //to set
"Mozilla/5.0 (X12; FreeBSD x86) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"; //fake useragent
mainWindow.loadFile("index.html");
mainWindow.focus();
mainWindow.webContents.on("new-window", function (e, url) {
e.preventDefault();
require("electron").shell.openExternal(url);
});
// Open the DevTools.
// mainWindow.webContents.openDevTools()
var contextMenu = Menu.buildFromTemplate([
{
label: "Show App",
click: function () {
mainWindow.show();
},
},
{
label: "Support Discord Server",
click: function () {
mainWindow.loadURL("https://discord.gg/F25bc4RYDt");
},
},
{
label: "Quit",
click: function () {
app.isQuiting = true;
app.quit();
},
},
]);
mainWindow.on("closed", () => {
appIcon.setContextMenu(contextMenu);
// Emitted when the window is closed.
mainWindow.on("close", function (event) {
mainWindow = null;
});
mainWindow.on("minimize", function (event) {
event.preventDefault();
mainWindow.hide();
});
mainWindow.on("show", function () {
appIcon.setHighlightMode("always");
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.

107
menu.js
View file

@ -1,107 +0,0 @@
const { app, Menu } = require("electron");
const isMac = process.platform === "darwin";
const template = [
// { role: 'appMenu' }
...(isMac
? [
{
label: app.name,
submenu: [
{ role: "about" },
{ type: "separator" },
{ role: "services" },
{ type: "separator" },
{ role: "hide" },
{ role: "hideothers" },
{ role: "unhide" },
{ type: "separator" },
{ role: "quit" },
],
},
]
: []),
// { role: 'fileMenu' }
{
label: "File",
submenu: [isMac ? { role: "close" } : { role: "quit" }],
},
// { role: 'editMenu' }
{
label: "Edit",
submenu: [
{ role: "undo" },
{ role: "redo" },
{ type: "separator" },
{ role: "cut" },
{ role: "copy" },
{ role: "paste" },
...(isMac
? [
{ role: "pasteAndMatchStyle" },
{ role: "delete" },
{ role: "selectAll" },
{ type: "separator" },
{
label: "Speech",
submenu: [{ role: "startSpeaking" }, { role: "stopSpeaking" }],
},
]
: [{ role: "delete" }, { type: "separator" }, { role: "selectAll" }]),
],
},
// { role: 'viewMenu' }
{
label: "View",
submenu: [
{ role: "reload" },
{ role: "forceReload" },
{ role: "toggleDevTools" },
{ type: "separator" },
{ role: "resetZoom" },
{ role: "zoomIn" },
{ role: "zoomOut" },
{ type: "separator" },
{ role: "togglefullscreen" },
],
},
// { role: 'windowMenu' }
{
label: "Window",
submenu: [
{ role: "minimize" },
{ role: "zoom" },
...(isMac
? [
{ type: "separator" },
{ role: "front" },
{ type: "separator" },
{ role: "window" },
]
: [{ role: "close" }]),
],
},
{
role: "help",
submenu: [
{
label: "Learn More",
click: async () => {
const { shell } = require("electron");
await shell.openExternal("https://github.com/smartfrigde/armcord");
},
},
{
label: "Support Server",
click: async () => {
const { shell } = require("electron");
await shell.openExternal("https://discord.gg/F25bc4RYDt");
},
},
],
},
];
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);

View file

@ -1,6 +1,6 @@
{
"name": "armcord",
"version": "2.2.0",
"version": "2.3.0",
"description": "ArmCord is a Discord client made for ARM Linux that allows you to customize your experience.",
"main": "main.js",
"scripts": {

View file

@ -5,6 +5,7 @@ const { remote } = require("electron");
window.addEventListener('DOMContentLoaded', () => {
new customTitlebar.Titlebar({
backgroundColor: customTitlebar.Color.fromHex("#202225"),
menu: false,
});
/**