Skip to content

Commit e1aae1f

Browse files
authored
Add Debug menu item to show the file of the current portfolio (#579)
Can be useful for quickly changing the enable currencies and other things in the future.
1 parent 3c8ad89 commit e1aae1f

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

app/menu.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
const path = require('path');
33
const electron = require('electron');
44
const {runJS, is, appMenu, openUrlMenuItem, aboutMenuItem} = require('electron-util');
5+
const ipc = require('electron-better-ipc');
56
const i18next = require('i18next');
67
const config = require('./config');
78
const {openGitHubIssue} = require('./util');
89
const {websiteUrl, repoUrl, appViews, supportedLanguagesWithNames} = require('./constants');
910
const {isDevelopment, isNightlyBuild} = require('./util-common');
1011
const {translate} = require('./locale');
12+
const {portfoliosDirectoryPath, getPortfolioFilePath} = require('./portfolio-util');
1113

12-
const {app, BrowserWindow, shell, clipboard, ipcMain: ipc, Menu} = electron;
14+
const {app, BrowserWindow, shell, clipboard, Menu} = electron;
1315
const t = translate('menu');
1416

1517
const sendAction = (action, data) => {
@@ -141,15 +143,22 @@ const createDebugMenu = () => {
141143
type: 'separator',
142144
},
143145
{
144-
label: 'Show Portfolios',
146+
label: 'Show Settings',
145147
click() {
146-
shell.openItem(path.join(app.getPath('userData'), 'portfolios'));
148+
config.openInEditor();
147149
},
148150
},
149151
{
150-
label: 'Show Settings',
152+
label: 'Show Current Portfolio',
153+
async click(menuItem, win) {
154+
const id = await ipc.callRenderer(win, 'current-portfolio-id');
155+
shell.openItem(getPortfolioFilePath(id));
156+
},
157+
},
158+
{
159+
label: 'Show Portfolios',
151160
click() {
152-
config.openInEditor();
161+
shell.openItem(portfoliosDirectoryPath);
153162
},
154163
},
155164
{

app/portfolio-util.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ const {translate} = require('./locale');
1212
const config = require('./config');
1313
const {defaultEnabledCurrencies} = require('./constants');
1414

15-
const portfolioPath = path.join(app.getPath('userData'), 'portfolios');
1615
const t = translate('login');
17-
16+
const portfoliosDirectoryPath = path.join(app.getPath('userData'), 'portfolios');
1817
const idToFileName = id => `hyperdex-portfolio-${id}.json`;
1918
const fileNameToId = fileName => fileName.replace(/^hyperdex-portfolio-/, '').replace(/\.json$/, '');
20-
const idToFilePath = id => path.join(portfolioPath, idToFileName(id));
19+
const idToFilePath = id => path.join(portfoliosDirectoryPath, idToFileName(id));
2120
const generateId = name => `${slugify(name).slice(0, 40)}-${randomString(6)}`;
2221

2322
class IncorrectPasswordError extends Error {
@@ -94,7 +93,7 @@ const removeDnrCurrency = async id => {
9493
const getPortfolios = async () => {
9594
let portfolioFiles;
9695
try {
97-
portfolioFiles = await dir.promiseFiles(portfolioPath);
96+
portfolioFiles = await dir.promiseFiles(portfoliosDirectoryPath);
9897
} catch (error) {
9998
if (error.code === 'ENOENT') {
10099
return [];
@@ -147,4 +146,6 @@ module.exports = {
147146
getPortfolios,
148147
decryptSeedPhrase,
149148
setCurrencies,
149+
portfoliosDirectoryPath,
150+
getPortfolioFilePath: idToFilePath,
150151
};

app/renderer/containers/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ appContainer.subscribe(() => {
322322
// We send an initial event so it can show the correct menu state after logging out
323323
ipc.send('app-container-state-updated', appContainer.state);
324324

325+
ipc.answerMain('current-portfolio-id', () => appContainer.state.portfolio.id);
326+
325327
window.addEventListener('beforeunload', () => {
326328
ipc.callMain('stop-marketmaker');
327329
});

0 commit comments

Comments
 (0)