Skip to content

Commit

Permalink
fix: yolo
Browse files Browse the repository at this point in the history
  • Loading branch information
truemiller committed Sep 30, 2024
1 parent e4ee9f6 commit 03bdef5
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 118 deletions.
20 changes: 15 additions & 5 deletions electron/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["prettier"],
"ignorePatterns": [".next/"],
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"plugins": [
"prettier"
],
// "ignorePatterns": [".next/"],
"rules": {
"prettier/prettier": [
"error",
Expand All @@ -11,7 +16,12 @@
"singleQuote": true
}
],
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
"no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_"
}
]
},
"parserOptions": {
"ecmaVersion": "latest",
Expand All @@ -21,4 +31,4 @@
"node": true,
"es6": true
}
}
}
2 changes: 1 addition & 1 deletion electron/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"exclude": [
"node_modules",
"**/node_modules/*",
"main.js" // You mentioned fixing this in the future
// "main.js" // You mentioned fixing this in the future
]
}

50 changes: 22 additions & 28 deletions electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
const { default: next } = require('next');
const next = require('next');
const http = require('http');
const AdmZip = require('adm-zip');

Expand Down Expand Up @@ -73,6 +73,12 @@ let tray = null;

let operateDaemon, operateDaemonPid, nextAppProcess, nextAppProcessPid;

// @ts-ignore - Workaround for the missing type definitions
const nextApp = next({
dev: false,
dir: path.join(__dirname),
});

const getActiveWindow = () => splashWindow ?? mainWindow;

