1414 * limitations under the License.
1515 */
1616
17- import { Choices , Profiles } from "madwizard"
17+ import { Profiles } from "madwizard"
1818import { MenuItemConstructorOptions } from "electron"
1919import { CreateWindowFunction } from "@kui-shell/core"
2020
2121import boot from "./boot"
2222import shutdown from "./shutdown"
23- import submenuForRuns from "./runs"
23+ import runs from "./runs"
2424
2525import UpdateFunction from "../../update"
2626import { profileIcon } from "../../icons"
27-
2827import ProfileStatusWatcher from "../../watchers/profile/status"
2928
29+ /** Memo of `ProfileStatusWatcher`, keyed by profile name */
3030const watchers : Record < string , ProfileStatusWatcher > = { }
3131
32- /** @return a menu for the given profile */
33- async function submenuForOneProfile (
34- state : Choices . ChoiceState ,
32+ /** @return menu items for the status of the given `profile` */
33+ function status ( profile : string , updateFunction : UpdateFunction ) {
34+ if ( ! watchers [ profile ] ) {
35+ watchers [ profile ] = new ProfileStatusWatcher ( profile , updateFunction )
36+ }
37+ const watcher = watchers [ profile ]
38+
39+ return [ { label : "Status" , enabled : false } , watcher . head , watcher . workers ]
40+ }
41+
42+ /** @return a menu for the given `profile` */
43+ async function profileMenu (
44+ profile : string ,
3545 createWindow : CreateWindowFunction ,
3646 updateFunction : UpdateFunction
3747) : Promise < MenuItemConstructorOptions > {
38- if ( ! watchers [ state . profile . name ] ) {
39- watchers [ state . profile . name ] = new ProfileStatusWatcher ( state . profile . name , updateFunction )
40- }
41- const watcher = watchers [ state . profile . name ]
42-
4348 return {
44- label : state . profile . name ,
49+ label : profile ,
4550 icon : profileIcon ,
4651 submenu : [
47- boot ( state . profile . name , createWindow ) ,
48- shutdown ( state . profile . name , createWindow ) ,
52+ boot ( profile , createWindow ) ,
53+ shutdown ( profile , createWindow ) ,
54+
4955 { type : "separator" } ,
50- { label : "Status" , enabled : false } ,
51- watcher . head ,
52- watcher . workers ,
56+ ...status ( profile , updateFunction ) ,
57+
5358 { type : "separator" } ,
54- ...( await submenuForRuns ( createWindow ) ) ,
59+ ...( await runs ( profile , createWindow ) ) ,
5560 ] ,
5661 }
5762}
@@ -68,6 +73,6 @@ export default async function profilesMenu(
6873 label : "Profiles" ,
6974 enabled : false ,
7075 } ,
71- ...( await Promise . all ( profiles . map ( ( _ ) => submenuForOneProfile ( _ , createWindow , updateFn ) ) ) ) ,
76+ ...( await Promise . all ( profiles . map ( ( _ ) => profileMenu ( _ . profile . name , createWindow , updateFn ) ) ) ) ,
7277 ]
7378}
0 commit comments