installMenu.js
1 export class InstallMenu { 2 constructor(uiService, menuLoop, configService, pathSelector, installer) { 3 this.ui = uiService; 4 this.loop = menuLoop; 5 this.configService = configService; 6 this.config = configService.get(); 7 this.pathSelector = pathSelector; 8 this.installer = installer; 9 10 this.loop.initialize(this.showMenu); 11 } 12 13 show = async () => { 14 await this.loop.showLoop(); 15 }; 16 17 showMenu = async () => { 18 if (await this.installer.isCodexInstalled()) { 19 await this.showUninstallMenu(); 20 } else { 21 await this.showInstallMenu(); 22 } 23 }; 24 25 showInstallMenu = async () => { 26 await this.ui.askMultipleChoice("Configure your Codex installation", [ 27 { 28 label: "Install path: " + this.config.codexRoot, 29 action: this.selectInstallPath, 30 }, 31 { 32 label: "Storage provider module: Disabled (todo)", 33 action: this.storageProviderOption, 34 }, 35 { 36 label: "Install!", 37 action: this.performInstall, 38 }, 39 { 40 label: "Cancel", 41 action: this.doNothing, 42 }, 43 ]); 44 }; 45 46 showUninstallMenu = async () => { 47 await this.ui.askMultipleChoice("Codex is installed", [ 48 { 49 label: "Uninstall", 50 action: this.showConfirmUninstall, 51 }, 52 { 53 label: "Cancel", 54 action: this.doNothing, 55 }, 56 ]); 57 }; 58 59 showConfirmUninstall = async () => { 60 this.ui.showInfoMessage( 61 "You are about to:\n" + 62 " - Uninstall the Codex application\n" + 63 " - Delete your Codex ethereum keys\n" + 64 " - Delete the data stored in your Codex node\n" + 65 " - Delete the log files of your Codex node", 66 ); 67 68 await this.ui.askMultipleChoice( 69 "Are you sure you want to uninstall Codex?", 70 [ 71 { 72 label: "No", 73 action: this.doNothing, 74 }, 75 { 76 label: "Yes", 77 action: this.performUninstall, 78 }, 79 ], 80 ); 81 }; 82 83 selectInstallPath = async () => { 84 this.config.codexRoot = await this.pathSelector.show( 85 this.config.codexRoot, 86 false, 87 ); 88 this.configService.saveConfig(); 89 }; 90 91 storageProviderOption = async () => { 92 this.ui.showInfoMessage("This option is not currently available."); 93 await this.show(); 94 }; 95 96 performInstall = async () => { 97 this.loop.stopLoop(); 98 await this.installer.installCodex(this); 99 }; 100 101 performUninstall = async () => { 102 this.loop.stopLoop(); 103 this.installer.uninstallCodex(); 104 }; 105 106 doNothing = async () => { 107 this.loop.stopLoop(); 108 }; 109 110 // Progress callbacks from installer module: 111 installStarts = () => { 112 this.installSpinner = this.ui.createAndStartSpinner("Installing..."); 113 }; 114 115 downloadSuccessful = () => { 116 this.ui.showInfoMessage("Download successful..."); 117 }; 118 119 installSuccessful = () => { 120 this.ui.showInfoMessage("Installation successful!"); 121 this.ui.stopSpinnerSuccess(this.installSpinner); 122 }; 123 124 warn = (message) => { 125 this.ui.showErrorMessage(message); 126 this.ui.stopSpinnerError(this.installSpinner); 127 }; 128 }