14
14
* limitations under the License.
15
15
*/
16
16
17
- import { Choices , Profiles } from "madwizard"
17
+ import { Profiles } from "madwizard"
18
18
import { MenuItemConstructorOptions } from "electron"
19
19
import { CreateWindowFunction } from "@kui-shell/core"
20
20
21
21
import boot from "./boot"
22
22
import shutdown from "./shutdown"
23
- import submenuForRuns from "./runs"
23
+ import runs from "./runs"
24
24
25
25
import UpdateFunction from "../../update"
26
26
import { profileIcon } from "../../icons"
27
-
28
27
import ProfileStatusWatcher from "../../watchers/profile/status"
29
28
29
+ /** Memo of `ProfileStatusWatcher`, keyed by profile name */
30
30
const watchers : Record < string , ProfileStatusWatcher > = { }
31
31
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 ,
35
45
createWindow : CreateWindowFunction ,
36
46
updateFunction : UpdateFunction
37
47
) : 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
-
43
48
return {
44
- label : state . profile . name ,
49
+ label : profile ,
45
50
icon : profileIcon ,
46
51
submenu : [
47
- boot ( state . profile . name , createWindow ) ,
48
- shutdown ( state . profile . name , createWindow ) ,
52
+ boot ( profile , createWindow ) ,
53
+ shutdown ( profile , createWindow ) ,
54
+
49
55
{ type : "separator" } ,
50
- { label : "Status" , enabled : false } ,
51
- watcher . head ,
52
- watcher . workers ,
56
+ ...status ( profile , updateFunction ) ,
57
+
53
58
{ type : "separator" } ,
54
- ...( await submenuForRuns ( createWindow ) ) ,
59
+ ...( await runs ( profile , createWindow ) ) ,
55
60
] ,
56
61
}
57
62
}
@@ -68,6 +73,6 @@ export default async function profilesMenu(
68
73
label : "Profiles" ,
69
74
enabled : false ,
70
75
} ,
71
- ...( await Promise . all ( profiles . map ( ( _ ) => submenuForOneProfile ( _ , createWindow , updateFn ) ) ) ) ,
76
+ ...( await Promise . all ( profiles . map ( ( _ ) => profileMenu ( _ . profile . name , createWindow , updateFn ) ) ) ) ,
72
77
]
73
78
}
0 commit comments