Skip to content

Commit 9b170a1

Browse files
Pablo Carmonastarpit
authored andcommitted
feat: add initial electron tray menu
1 parent 91e6253 commit 9b170a1

File tree

9 files changed

+1909
-5656
lines changed

9 files changed

+1909
-5656
lines changed

package-lock.json

Lines changed: 1755 additions & 5642 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@
8686
"printWidth": 120
8787
},
8888
"devDependencies": {
89-
"@kui-shell/builder": "11.5.0-dev-20220713-175136",
90-
"@kui-shell/proxy": "11.5.0-dev-20220713-175136",
91-
"@kui-shell/react": "11.5.0-dev-20220713-175136",
92-
"@kui-shell/webpack": "11.5.0-dev-20220713-175136",
93-
"@playwright/test": "^1.23.3",
89+
"@kui-shell/builder": "11.5.0-dev-20220713-201002",
90+
"@kui-shell/proxy": "11.5.0-dev-20220713-201002",
91+
"@kui-shell/react": "11.5.0-dev-20220713-201002",
92+
"@kui-shell/webpack": "11.5.0-dev-20220713-201002",
93+
"@playwright/test": "^1.23.2",
9494
"@types/debug": "^4.1.7",
9595
"@types/node": "14.11.8",
9696
"@types/react": "17.0.39",
@@ -113,16 +113,16 @@
113113
},
114114
"dependencies": {
115115
"@kui-shell/client": "file:./plugins/plugin-client-default",
116-
"@kui-shell/core": "11.5.0-dev-20220713-175136",
117-
"@kui-shell/plugin-bash-like": "11.5.0-dev-20220713-175136",
118-
"@kui-shell/plugin-client-common": "11.5.0-dev-20220713-175136",
116+
"@kui-shell/core": "11.5.0-dev-20220713-201002",
117+
"@kui-shell/plugin-bash-like": "11.5.0-dev-20220713-201002",
118+
"@kui-shell/plugin-client-common": "11.5.0-dev-20220713-201002",
119119
"@kui-shell/plugin-codeflare": "file:./plugins/plugin-codeflare",
120-
"@kui-shell/plugin-core-support": "11.5.0-dev-20220713-175136",
121-
"@kui-shell/plugin-electron-components": "11.5.0-dev-20220713-175136",
122-
"@kui-shell/plugin-kubectl": "11.5.0-dev-20220713-175136",
120+
"@kui-shell/plugin-core-support": "11.5.0-dev-20220713-201002",
121+
"@kui-shell/plugin-electron-components": "11.5.0-dev-20220713-201002",
122+
"@kui-shell/plugin-kubectl": "11.5.0-dev-20220713-201002",
123123
"@kui-shell/plugin-madwizard": "file:./plugins/plugin-madwizard",
124-
"@kui-shell/plugin-patternfly4-themes": "11.5.0-dev-20220713-175136",
125-
"@kui-shell/plugin-proxy-support": "11.5.0-dev-20220713-175136",
126-
"@kui-shell/plugin-s3": "11.5.0-dev-20220713-175136"
124+
"@kui-shell/plugin-patternfly4-themes": "11.5.0-dev-20220713-201002",
125+
"@kui-shell/plugin-proxy-support": "11.5.0-dev-20220713-201002",
126+
"@kui-shell/plugin-s3": "11.5.0-dev-20220713-201002"
127127
}
128128
}
8.18 KB
Loading
332 Bytes
Loading
355 Bytes
Loading

plugins/plugin-codeflare/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@logdna/tail-file": "^3.0.0",
2727
"@patternfly/react-charts": "^6.77.1",
2828
"@patternfly/react-core": "^4.224.1",
29+
"open": "^8.4.0",
2930
"pretty-bytes": "^6.0.0",
3031
"split2": "^4.1.0",
3132
"strip-ansi": "6.0.0",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2022 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export async function initTray(args: { command: string } /* , _: unknown , createWindow: (argv: string[]) => void */) {
18+
if (args.command === "/tray/init") {
19+
import("./tray").then((_) => _.main(/* createWindow */))
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2022 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
export default async () => {
18+
const { ipcRenderer } = await import("electron")
19+
import("./tray").then((_) => _.renderer(ipcRenderer))
20+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2022 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import open from "open"
18+
import { Choices, Profiles } from "madwizard"
19+
import { MenuItemConstructorOptions } from "electron"
20+
21+
import { productName } from "@kui-shell/client/config.d/name.json"
22+
import { bugs, homepage, version } from "@kui-shell/client/package.json"
23+
24+
let tray: null | InstanceType<typeof import("electron").Tray> = null
25+
26+
function profileMenu(state: Choices.ChoiceState): MenuItemConstructorOptions {
27+
return { label: state.profile.name, type: "radio" }
28+
}
29+
30+
async function profilesMenu(): Promise<MenuItemConstructorOptions> {
31+
const profiles = await Profiles.list({})
32+
33+
return { label: "Profiles", submenu: profiles.map(profileMenu) }
34+
}
35+
36+
async function buildContextMenu(/* createWindow: (argv: string[]) => void */) {
37+
const { Menu } = await import("electron")
38+
39+
const contextMenu = Menu.buildFromTemplate([
40+
{ label: `CodeFlare v${version}`, click: () => open(homepage) },
41+
{ type: "separator" },
42+
await profilesMenu(),
43+
{ type: "separator" },
44+
/* {
45+
label: `Test new window`,
46+
click: async () => {
47+
try {
48+
createWindow(["echo", "hello"])
49+
} catch (err) {
50+
console.error(err)
51+
}
52+
},
53+
}, */
54+
{ label: `Report a Bug`, click: () => open(bugs.url) },
55+
{ label: `Quit ${productName}`, role: "quit" },
56+
])
57+
58+
return contextMenu
59+
}
60+
61+
export async function main(/* createWindow: (argv: string[]) => void */) {
62+
if (tray) {
63+
// only register one tray menu...
64+
return
65+
}
66+
67+
const { app } = await import("electron")
68+
69+
app
70+
.whenReady()
71+
.then(async () => {
72+
try {
73+
const { Tray } = await import("electron")
74+
tray = new Tray(require.resolve("@kui-shell/build/icons/png/codeflareTemplate.png"))
75+
76+
tray.setToolTip(productName)
77+
tray.setContextMenu(await buildContextMenu(/* createWindow */))
78+
} catch (err) {
79+
console.error("Error registering electron tray menu", err)
80+
}
81+
})
82+
.catch((err) => {
83+
console.error("Error registering electron tray menu", err)
84+
})
85+
}
86+
87+
export async function renderer(ipcRenderer: import("electron").IpcRenderer) {
88+
ipcRenderer.send(
89+
"/exec/invoke",
90+
JSON.stringify({
91+
module: "plugin-codeflare",
92+
main: "initTray",
93+
args: {
94+
command: "/tray/init",
95+
},
96+
})
97+
)
98+
}

0 commit comments

Comments
 (0)