95 lines
2.0 KiB
JavaScript
Raw Normal View History

2025-02-25 13:59:26 +01:00
export class MainMenu {
2025-04-14 14:31:22 +02:00
constructor(
uiService,
menuLoop,
installMenu,
configMenu,
installer,
processControl,
) {
2025-02-25 13:59:26 +01:00
this.ui = uiService;
2025-04-01 14:09:20 +02:00
this.loop = menuLoop;
2025-03-07 13:14:32 +01:00
this.installMenu = installMenu;
2025-03-31 15:02:37 +02:00
this.configMenu = configMenu;
2025-04-14 14:31:22 +02:00
this.installer = installer;
this.processControl = processControl;
2025-04-01 14:09:20 +02:00
this.loop.initialize(this.promptMainMenu);
2025-02-25 13:59:26 +01:00
}
show = async () => {
this.ui.showLogo();
2025-03-07 13:14:32 +01:00
2025-04-01 14:09:20 +02:00
await this.loop.showLoop();
2025-02-25 15:25:14 +01:00
this.ui.showInfoMessage("K-THX-BYE");
};
2025-03-07 13:14:32 +01:00
promptMainMenu = async () => {
2025-04-14 14:31:22 +02:00
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", [
2025-03-07 13:14:32 +01:00
{
2025-04-14 14:31:22 +02:00
label: "Install Codex",
2025-03-07 13:14:32 +01:00
action: this.installMenu.show,
},
2025-03-31 15:02:37 +02:00
{
2025-04-14 14:31:22 +02:00
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",
2025-03-31 15:02:37 +02:00
action: this.configMenu.show,
},
2025-04-14 14:31:22 +02:00
{
label: "Uninstall Codex",
action: this.installMenu.show,
},
{
2025-03-07 13:14:32 +01:00
label: "Exit",
2025-04-01 14:09:20 +02:00
action: this.loop.stopLoop,
},
2025-03-07 13:14:32 +01:00
]);
2025-02-25 13:59:26 +01:00
};
}