From def95f835a203a5edfa2195e8ff47249d313c500 Mon Sep 17 00:00:00 2001 From: everoddandeven Date: Sat, 12 Oct 2024 14:28:16 +0200 Subject: [PATCH] Window and tray icon implemetation --- app/main.ts | 50 ++++++++++++++++++- app/package.json | 11 ++-- package.json | 13 ++--- .../components/navbar/navbar.component.html | 2 +- 4 files changed, 62 insertions(+), 14 deletions(-) diff --git a/app/main.ts b/app/main.ts index d9901ec..f819c27 100644 --- a/app/main.ts +++ b/app/main.ts @@ -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); }) diff --git a/app/package.json b/app/package.json index 6fe9d2a..a8b0856 100644 --- a/app/package.json +++ b/app/package.json @@ -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": { diff --git a/package.json b/package.json index bbf709f..bbfebe4 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/app/shared/components/navbar/navbar.component.html b/src/app/shared/components/navbar/navbar.component.html index 3c0ec42..9482247 100644 --- a/src/app/shared/components/navbar/navbar.component.html +++ b/src/app/shared/components/navbar/navbar.component.html @@ -19,7 +19,7 @@ -->