Window and tray icon implemetation

This commit is contained in:
everoddandeven 2024-10-12 14:28:16 +02:00
parent 7f47295eb7
commit def95f835a
4 changed files with 62 additions and 14 deletions

View file

@ -1,4 +1,4 @@
import {app, BrowserWindow, ipcMain, screen, dialog } from 'electron';
import { app, BrowserWindow, ipcMain, screen, dialog, Tray, Menu, MenuItemConstructorOptions } from 'electron';
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import * as path from 'path';
import * as fs from 'fs';
@ -12,12 +12,43 @@ import * as os from 'os';
const bz2 = require('unbzip2-stream');
let win: BrowserWindow | null = null;
let isQuitting: boolean = false;
const args = process.argv.slice(1),
serve = args.some(val => val === '--serve');
function createWindow(): BrowserWindow {
const size = screen.getPrimaryDisplay().workAreaSize;
const wdwIcon = path.join(__dirname, 'assets/icons/monero-symbol-on-white-480.png');
const trayMenuTemplate: MenuItemConstructorOptions[] = [
{
id: "stopDaemon",
label: "Stop",
toolTip: "Stop monero daemon",
click: () => {
console.log("Clicked stop daemon tray icon menu");
}
},
{
id: "quitDaemon",
label: "Quit",
toolTip: "Quit monero daemon",
click: () => {
isQuitting = true;
app.quit();
console.log("Quit monero daemon");
}
}
];
const tray = new Tray(wdwIcon);
const trayMenu = Menu.buildFromTemplate(trayMenuTemplate);
tray.setContextMenu(trayMenu);
console.log(`createWindow(): icon = ${wdwIcon}`);
// Create the browser window.
win = new BrowserWindow({
@ -33,10 +64,11 @@ function createWindow(): BrowserWindow {
devTools: true,
},
autoHideMenuBar: true,
icon: path.join(__dirname, '../src/assets/icons/favicon.ico')
icon: wdwIcon
});
win.webContents.openDevTools();
//win.setIcon()
if (serve) {
const debug = require('electron-debug');
@ -57,6 +89,16 @@ function createWindow(): BrowserWindow {
win.loadURL(url.href);
}
win.on('close', (event) => {
if (!isQuitting) {
event.preventDefault();
win?.hide();
//event.returnValue = false;
}
return false;
});
// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
@ -301,6 +343,10 @@ try {
}
});
app.on('before-quit', () => {
isQuitting = true;
});
ipcMain.handle('start-monerod', (event, configFilePath: string[]) => {
startMoneroDaemon(configFilePath);
})

View file

@ -1,11 +1,12 @@
{
"name": "angular-electron",
"description": "Angular Electron sample",
"name": "monerod-gui",
"icon": "./assets/icons/favicon.ico",
"description": "Monero Daemon GUI",
"author": {
"name": "Maxime GRIS",
"email": "maxime.gris@gmail.com"
"name": "everoddandeven",
"email": "everoddandeven@protonmail.com"
},
"version": "14.0.1",
"version": "0.1.0",
"main": "main.js",
"private": true,
"dependencies": {

View file

@ -1,11 +1,12 @@
{
"name": "angular-electron",
"version": "14.0.1",
"description": "Angular 17 with Electron 30 (Typescript + SASS + Hot Reload)",
"homepage": "https://github.com/maximegris/angular-electron",
"name": "monerod-gui",
"version": "0.1.0",
"description": "Monero daemon GUI",
"icon": "./assets/icons/favicon.ico",
"homepage": "https://github.com/everoddandeven/monerod-gui",
"author": {
"name": "Maxime GRIS",
"email": "maxime.gris@gmail.com"
"name": "everoddandeven",
"email": "everoddandeven@protonmail.com"
},
"keywords": [
"angular",

View file

@ -19,7 +19,7 @@
-->
<header class="navbar sticky-top bg-dark d-flex flex-md-nowrap p-0 shadow" data-bs-theme="dark">
<span class="navbar-brand col-md-3 col-lg-3 me-0 px-3 fs-6 text-white" href="#">
<img class="m-1" src="/assets/icons/monero-symbol-on-white-480.png" width="40" height="40">
<img class="m-1" src="assets/icons/monero-symbol-on-white-480.png" width="40" height="40">
<strong>Monero Daemon</strong>
</span>