Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
linting index.js.
Browse files Browse the repository at this point in the history
  • Loading branch information
davemfish committed Aug 9, 2020
1 parent 08df402 commit 039a723
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 51 deletions.
10 changes: 5 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
presets: [
"@babel/preset-env",
"@babel/preset-react"
],
'@babel/preset-env',
'@babel/preset-react',
],
plugins: [
"@babel/plugin-transform-runtime"
]
'@babel/plugin-transform-runtime',
],
};
67 changes: 27 additions & 40 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
"use strict";
const fs = require('fs');
const path = require('path');
const { remote, ipcRenderer } = require('electron'); // eslint-disable-line import/no-extraneous-dependencies
const { getLogger } = require('./logger')

const logger = getLogger(__filename.split('/').slice(-1)[0])

const isDevMode = remote.process.argv[2] == '--dev'
const isDevMode = remote.process.argv[2] === '--dev';
if (isDevMode) {
// in dev mode we can have babel transpile modules on import
require("@babel/register");
require('@babel/register'); // eslint-disable-line import/no-extraneous-dependencies
// load the '.env' file from the project root
const dotenv = require('dotenv');
const dotenv = require('dotenv'); // eslint-disable-line import/no-extraneous-dependencies
dotenv.config();
}

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _reactHotLoader = require("react-hot-loader");
const _interopRequireDefault = require('@babel/runtime/helpers/interopRequireDefault');
const react = _interopRequireDefault(require('react'));
const reactDom = _interopRequireDefault(require('react-dom'));

var _app = _interopRequireDefault(require("./app"));
const { fileRegistry } = require("./constants")
const app = require('./app');
const { fileRegistry } = require('./constants');

// Create a right-click menu
// TODO: Not sure if Inspect Element should be available in production
Expand All @@ -34,35 +24,32 @@ let rightClickPosition = null
const menu = new Menu();
menu.append(new MenuItem({
label: 'Inspect Element',
click: () => {
click: () => {
remote.getCurrentWindow().inspectElement(rightClickPosition.x, rightClickPosition.y)
}
}))
}));

window.addEventListener('contextmenu', (e) => {
e.preventDefault()
rightClickPosition = {x: e.x, y: e.y}
menu.popup({ window: remote.getCurrentWindow() })
}, false)

var render = async function render(investExe) {
_reactDom["default"].render(
_react["default"].createElement(
_reactHotLoader.AppContainer, null, _react["default"].createElement(
_app["default"], {
jobDatabase: fileRegistry.JOBS_DATABASE,
investExe: investExe })),
document.getElementById('App'));
e.preventDefault();
rightClickPosition = { x: e.x, y: e.y };
menu.popup({ window: remote.getCurrentWindow() });
}, false);

const render = async function render(investExe) {
reactDom.default.render(
react.default.createElement(
app.default, {
jobDatabase: fileRegistry.JOBS_DATABASE,
investExe: investExe,
}
),
document.getElementById('App')
);
};

ipcRenderer.on('variable-reply', (event, arg) => {
// render the App after receiving any critical data
// from the main process
render(arg.investExe)
render(arg.investExe);
})
ipcRenderer.send('variable-request', 'ping')

if (module.hot) {
logger.debug('if hot module');
module.hot.accept(render);
}
ipcRenderer.send('variable-request', 'ping');
1 change: 0 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ const createWindow = async () => {
default: installExtension, REACT_DEVELOPER_TOOLS
} = require('electron-devtools-installer');
await installExtension(REACT_DEVELOPER_TOOLS);
// enableLiveReload({ strategy: 'react-hmr' });
mainWindow.webContents.openDevTools();
}
});
Expand Down
9 changes: 4 additions & 5 deletions src/server_requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const HOSTNAME = 'http://localhost';
* @param {number} retries - number of recursive calls this function is allowed.
* @returns { Promise } resolves text indicating success.
*/
export function getFlaskIsReady(i = 0, retries = 11) {
export function getFlaskIsReady({ i = 0, retries = 21 } = {}) {
return (
fetch(`${HOSTNAME}:${PORT}/ready`, {
method: 'get',
Expand All @@ -24,11 +24,10 @@ export function getFlaskIsReady(i = 0, retries = 11) {
if (error.code === 'ECONNREFUSED') {
while (i < retries) {
i++;
// Try again after a short pause. 500ms works well in the
// context of flaskapp.test.js. Requiring 1 or 2 retries.
await new Promise((resolve) => setTimeout(resolve, 500));
// Try every 100ms, usually takes about 1 second to startup.
await new Promise((resolve) => setTimeout(resolve, 100));
logger.debug(`retry # ${i}`);
return await getFlaskIsReady(i);
return await getFlaskIsReady({ i: i, retries: retries });
}
logger.error(`Not able to connect to server after ${retries} tries.`);
logger.error(error.stack);
Expand Down

0 comments on commit 039a723

Please sign in to comment.