wip updating main menu

This commit is contained in:
ThatBen 2025-04-14 14:31:22 +02:00
parent 5fcb55015a
commit 0b24fc238e
No known key found for this signature in database
GPG Key ID: E020A7DDCD52E1AB
3 changed files with 77 additions and 24 deletions

View File

@ -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 () => {

View File

@ -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;

View File

@ -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,