mirror of
https://github.com/logos-storage/logos-storage-installer.git
synced 2026-01-04 22:43:09 +00:00
guard conditions for menu items
This commit is contained in:
parent
0e85190026
commit
fa86a80eab
@ -35,35 +35,35 @@ export class MainMenu {
|
||||
await this.ui.askMultipleChoice("Select an option", [
|
||||
{
|
||||
label: "Download and install Codex",
|
||||
action: this.installMenu.show,
|
||||
action: this.ifNotInstalled(this.installMenu.show),
|
||||
},
|
||||
{
|
||||
label: "Start Codex node",
|
||||
action: this.startCodex,
|
||||
action: this.ifInstalled(this.ifNotRunning(this.startCodex)),
|
||||
},
|
||||
{
|
||||
label: "Check node status",
|
||||
action: this.nodeStatusMenu.showNodeStatus,
|
||||
action: this.ifRunning(this.nodeStatusMenu.showNodeStatus),
|
||||
},
|
||||
{
|
||||
label: "Upload a file",
|
||||
action: this.dataMenu.performUpload,
|
||||
action: this.ifRunning(this.dataMenu.performUpload),
|
||||
},
|
||||
{
|
||||
label: "Download a file",
|
||||
action: this.dataMenu.performDownload,
|
||||
action: this.ifRunning(this.dataMenu.performDownload),
|
||||
},
|
||||
{
|
||||
label: "Show local data",
|
||||
action: this.dataMenu.showLocalData,
|
||||
action: this.ifRunning(this.dataMenu.showLocalData),
|
||||
},
|
||||
{
|
||||
label: "Stop Codex node",
|
||||
action: this.stopCodex,
|
||||
action: this.ifRunning(this.stopCodex),
|
||||
},
|
||||
{
|
||||
label: "Uninstall Codex node",
|
||||
action: this.installMenu.show,
|
||||
action: this.ifInstalled(this.ifNotRunning(this.installMenu.show)),
|
||||
},
|
||||
{
|
||||
label: "Submit feedback",
|
||||
@ -97,4 +97,44 @@ export class MainMenu {
|
||||
this.ui.showErrorMessage(`Failed to stop Codex. "${exception}"`);
|
||||
}
|
||||
};
|
||||
|
||||
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.");
|
||||
}
|
||||
};
|
||||
|
||||
ifNotRunning = async (call) => {
|
||||
if (!await this.isRunning()) {
|
||||
await call();
|
||||
} else {
|
||||
this.ui.showInfoMessage("Codex is running.");
|
||||
}
|
||||
};
|
||||
|
||||
isInstalled = async () => {
|
||||
return await this.installer.isCodexInstalled();
|
||||
};
|
||||
|
||||
isRunning = async () => {
|
||||
return ((await this.processControl.getNumberOfCodexProcesses()) > 0);
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user