Skip to content

Commit

Permalink
Add Debug menu item to show the file of the current portfolio (#579)
Browse files Browse the repository at this point in the history
Can be useful for quickly changing the enable currencies and other things in the future.
  • Loading branch information
sindresorhus committed Dec 19, 2018
1 parent 3c8ad89 commit e1aae1f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
19 changes: 14 additions & 5 deletions app/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
const path = require('path');
const electron = require('electron');
const {runJS, is, appMenu, openUrlMenuItem, aboutMenuItem} = require('electron-util');
const ipc = require('electron-better-ipc');
const i18next = require('i18next');
const config = require('./config');
const {openGitHubIssue} = require('./util');
const {websiteUrl, repoUrl, appViews, supportedLanguagesWithNames} = require('./constants');
const {isDevelopment, isNightlyBuild} = require('./util-common');
const {translate} = require('./locale');
const {portfoliosDirectoryPath, getPortfolioFilePath} = require('./portfolio-util');

const {app, BrowserWindow, shell, clipboard, ipcMain: ipc, Menu} = electron;
const {app, BrowserWindow, shell, clipboard, Menu} = electron;
const t = translate('menu');

const sendAction = (action, data) => {
Expand Down Expand Up @@ -141,15 +143,22 @@ const createDebugMenu = () => {
type: 'separator',
},
{
label: 'Show Portfolios',
label: 'Show Settings',
click() {
shell.openItem(path.join(app.getPath('userData'), 'portfolios'));
config.openInEditor();
},
},
{
label: 'Show Settings',
label: 'Show Current Portfolio',
async click(menuItem, win) {
const id = await ipc.callRenderer(win, 'current-portfolio-id');
shell.openItem(getPortfolioFilePath(id));
},
},
{
label: 'Show Portfolios',
click() {
config.openInEditor();
shell.openItem(portfoliosDirectoryPath);
},
},
{
Expand Down
9 changes: 5 additions & 4 deletions app/portfolio-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ const {translate} = require('./locale');
const config = require('./config');
const {defaultEnabledCurrencies} = require('./constants');

const portfolioPath = path.join(app.getPath('userData'), 'portfolios');
const t = translate('login');

const portfoliosDirectoryPath = path.join(app.getPath('userData'), 'portfolios');
const idToFileName = id => `hyperdex-portfolio-${id}.json`;
const fileNameToId = fileName => fileName.replace(/^hyperdex-portfolio-/, '').replace(/\.json$/, '');
const idToFilePath = id => path.join(portfolioPath, idToFileName(id));
const idToFilePath = id => path.join(portfoliosDirectoryPath, idToFileName(id));
const generateId = name => `${slugify(name).slice(0, 40)}-${randomString(6)}`;

class IncorrectPasswordError extends Error {
Expand Down Expand Up @@ -94,7 +93,7 @@ const removeDnrCurrency = async id => {
const getPortfolios = async () => {
let portfolioFiles;
try {
portfolioFiles = await dir.promiseFiles(portfolioPath);
portfolioFiles = await dir.promiseFiles(portfoliosDirectoryPath);
} catch (error) {
if (error.code === 'ENOENT') {
return [];
Expand Down Expand Up @@ -147,4 +146,6 @@ module.exports = {
getPortfolios,
decryptSeedPhrase,
setCurrencies,
portfoliosDirectoryPath,
getPortfolioFilePath: idToFilePath,
};
2 changes: 2 additions & 0 deletions app/renderer/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ appContainer.subscribe(() => {
// We send an initial event so it can show the correct menu state after logging out
ipc.send('app-container-state-updated', appContainer.state);

ipc.answerMain('current-portfolio-id', () => appContainer.state.portfolio.id);

window.addEventListener('beforeunload', () => {
ipc.callMain('stop-marketmaker');
});
Expand Down

0 comments on commit e1aae1f

Please sign in to comment.