diff --git a/src/handlers/processControl.js b/src/handlers/processControl.js index 96a7d1c..cf4423a 100644 --- a/src/handlers/processControl.js +++ b/src/handlers/processControl.js @@ -5,7 +5,7 @@ export class ProcessControl { this.shell = shellService; this.os = osService; this.fs = fsService; - this.codexGlobals; + this.codexGlobals = codexGlobals; } getCodexProcesses = async () => { @@ -31,8 +31,8 @@ export class ProcessControl { }; startCodexProcess = async () => { - this.saveCodexConfigFile(); - this.startCodex(); + await this.saveCodexConfigFile(); + await this.startCodex(); }; saveCodexConfigFile = async () => { diff --git a/src/main.js b/src/main.js index ad7f22a..ef50b55 100644 --- a/src/main.js +++ b/src/main.js @@ -100,6 +100,7 @@ export async function main() { process.on("SIGTERM", handleExit); process.on("SIGQUIT", handleExit); + const codexGlobals = new CodexGlobals(); const uiService = new UiService(); const fsService = new FsService(); const configService = new ConfigService(fsService); @@ -125,31 +126,24 @@ export async function main() { configService, pathSelector, numberSelector, + new DataDirMover(fsService, uiService), + ); + const processControl = new ProcessControl( + configService, + shellService, + osService, + fsService, + codexGlobals, ); const mainMenu = new MainMenu( uiService, new MenuLoop(), installMenu, configMenu, - new DataDirMover(fsService, uiService), + installer, + processControl, ); - const codexGlobals = new CodexGlobals(); - - const processControl = new ProcessControl( - configService, - shellService, - osService, - fsService, - ); - - console.log("ip: " + (await codexGlobals.getPublicIp())); - console.log("spr: " + (await codexGlobals.getTestnetSprs())); - - //await processControl.doThing(); - // await processControl.detectThing(); - return; - await mainMenu.show(); return; diff --git a/src/ui/mainMenu.js b/src/ui/mainMenu.js index 50c1e11..fc28d3f 100644 --- a/src/ui/mainMenu.js +++ b/src/ui/mainMenu.js @@ -1,9 +1,18 @@ export class MainMenu { - constructor(uiService, menuLoop, installMenu, configMenu) { + constructor( + uiService, + menuLoop, + installMenu, + configMenu, + installer, + processControl, + ) { this.ui = uiService; this.loop = menuLoop; this.installMenu = installMenu; this.configMenu = configMenu; + this.installer = installer; + this.processControl = processControl; this.loop.initialize(this.promptMainMenu); } @@ -17,15 +26,65 @@ export class MainMenu { }; promptMainMenu = async () => { - await this.ui.askMultipleChoice("Select an option", [ + if ((await this.processControl.getNumberOfCodexProcesses) > 0) { + await this.showRunningMenu(); + } else { + if (await this.installer.isCodexInstalled()) { + await this.showCodexNotRunningMenu(); + } else { + await this.showNotInstalledMenu(); + } + } + }; + + showNotInstalledMenu = async () => { + await this.ui.askMultipleChoice("Codex is not installed", [ { - label: "Install/uninstall Codex", + label: "Install Codex", action: this.installMenu.show, }, { - label: "Configure Codex", + label: "Exit", + action: this.loop.stopLoop, + }, + ]); + }; + + showRunningMenu = async () => { + await this.ui.askMultipleChoice("Codex is running", [ + { + label: "Stop Codex", + action: this.processControl.stopCodexProcess, + }, + { + label: "Open Codex app", + action: this.openCodexApp, + }, + { + label: "Exit", + action: this.loop.stopLoop, + }, + ]); + }; + + openCodexApp = async () => { + console.log("todo!"); + }; + + showCodexNotRunningMenu = async () => { + await this.ui.askMultipleChoice("Codex is not running", [ + { + label: "Start Codex", + action: this.processControl.startCodexProcess, + }, + { + label: "Edit Codex config", action: this.configMenu.show, }, + { + label: "Uninstall Codex", + action: this.installMenu.show, + }, { label: "Exit", action: this.loop.stopLoop,