Skip to content

Commit

Permalink
feat: wip context menus
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 14, 2021
1 parent 1e33a1c commit b272af3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import { remote } from 'electron';
import { useClipboard } from '@blockstack/ui';
import { Transaction } from '@blockstack/stacks-blockchain-api-types';

Expand Down Expand Up @@ -29,46 +28,39 @@ interface TxListContextMenu {
}

export function createTxListContextMenu(event: Event, { tx, copy }: TxListContextMenu) {
// event.preventDefault();
// const { Menu, MenuItem } = remote;
// const menu = new Menu();
// const menuItems: Electron.MenuItemConstructorOptions[] = [
// {
// label: 'Copy to clipboard',
// enabled: false,
// },
// { type: 'separator' },
// {
// label: 'Transaction ID',
// click: () => copy.txid.onCopy(),
// },
// {
// label: 'Recipient address',
// visible: !!getRecipientAddress(tx),
// click: () => copy.recipientAddress.onCopy(),
// },
// {
// label: 'Memo',
// visible: hasMemo(tx),
// click: () => copy.memo.onCopy(),
// },
// {
// label: 'Timestamp',
// click: () => copy.date.onCopy(),
// },
// {
// label: 'Transaction (as JSON)',
// click: () => copy.txDetails.onCopy(),
// },
// {
// label: 'Explorer link',
// click: () => copy.explorerLink.onCopy(),
// },
// ];
// menuItems.forEach(item => menu.append(new MenuItem(item)));
// menu.popup({ window: remote.getCurrentWindow() });
// menu.once('menu-will-close', () => {
// // `destroy` call untyped
// (menu as any).destroy();
// });
event.preventDefault();
const menuItems: Electron.MenuItemConstructorOptions[] = [
{
label: 'Copy to clipboard',
enabled: false,
},
{ type: 'separator' },
{
label: 'Transaction ID',
click: () => copy.txid.onCopy(),
},
{
label: 'Recipient address',
visible: !!getRecipientAddress(tx),
click: () => copy.recipientAddress.onCopy(),
},
{
label: 'Memo',
visible: hasMemo(tx),
click: () => copy.memo.onCopy(),
},
{
label: 'Timestamp',
click: () => copy.date.onCopy(),
},
{
label: 'Transaction (as JSON)',
click: () => copy.txDetails.onCopy(),
},
{
label: 'Explorer link',
click: () => copy.explorerLink.onCopy(),
},
];
api.contextMenu(menuItems);
}
16 changes: 13 additions & 3 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import 'core-js/stable';
import 'regenerator-runtime/runtime';
import path from 'path';
import { app, BrowserWindow, ipcMain } from 'electron';
import { app, BrowserWindow, ipcMain, Menu, MenuItem } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import windowState from 'electron-window-state';
Expand Down Expand Up @@ -96,7 +96,7 @@ const createWindow = async () => {
mainWindowState.manage(mainWindow);

if (process.env.NODE_ENV === 'development' && process.env.DEBUG_PROD !== 'true') {
void mainWindow.loadURL(`file://${__dirname}/app-dev.html`);
void mainWindow.loadFile(`app-dev.html`);
}

if (process.env.NODE_ENV === 'production' || process.env.DEBUG_PROD === 'true') {
Expand Down Expand Up @@ -182,6 +182,16 @@ ipcMain.handle('derive-key', async (_e, args) => {
return deriveKey(args);
});

ipcMain.handle('reload-app', _e => {
ipcMain.handle('reload-app', () => {
mainWindow?.reload();
});

ipcMain.on('context-menu-open', (_e, { menuItems }) => {
const menu = new Menu();
menuItems.forEach((item: Electron.MenuItemConstructorOptions) => menu.append(new MenuItem(item)));
menu.popup({ window: mainWindow?.getParentWindow() });
menu.once('menu-will-close', () => {
// `destroy` call untyped
(menu as any).destroy();
});
});
4 changes: 3 additions & 1 deletion app/preload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const { contextBridge, ipcRenderer, app, shell, remote } = require('electron');
const { contextBridge, ipcRenderer, app, shell } = require('electron');

const TransportNodeHid = require('@ledgerhq/hw-transport-node-hid').default;

Expand Down Expand Up @@ -75,4 +75,6 @@ contextBridge.exposeInMainWorld('api', {
};
},
},

contextMenu: menuItems => ipcRenderer.send('context-menu-open', { menuItems }),
});
2 changes: 2 additions & 0 deletions app/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ declare const api: {

reloadApp(): void;

contextMenu(menuItems: any[]): void;

nodeHid: {
listen: typeof import('@ledgerhq/hw-transport').default['listen'];
open({
Expand Down

0 comments on commit b272af3

Please sign in to comment.