Skip to content

Commit

Permalink
fix: tray menu does not appear in production builds on linux and windows
Browse files Browse the repository at this point in the history
We had two places in the tray menu code where we were assuming the macOS file layout for production builds (which is somewhat different from that on linux and windows)
  • Loading branch information
starpit committed Aug 29, 2022
1 parent c9ee70d commit cda2080
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
10 changes: 8 additions & 2 deletions plugins/plugin-codeflare/src/tray/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ import gettingStarted from "@kui-shell/client/icons/png/gettingStartedTemplate.p

import { join } from "path"

const iconHome = process.env.CODEFLARE_HEADLESS || join(process.argv0, "../../Resources/app/dist/headless")
function resources() {
return process.platform === "darwin" ? join(process.argv0, "../../Resources") : join(process.argv0, "../resources")
}

export function iconHome() {
return process.env.CODEFLARE_HEADLESS || join(resources(), "app/dist/headless")
}

/** Resize and templatize, so that the icon morphs with platform color themes */
function iconFor(filepath: string) {
return join(iconHome, filepath)
return join(iconHome(), filepath)
}

export const rayIcon = iconFor(ray)
Expand Down
18 changes: 7 additions & 11 deletions plugins/plugin-codeflare/src/tray/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { join } from "path"
import { CreateWindowFunction } from "@kui-shell/core"

import { iconHome } from "./icons"
import buildContextMenu from "./menus"
import { productName } from "@kui-shell/client/config.d/name.json"

Expand Down Expand Up @@ -87,18 +88,13 @@ export default async function main(createWindow: CreateWindowFunction) {
try {
const { Tray } = await import("electron")

const iconHome = process.env.CODEFLARE_HEADLESS || join(process.argv0, "../../Resources/app/dist/headless")
if (iconHome) {
// this forces webpack to include the @2x template images in
// the build
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const fake = "dist/headless/" + icon2x
// this forces webpack to include the @2x template images in
// the build
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const fake = "dist/headless/" + icon2x

tray = new Tray(join(iconHome, icon))
new LiveMenu(tray, createWindow)
} else {
console.error("Cannot register electron tray menu, because CODEFLARE_HEADLESS environment variable is absent")
}
tray = new Tray(join(iconHome(), icon))
new LiveMenu(tray, createWindow)
} catch (err) {
console.error("Error registering electron tray menu", err)
}
Expand Down

0 comments on commit cda2080

Please sign in to comment.