Skip to content

Commit

Permalink
feat: speed improvements and portable systray menus
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 24, 2021
1 parent 9aebcef commit 2dd7501
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions packages/app-electron/src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import '@agoric/install-ses';
import { makeCapTP, E } from '@agoric/captp';
import { app, BrowserWindow, Menu, MenuItem, Tray } from 'electron';
import { app, BrowserWindow, Menu, shell, Tray } from 'electron';
import path from 'path';

// This is needed to map the Pledger systray to the signing certificate.
const TRAY_GUID = 'C728AAD2-DA20-421C-B534-97023DACF258';

const WALLET_PORT = 8000;

import { bootPlugin as bootAppPlugin } from '@pledger/plugin-agoric-app/src/server';

async function main(argv, isProduction) {
Expand All @@ -26,9 +29,13 @@ async function main(argv, isProduction) {
// Start the ag-solo running.
E(appPlugin).fork('Agoric', 'ag-solo', 'setup');

let exiting = false;
let quitting = false;
app.on('before-quit', () => {
// If they hit C-q, treat it as a full exit.
quitting = true;
});

let dashboardWindow = null;
app.dock && app.dock.hide();
const createDashboardWindow = async () => {
app.dock && app.dock.show();
if (dashboardWindow) {
Expand All @@ -46,10 +53,9 @@ async function main(argv, isProduction) {
},
});

// Dispose of the plugin when we're closed.
// dashboardWindow.on('closed', () => E(appPlugin).dispose());
// Just hide.
dashboardWindow.on('close', e => {
if (!exiting) {
if (!quitting) {
e.preventDefault();
dashboardWindow.hide();
app.dock && app.dock.hide();
Expand Down Expand Up @@ -82,23 +88,38 @@ async function main(argv, isProduction) {
const icon = process.platform === 'win32' ? 'agoric.ico' : 'agoric-systray.png';
appIcon = new Tray(`${__dirname}/../assets/${icon}`, TRAY_GUID);
const contextMenu = Menu.buildFromTemplate([
{ label: 'Open Agoric Wallet', click() {
E(appPlugin).fork('Wallet', 'agoric-cli', 'open');
{ label: 'Open Agoric Wallet', async click() {
const ac = await E(appPlugin).getAccessToken(WALLET_PORT);
shell.openExternal(`http://localhost:${WALLET_PORT}/wallet#accessToken=${ac}`);
} },
{ label: 'Agoric Console (REPL)', click() {
E(appPlugin).fork('Wallet', 'agoric-cli', 'open', '--repl=only');
{ label: 'Agoric Console (REPL)', async click() {
const ac = await E(appPlugin).getAccessToken(WALLET_PORT);
shell.openExternal(`http://localhost:${WALLET_PORT}/?w=0#accessToken=${ac}`);
} },
{ type: 'separator' },
{ label: 'Pledger Logs...', click: createDashboardWindow },
{ label: 'Pledger Dashboard...', click: createDashboardWindow },
{ type: 'separator' },
{ label: 'Quit Pledger', click() {
exiting = true;
E(appPlugin).dispose().finally(() => app.quit());
} },
]);

appIcon.setToolTip('Pledger Wallet');
appIcon.setContextMenu(contextMenu);
appIcon.on('click', () => appIcon.popUpContextMenu());

if (0) {
// Pop up the dashboard immediately.
createDashboardWindow();
} else {
// Hide the dock icon.
app.dock && app.dock.hide();
if (0) {
// Pop up the context menu for engagement.
const { x, y } = appIcon.getBounds();
appIcon.popUpContextMenu(contextMenu, { x, y });
}
}
};

// This method will be called when Electron has finished
Expand Down

0 comments on commit 2dd7501

Please sign in to comment.