Skip to content

Commit 0130ff4

Browse files
committed
fix: tray menu does not appear in production builds
- The headless webpack config ignores pngs. This PR pulls in a fix from Kui for that. - The tray.ts logic for expressing the path to the tray icon currently assumes a dev file layout. This PR also adds the original codeflare-favicon.svg vector source.
1 parent ea62090 commit 0130ff4

File tree

7 files changed

+227
-107
lines changed

7 files changed

+227
-107
lines changed

bin/codeflare

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,5 @@ fi
162162
trap 'pkill -P $$; exit 1;' TERM INT
163163

164164
# otherwise, we launch the UI version
165+
export CODEFLARE_HEADLESS=$HEADLESS
165166
"$NODE" "$HEADLESS"/codeflare.min.js -- codeflare $EXTRAPREFIX "$@"

package-lock.json

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

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
"printWidth": 120
8787
},
8888
"devDependencies": {
89-
"@kui-shell/builder": "11.5.0-dev-20220715-170302",
90-
"@kui-shell/proxy": "11.5.0-dev-20220715-170302",
91-
"@kui-shell/react": "11.5.0-dev-20220715-170302",
92-
"@kui-shell/webpack": "11.5.0-dev-20220715-170302",
89+
"@kui-shell/builder": "11.5.0-dev-20220715-111236",
90+
"@kui-shell/proxy": "11.5.0-dev-20220715-111236",
91+
"@kui-shell/react": "11.5.0-dev-20220715-111236",
92+
"@kui-shell/webpack": "11.5.0-dev-20220715-111236",
9393
"@playwright/test": "^1.23.2",
9494
"@types/debug": "^4.1.7",
9595
"@types/node": "14.11.8",
@@ -113,16 +113,16 @@
113113
},
114114
"dependencies": {
115115
"@kui-shell/client": "file:./plugins/plugin-client-default",
116-
"@kui-shell/core": "11.5.0-dev-20220715-170302",
117-
"@kui-shell/plugin-bash-like": "11.5.0-dev-20220715-170302",
118-
"@kui-shell/plugin-client-common": "11.5.0-dev-20220715-170302",
116+
"@kui-shell/core": "11.5.0-dev-20220715-111236",
117+
"@kui-shell/plugin-bash-like": "11.5.0-dev-20220715-111236",
118+
"@kui-shell/plugin-client-common": "11.5.0-dev-20220715-111236",
119119
"@kui-shell/plugin-codeflare": "file:./plugins/plugin-codeflare",
120-
"@kui-shell/plugin-core-support": "11.5.0-dev-20220715-170302",
121-
"@kui-shell/plugin-electron-components": "11.5.0-dev-20220715-170302",
122-
"@kui-shell/plugin-kubectl": "11.5.0-dev-20220715-170302",
120+
"@kui-shell/plugin-core-support": "11.5.0-dev-20220715-111236",
121+
"@kui-shell/plugin-electron-components": "11.5.0-dev-20220715-111236",
122+
"@kui-shell/plugin-kubectl": "11.5.0-dev-20220715-111236",
123123
"@kui-shell/plugin-madwizard": "file:./plugins/plugin-madwizard",
124-
"@kui-shell/plugin-patternfly4-themes": "11.5.0-dev-20220715-170302",
125-
"@kui-shell/plugin-proxy-support": "11.5.0-dev-20220715-170302",
126-
"@kui-shell/plugin-s3": "11.5.0-dev-20220715-170302"
124+
"@kui-shell/plugin-patternfly4-themes": "11.5.0-dev-20220715-111236",
125+
"@kui-shell/plugin-proxy-support": "11.5.0-dev-20220715-111236",
126+
"@kui-shell/plugin-s3": "11.5.0-dev-20220715-111236"
127127
}
128128
}
Lines changed: 91 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
These are needed if you want to import svg or png as ES6 imports. See
2+
plugin-client-default/src/index.tsx for an example.
3+
4+
These are also in @kui-shell/plugin-client-common/src/@types... I wish
5+
we could just use those. Maybe we can find a way?
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module "*.svg" {
2+
const content: string
3+
export default content
4+
}
5+
6+
declare module "*.png" {
7+
const content: string
8+
export default content
9+
}

plugins/plugin-codeflare/src/tray.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
*/
1616

1717
import open from "open"
18+
import { join } from "path"
1819
import { Choices, Profiles } from "madwizard"
1920
import { MenuItemConstructorOptions } from "electron"
2021

2122
import { productName } from "@kui-shell/client/config.d/name.json"
2223
import { bugs, version } from "@kui-shell/client/package.json"
2324

25+
import icon from "@kui-shell/client/icons/png/codeflareTemplate.png"
26+
import icon2x from "@kui-shell/client/icons/png/[email protected]"
27+
2428
let tray: null | InstanceType<typeof import("electron").Tray> = null
2529

2630
function profileMenu(state: Choices.ChoiceState): MenuItemConstructorOptions {
@@ -71,10 +75,20 @@ export async function main(createWindow: (argv: string[]) => void) {
7175
.then(async () => {
7276
try {
7377
const { Tray } = await import("electron")
74-
tray = new Tray(require.resolve("@kui-shell/build/icons/png/codeflareTemplate.png"))
7578

76-
tray.setToolTip(productName)
77-
tray.setContextMenu(await buildContextMenu(createWindow))
79+
const iconHome = process.env.CODEFLARE_HEADLESS || join(process.argv0, "../../Resources/app/dist/headless")
80+
if (iconHome) {
81+
// this forces webpack to include the @2x template images in
82+
// the build
83+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
84+
const fake = "dist/headless/" + icon2x
85+
86+
tray = new Tray(join(iconHome, icon))
87+
tray.setToolTip(productName)
88+
tray.setContextMenu(await buildContextMenu(createWindow))
89+
} else {
90+
console.error("Cannot register electron tray menu, because CODEFLARE_HEADLESS environment variable is absent")
91+
}
7892
} catch (err) {
7993
console.error("Error registering electron tray menu", err)
8094
}

0 commit comments

Comments
 (0)