mirror of
https://github.com/everoddandeven/monerod-gui.git
synced 2025-01-03 09:29:36 +00:00
Window and tray icon implemetation
This commit is contained in:
parent
7f47295eb7
commit
def95f835a
4 changed files with 62 additions and 14 deletions
50
app/main.ts
50
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 { ChildProcessWithoutNullStreams, spawn } from 'child_process';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
@ -12,12 +12,43 @@ import * as os from 'os';
|
||||||
const bz2 = require('unbzip2-stream');
|
const bz2 = require('unbzip2-stream');
|
||||||
|
|
||||||
let win: BrowserWindow | null = null;
|
let win: BrowserWindow | null = null;
|
||||||
|
let isQuitting: boolean = false;
|
||||||
|
|
||||||
const args = process.argv.slice(1),
|
const args = process.argv.slice(1),
|
||||||
serve = args.some(val => val === '--serve');
|
serve = args.some(val => val === '--serve');
|
||||||
|
|
||||||
function createWindow(): BrowserWindow {
|
function createWindow(): BrowserWindow {
|
||||||
|
|
||||||
const size = screen.getPrimaryDisplay().workAreaSize;
|
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.
|
// Create the browser window.
|
||||||
win = new BrowserWindow({
|
win = new BrowserWindow({
|
||||||
|
@ -33,10 +64,11 @@ function createWindow(): BrowserWindow {
|
||||||
devTools: true,
|
devTools: true,
|
||||||
},
|
},
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
icon: path.join(__dirname, '../src/assets/icons/favicon.ico')
|
icon: wdwIcon
|
||||||
});
|
});
|
||||||
|
|
||||||
win.webContents.openDevTools();
|
win.webContents.openDevTools();
|
||||||
|
//win.setIcon()
|
||||||
|
|
||||||
if (serve) {
|
if (serve) {
|
||||||
const debug = require('electron-debug');
|
const debug = require('electron-debug');
|
||||||
|
@ -57,6 +89,16 @@ function createWindow(): BrowserWindow {
|
||||||
win.loadURL(url.href);
|
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.
|
// Emitted when the window is closed.
|
||||||
win.on('closed', () => {
|
win.on('closed', () => {
|
||||||
// Dereference the window object, usually you would store window
|
// 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[]) => {
|
ipcMain.handle('start-monerod', (event, configFilePath: string[]) => {
|
||||||
startMoneroDaemon(configFilePath);
|
startMoneroDaemon(configFilePath);
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "angular-electron",
|
"name": "monerod-gui",
|
||||||
"description": "Angular Electron sample",
|
"icon": "./assets/icons/favicon.ico",
|
||||||
|
"description": "Monero Daemon GUI",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Maxime GRIS",
|
"name": "everoddandeven",
|
||||||
"email": "maxime.gris@gmail.com"
|
"email": "everoddandeven@protonmail.com"
|
||||||
},
|
},
|
||||||
"version": "14.0.1",
|
"version": "0.1.0",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
13
package.json
13
package.json
|
@ -1,11 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "angular-electron",
|
"name": "monerod-gui",
|
||||||
"version": "14.0.1",
|
"version": "0.1.0",
|
||||||
"description": "Angular 17 with Electron 30 (Typescript + SASS + Hot Reload)",
|
"description": "Monero daemon GUI",
|
||||||
"homepage": "https://github.com/maximegris/angular-electron",
|
"icon": "./assets/icons/favicon.ico",
|
||||||
|
"homepage": "https://github.com/everoddandeven/monerod-gui",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Maxime GRIS",
|
"name": "everoddandeven",
|
||||||
"email": "maxime.gris@gmail.com"
|
"email": "everoddandeven@protonmail.com"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"angular",
|
"angular",
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
-->
|
-->
|
||||||
<header class="navbar sticky-top bg-dark d-flex flex-md-nowrap p-0 shadow" data-bs-theme="dark">
|
<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="#">
|
<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>
|
<strong>Monero Daemon</strong>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue