Skip to content

Commit c9ee70d

Browse files
committed
fix: avoid tray menu "blinking" on linux
1 parent f6efb4a commit c9ee70d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

plugins/plugin-codeflare/src/tray/main.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ import icon2x from "@kui-shell/client/icons/png/codeflareTemplate@2x.png"
3131
let tray: null | InstanceType<typeof import("electron").Tray> = null
3232

3333
class LiveMenu {
34+
// serialized form, to avoid unnecessary repaints
35+
private currentContextMenu = ""
36+
3437
public constructor(
3538
private readonly tray: import("electron").Tray,
3639
private readonly createWindow: CreateWindowFunction,
@@ -47,8 +50,19 @@ class LiveMenu {
4750
clearTimeout(this.debounce)
4851
}
4952
this.debounce = setTimeout(async () => {
50-
this.tray.setToolTip(productName)
51-
this.tray.setContextMenu(await buildContextMenu(this.createWindow, this.render.bind(this)))
53+
// avoid blinking on linux by constantly repainting: only update
54+
// the tray if the model has changed
55+
const newContextMenu = await buildContextMenu(this.createWindow, this.render.bind(this))
56+
const newContextMenuSerialized = JSON.stringify(
57+
newContextMenu,
58+
(key, value) => (key === "menu" || key === "commandsMap" || key === "commandId" ? undefined : value),
59+
2
60+
)
61+
if (this.currentContextMenu !== newContextMenuSerialized) {
62+
this.currentContextMenu = newContextMenuSerialized
63+
this.tray.setToolTip(productName)
64+
this.tray.setContextMenu(newContextMenu)
65+
}
5266
}, 200)
5367
}
5468
}

plugins/plugin-codeflare/src/tray/watchers/profile/status.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import Debug from "debug"
1818
import { spawn } from "child_process"
19-
import { encodeComponent } from "@kui-shell/core"
2019

2120
import UpdateFunction from "../../update"
2221
import respawnCommand from "../../../controller/respawn"
@@ -54,15 +53,15 @@ export default class ProfileStatusWatcher {
5453
}
5554

5655
private initJob(profile: string) {
57-
console.error("Watcher start", profile)
5856
const { argv, env } = respawnCommand([
5957
"guide",
6058
"-q",
6159
"-y",
6260
"--profile",
63-
encodeComponent(profile),
61+
profile,
6462
"ml/ray/cluster/kubernetes/is-ready",
6563
])
64+
Debug("codeflare")("Watcher start", profile, argv)
6665
const job = spawn(argv[0], argv.slice(1), { env, stdio: ["pipe", "pipe", "inherit"], detached: true })
6766

6867
// make sure to kill that watcher subprocess when we exit
@@ -97,6 +96,7 @@ export default class ProfileStatusWatcher {
9796
.toString()
9897
.split(/\n/)
9998
.forEach((line: string) => {
99+
Debug("codeflare")("profile status watcher line", line)
100100
const match = line.match(/^(head|workers)\s+(\S+)$/)
101101
if (!match) {
102102
// console.error('Bogus line emitted by ray cluster readiness probe', line)

0 commit comments

Comments
 (0)