function showNotification(title, body) {
Expand Down Expand Up @@ -314,21 +320,7 @@ async function launchDaemonDev() {

async function launchNextApp() {
logger.electron('Launching Next App');
const nextApp = next({
dev: false,
dir: path.join(__dirname),
port: appConfig.ports.prod.next,
// env: {
// GNOSIS_RPC:
// process.env.NODE_ENV === 'production'
// ? process.env.FORK_URL
// : process.env.DEV_RPC,
// NEXT_PUBLIC_BACKEND_PORT:
// process.env.NODE_ENV === 'production'
// ? appConfig.ports.prod.operate
// : appConfig.ports.dev.operate,
// },
});

logger.electron('Preparing Next App');
await nextApp.prepare();

Expand All @@ -351,15 +343,15 @@ async function launchNextApp() {

async function launchNextAppDev() {
await new Promise(function (resolve, _reject) {
process.env.NEXT_PUBLIC_BACKEND_PORT = appConfig.ports.dev.operate; // must set next env var to connect to backend
process.env.NEXT_PUBLIC_BACKEND_PORT = `${appConfig.ports.dev.operate}`; // must set next env var to connect to backend
nextAppProcess = spawn(
'yarn',
['dev:frontend', '--port', appConfig.ports.dev.next],
['dev:frontend', '--port', `${appConfig.ports.dev.next}`],
{
shell: true,
env: {
...process.env,
NEXT_PUBLIC_BACKEND_PORT: appConfig.ports.dev.operate,
NEXT_PUBLIC_BACKEND_PORT: `${appConfig.ports.dev.operate}`,
},
},
);
Expand Down Expand Up @@ -439,19 +431,20 @@ ipcMain.on('check', async function (event, _argument) {
await launchNextAppDev();
} else {
event.sender.send('response', 'Starting Pearl Daemon');
// await launchDaemon();

await launchDaemon();
event.sender.send('response', 'Starting Frontend Server');
const frontendPortAvailable = await isPortAvailable(
appConfig.ports.prod.next,
);
if (!frontendPortAvailable) {
appConfig.ports.prod.next = await findAvailablePort({
...PORT_RANGE,
startPort: PORT_RANGE.startPort,
endPort: PORT_RANGE.endPort,
excludePorts: [appConfig.ports.prod.operate],
});
}
await launchNextApp();
await launchNextApp().catch((e) => logger.electron(JSON.stringify(e)));
logger.electron('Frontend server started');
}

event.sender.send('response', 'Launching App');
Expand Down Expand Up @@ -535,11 +528,12 @@ ipcMain.on('open-path', (_, filePath) => {
* If the file path does not exist, it returns null.
* If no file path is provided, it sanitizes the provided data directly.
* The sanitized log data is then written to the destination path.
* @param {Object} options - The options for sanitizing logs.
* @param {string} options.name - The name of the log file.
* @param {string} options.filePath - The file path to read the log data from.
* @param {string} options.data - The log data to sanitize if no file path is provided.
* @param {string} options.destPath - The destination path where the logs should be stored after sanitization.
* @param {{
* name: string,
* filePath?: string,
* data?: string,
* destPath?: string,
* }} options - The options for sanitizing logs.
* @returns {string|null} - The file path of the sanitized log data, or null if the file path does not exist.
*/
function sanitizeLogs({
Expand Down
7 changes: 0 additions & 7 deletions electron/ports.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
const net = require('net');
const { ERROR_ADDRESS_IN_USE } = require('./constants');

/**
* Finds an available port within the specified range, excluding specified ports.
* @param {number} startPort - The start of the port range.
* @param {number} endPort - The end of the port range.
* @param {Array<number>} excludePorts - An array of ports to be skipped.
* @returns {Promise<number>} The first available port found within the range that's not excluded.
*/
function findAvailablePort({ startPort, endPort, excludePorts = [] }) {
return new Promise((resolve, reject) => {
let currentPort = startPort;
Expand Down
10 changes: 4 additions & 6 deletions electron/processes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ function killProcesses(pid) {

// Array of PIDs to kill, starting with the children
const pidsToKill = children.map((p) => p.PID);
logger.info("Pids to kill " + JSON.stringify(pidsToKill));
logger.info('Pids to kill ' + JSON.stringify(pidsToKill));

const killCommand = isWindows ? windowsKillCommand : unixKillCommand;

let errors = [];
for (const ppid of pidsToKill) {
logger.info("kill: " + ppid);
logger.info('kill: ' + ppid);
exec(`${killCommand} ${ppid}`, (err) => {
logger.error("Pids to kill error:" + err);
logger.error('Pids to kill error:' + err);
if (
err?.message?.includes(isWindows ? 'not found' : 'No such process')
) {
Expand All @@ -36,9 +36,7 @@ function killProcesses(pid) {

if (errors.length === 0) {
reject(errors);


} else resolve();
} else resolve();
});
});
}
Expand Down
2 changes: 2 additions & 0 deletions electron/store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-check
const Store = require('electron-store');

const { logger } = require('./logger');
Expand Down Expand Up @@ -49,6 +50,7 @@ const migrations = {
* @returns {Promise<void>} - A promise that resolves once the store is set up.
*/
const setupStore = async (ipcMain, mainWindow) => {
logger.electron('Setting up Electron store');
const store = new Store({
schema,
migrations,
Expand Down
6 changes: 3 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"ethers": "5.7.2",
"ethers-multicall": "^0.2.3",
"lodash": "^4.17.21",
"next": "^14.2.3",
"react": "^18.3.1",
"next": "==14.2.3",
"react": "==18.3.1",
"react-canvas-confetti": "1.2.1",
"react-dom": "^18.3.1",
"react-dom": "==18.3.1",
"sass": "^1.72.0",
"styled-components": "^6.1.8",
"usehooks-ts": "^2.14.0"
Expand Down
6 changes: 3 additions & 3 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4564,7 +4564,7 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==

next@^14.2.3:
next@==14.2.3:
version "14.2.3"
resolved "https://registry.yarnpkg.com/next/-/next-14.2.3.tgz#f117dd5d5f20c307e7b8e4f9c1c97d961008925d"
integrity sha512-dowFkFTR8v79NPJO4QsBUtxv0g9BrS/phluVpMAt2ku7H+cbcBJlopXjkWlwxrk/xGqMemr7JkGPGemPrLLX7A==
Expand Down Expand Up @@ -5300,7 +5300,7 @@ [email protected]:
"@types/canvas-confetti" "1.4.0"
canvas-confetti "1.4.0"

react-dom@^18.3.1:
react-dom@==18.3.1:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.3.1.tgz#c2265d79511b57d479b3dd3fdfa51536494c5cb4"
integrity sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==
Expand All @@ -5323,7 +5323,7 @@ react-is@^18.0.0, react-is@^18.2.0:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==

react@^18.3.1:
react@==18.3.1:
version "18.3.1"
resolved "https://registry.yarnpkg.com/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891"
integrity sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
"ethers": "5.7.2",
"ethers-multicall": "^0.2.3",
"lodash": "^4.17.21",
"next": "^14.2.3",
"next": "==14.2.3",
"ps-tree": "^1.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"sass": "^1.72.0",
"styled-components": "^6.1.8",
"sudo-prompt": "9.2.1",
"usehooks-ts": "^2.14.0",
"net": "^1.0.2",
"winston": "^3.13.0"
},
"devDependencies": {
Expand All @@ -35,7 +36,6 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"hardhat": "==2.17.1",
"net": "^1.0.2",
"prettier": "^3.2.5"
},
"main": "electron/main.js",
Expand Down
Loading

0 comments on commit 03bdef5

Please sign in to comment.