1616
1717import open from "open"
1818import { join } from "path"
19- import { Choices , Profiles } from "madwizard"
20- import { MenuItemConstructorOptions } from "electron"
19+ import { Menu } from "electron"
20+ import { CreateWindowFunction } from "@kui-shell/core"
21+
22+ import profilesMenu from "./profiles"
2123
2224import { productName } from "@kui-shell/client/config.d/name.json"
2325import { bugs , version } from "@kui-shell/client/package.json"
2426
27+ // these our are tray menu icons; the electron api specifies that if
28+ // the files are named fooTemplate, then it will take care of
29+ // rendering them as a "template icon" via underlying platform apis
2530import icon from "@kui-shell/client/icons/png/codeflareTemplate.png"
2631import icon2x from "@kui-shell/client/icons/png/codeflareTemplate@2x.png"
2732
33+ // we only want one tray menu, so we need to squirrel away a reference
34+ // somewhere
2835let tray : null | InstanceType < typeof import ( "electron" ) . Tray > = null
2936
30- function profileMenu ( state : Choices . ChoiceState ) : MenuItemConstructorOptions {
31- return { label : state . profile . name , type : "radio" }
32- }
33-
34- async function profilesMenu ( ) : Promise < MenuItemConstructorOptions > {
35- const profiles = await Profiles . list ( { } )
36-
37- return { label : "Profiles" , submenu : profiles . map ( profileMenu ) }
38- }
39-
40- async function buildContextMenu ( createWindow : ( argv : string [ ] ) => void ) {
37+ /** @return an Electron `Menu` model for our tray menu */
38+ async function buildContextMenu ( createWindow : CreateWindowFunction ) : Promise < Menu > {
4139 const { Menu } = await import ( "electron" )
4240
4341 const contextMenu = Menu . buildFromTemplate ( [
4442 { label : `CodeFlare v${ version } ` , click : ( ) => createWindow ( [ ] ) } ,
4543 { type : "separator" } ,
46- await profilesMenu ( ) ,
44+ await profilesMenu ( createWindow ) ,
4745 { type : "separator" } ,
4846 /* {
4947 label: `Test new window`,
@@ -62,7 +60,13 @@ async function buildContextMenu(createWindow: (argv: string[]) => void) {
6260 return contextMenu
6361}
6462
65- export async function main ( createWindow : ( argv : string [ ] ) => void ) {
63+ /**
64+ * This is the logic that will be executed in the *electron-main*
65+ * process for tray menu registration. This will be invoked by our
66+ * `electron-main.ts`, via the `renderer` function below, which in
67+ * turn is called from our `preload.ts`.
68+ */
69+ export default async function main ( createWindow : CreateWindowFunction ) {
6670 if ( tray ) {
6771 // only register one tray menu...
6872 return
@@ -97,18 +101,3 @@ export async function main(createWindow: (argv: string[]) => void) {
97101 console . error ( "Error registering electron tray menu" , err )
98102 } )
99103}
100-
101- export async function renderer ( ipcRenderer : import ( "electron" ) . IpcRenderer ) {
102- if ( ipcRenderer ) {
103- ipcRenderer . send (
104- "/exec/invoke" ,
105- JSON . stringify ( {
106- module : "plugin-codeflare" ,
107- main : "initTray" ,
108- args : {
109- command : "/tray/init" ,
110- } ,
111- } )
112- )
113- }
114- }
0 commit comments