diff --git a/src/main.js b/src/main.js index d2e449d..9e14f93 100644 --- a/src/main.js +++ b/src/main.js @@ -154,7 +154,11 @@ export async function main() { const dataService = new DataService(configService); const dataMenu = new DataMenu(uiService, fsService, dataService); const feedbackService = new FeedbackService(); - const nodeStatusMenu = new NodeStatusMenu(uiService, dataService, new MenuLoop()); + const nodeStatusMenu = new NodeStatusMenu( + uiService, + dataService, + new MenuLoop(), + ); const mainMenu = new MainMenu( uiService, new MenuLoop(), diff --git a/src/services/configService.js b/src/services/configService.js index d17016b..471711d 100644 --- a/src/services/configService.js +++ b/src/services/configService.js @@ -60,7 +60,6 @@ export class ConfigService { this.config = defaultConfig; this.saveConfig(); } - } } catch (error) { console.error( diff --git a/src/services/dataService.js b/src/services/dataService.js index bb30262..0ca0739 100644 --- a/src/services/dataService.js +++ b/src/services/dataService.js @@ -45,14 +45,14 @@ export class DataService { debugInfo = async () => { const debug = this.getCodexDebug(); return await debug.info(); - } + }; localData = async () => { const data = this.getCodexData(); return await data.cids(); }; - getCodex = () =>{ + getCodex = () => { const config = this.configService.get(); const url = `http://localhost:${config.ports.apiPort}`; const codex = new Codex(url); @@ -63,7 +63,7 @@ export class DataService { return this.getCodex().data; }; - getCodexDebug = () =>{ + getCodexDebug = () => { return this.getCodex().debug; }; diff --git a/src/services/feedbackService.js b/src/services/feedbackService.js index 6e787f7..b233aec 100644 --- a/src/services/feedbackService.js +++ b/src/services/feedbackService.js @@ -2,9 +2,7 @@ import open from "open"; export class FeedbackService { openFeedbackPage = async () => { - const segments = [ - "https://tally.so/r/w2DlXb", - ]; + const segments = ["https://tally.so/r/w2DlXb"]; const url = segments.join(""); open(url); diff --git a/src/ui/dataMenu.js b/src/ui/dataMenu.js index 4749561..be871e5 100644 --- a/src/ui/dataMenu.js +++ b/src/ui/dataMenu.js @@ -40,33 +40,39 @@ export class DataMenu { try { const localData = await this.dataService.localData(); this.displayLocalData(localData); - } - catch (exception) { + } catch (exception) { this.ui.showErrorMessage("Failed to fetch local data: " + exception); } }; displayLocalData = (filesData) => { if (filesData.content && filesData.content.length > 0) { - this.ui.showInfoMessage(`Found ${filesData.content.length} local file(s)`); + this.ui.showInfoMessage( + `Found ${filesData.content.length} local file(s)`, + ); filesData.content.forEach((file, index) => { - const { cid, manifest } = file; - const { originalBytes, protected: isProtected, filename, mimetype } = manifest; + const { cid, manifest } = file; + const { + originalBytes, + protected: isProtected, + filename, + mimetype, + } = manifest; - const fileSize = (originalBytes / 1024).toFixed(2); + const fileSize = (originalBytes / 1024).toFixed(2); - this.ui.showInfoMessage( - `${chalk.cyan('File')} ${index + 1} of ${filesData.content.length}\n\n` + - `${chalk.cyan('Filename:')} ${filename}\n` + - `${chalk.cyan('CID:')} ${cid}\n` + - `${chalk.cyan('Size:')} ${fileSize} KB\n` + - `${chalk.cyan('MIME Type:')} ${mimetype}\n` + - `${chalk.cyan('Protected:')} ${isProtected ? chalk.green('Yes') : chalk.red('No')}`, - ); + this.ui.showInfoMessage( + `${chalk.cyan("File")} ${index + 1} of ${filesData.content.length}\n\n` + + `${chalk.cyan("Filename:")} ${filename}\n` + + `${chalk.cyan("CID:")} ${cid}\n` + + `${chalk.cyan("Size:")} ${fileSize} KB\n` + + `${chalk.cyan("MIME Type:")} ${mimetype}\n` + + `${chalk.cyan("Protected:")} ${isProtected ? chalk.green("Yes") : chalk.red("No")}`, + ); }); } else { - this.ui.showInfoMessage("Node contains no datasets."); + this.ui.showInfoMessage("Node contains no datasets."); } }; } diff --git a/src/ui/mainMenu.js b/src/ui/mainMenu.js index fc3772a..a1a8ab0 100644 --- a/src/ui/mainMenu.js +++ b/src/ui/mainMenu.js @@ -98,36 +98,44 @@ export class MainMenu { } }; - ifInstalled = async (call) => { - if (await this.isInstalled()) { - await call(); - } else { - this.ui.showInfoMessage("Codex is not yet installed."); - } - } - - ifNotInstalled = async (call) => { - if (!await this.isInstalled()) { - await call(); - } else { - this.ui.showInfoMessage("Codex is installed."); - } - } - - ifRunning = async (call) => { - if (await this.isRunning()) { - await call(); - } else { - this.ui.showInfoMessage("Codex is not yet running."); - } + ifInstalled = (call) => { + return async () => { + if (await this.isInstalled()) { + await call(); + } else { + this.ui.showInfoMessage("Codex is not yet installed."); + } + }; }; - ifNotRunning = async (call) => { - if (!await this.isRunning()) { - await call(); - } else { - this.ui.showInfoMessage("Codex is running."); - } + ifNotInstalled = (call) => { + return async () => { + if (!(await this.isInstalled())) { + await call(); + } else { + this.ui.showInfoMessage("Codex is installed."); + } + }; + }; + + ifRunning = (call) => { + return async () => { + if (await this.isRunning()) { + await call(); + } else { + this.ui.showInfoMessage("Codex is not yet running."); + } + }; + }; + + ifNotRunning = (call) => { + return async () => { + if (!(await this.isRunning())) { + await call(); + } else { + this.ui.showInfoMessage("Codex is running."); + } + }; }; isInstalled = async () => { @@ -135,6 +143,6 @@ export class MainMenu { }; isRunning = async () => { - return ((await this.processControl.getNumberOfCodexProcesses()) > 0); + return (await this.processControl.getNumberOfCodexProcesses()) > 0; }; } diff --git a/src/ui/nodeStatusMenu.js b/src/ui/nodeStatusMenu.js index b19b75e..556b586 100644 --- a/src/ui/nodeStatusMenu.js +++ b/src/ui/nodeStatusMenu.js @@ -19,13 +19,13 @@ export class NodeStatusMenu { if (isOnline) { this.showSuccessMessage( "Node is ONLINE & DISCOVERABLE", - "🔌 Node Status" - ) + "🔌 Node Status", + ); } else { this.showInfoMessage( "Node is ONLINE but has few peers", - "🔌 Node Status" - ) + "🔌 Node Status", + ); } await this.loop.showLoop(); @@ -51,31 +51,31 @@ export class NodeStatusMenu { showPeers = async () => { const peerCount = this.debugInfo.table.nodes.length; if (peerCount > 0) { - this.ui.showInfoMessage('Connected Peers'); - this.debugInfo.table.nodes.forEach((node, index) => { - this.ui.showInfoMessage( - `Peer ${index + 1}:\n` + - `${chalk.cyan('Peer ID:')} ${node.peerId}\n` + - `${chalk.cyan('Address:')} ${node.address}\n` + - `${chalk.cyan('Status:')} ${node.seen ? chalk.green('Active') : chalk.gray('Inactive')}`, - ); - }); + this.ui.showInfoMessage("Connected Peers"); + this.debugInfo.table.nodes.forEach((node, index) => { + this.ui.showInfoMessage( + `Peer ${index + 1}:\n` + + `${chalk.cyan("Peer ID:")} ${node.peerId}\n` + + `${chalk.cyan("Address:")} ${node.address}\n` + + `${chalk.cyan("Status:")} ${node.seen ? chalk.green("Active") : chalk.gray("Inactive")}`, + ); + }); } else { - this.ui.showInfoMessage('No connected peers found.'); + this.ui.showInfoMessage("No connected peers found."); } }; showNodeInfo = async () => { const data = this.debugInfo; this.ui.showInfoMessage( - `${chalk.cyan('Version:')} ${data.codex.version}\n` + - `${chalk.cyan('Revision:')} ${data.codex.revision}\n\n` + - `${chalk.cyan('Node ID:')} ${data.table.localNode.nodeId}\n` + - `${chalk.cyan('Peer ID:')} ${data.table.localNode.peerId}\n` + - `${chalk.cyan('Listening Address:')} ${data.table.localNode.address}\n\n` + - `${chalk.cyan('Public IP:')} ${data.announceAddresses[0].split('/')[2]}\n` + - `${chalk.cyan('Port:')} ${data.announceAddresses[0].split('/')[4]}\n` + - `${chalk.cyan('Connected Peers:')} ${data.table.nodes.length}`, + `${chalk.cyan("Version:")} ${data.codex.version}\n` + + `${chalk.cyan("Revision:")} ${data.codex.revision}\n\n` + + `${chalk.cyan("Node ID:")} ${data.table.localNode.nodeId}\n` + + `${chalk.cyan("Peer ID:")} ${data.table.localNode.peerId}\n` + + `${chalk.cyan("Listening Address:")} ${data.table.localNode.address}\n\n` + + `${chalk.cyan("Public IP:")} ${data.announceAddresses[0].split("/")[2]}\n` + + `${chalk.cyan("Port:")} ${data.announceAddresses[0].split("/")[4]}\n` + + `${chalk.cyan("Connected Peers:")} ${data.table.nodes.length}`, ); }; @@ -83,13 +83,11 @@ export class NodeStatusMenu { const spinner = this.ui.createAndStartSpinner("Fetching..."); try { return await this.dataService.debugInfo(); - } - catch { + } catch { this.ui.showErrorMessage("Failed to fetch debug/info"); return; - } - finally { + } finally { this.ui.stopSpinnerSuccess(spinner); } - } + }; }