Skip to content

Commit 18da3ef

Browse files
committed
chore: code cleanup for tray menu, plus wording and placement updates
1 parent dead357 commit 18da3ef

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
import open from "open"
1817
import { join } from "path"
19-
import { Menu } from "electron"
2018
import { CreateWindowFunction } from "@kui-shell/core"
2119

22-
import profilesMenu from "./profiles"
23-
import { bugIcon, powerOffIcon } from "./icons"
24-
20+
import buildContextMenu from "./menus"
2521
import { productName } from "@kui-shell/client/config.d/name.json"
26-
import { bugs, version } from "@kui-shell/client/package.json"
2722

2823
// these our are tray menu icons; the electron api specifies that if
2924
// the files are named fooTemplate, then it will take care of
@@ -35,32 +30,6 @@ import icon2x from "@kui-shell/client/icons/png/codeflareTemplate@2x.png"
3530
// somewhere
3631
let tray: null | InstanceType<typeof import("electron").Tray> = null
3732

38-
/** @return an Electron `Menu` model for our tray menu */
39-
async function buildContextMenu(createWindow: CreateWindowFunction): Promise<Menu> {
40-
const { Menu } = await import("electron")
41-
42-
const contextMenu = Menu.buildFromTemplate([
43-
{ label: `CodeFlare v${version}`, click: () => createWindow([]) },
44-
{ type: "separator" },
45-
await profilesMenu(createWindow),
46-
{ type: "separator" },
47-
/* {
48-
label: `Test new window`,
49-
click: async () => {
50-
try {
51-
createWindow(["echo", "hello"])
52-
} catch (err) {
53-
console.error(err)
54-
}
55-
},
56-
}, */
57-
{ label: `Report a Bug`, icon: bugIcon, click: () => open(bugs.url) },
58-
{ label: `Quit ${productName}`, icon: powerOffIcon, role: "quit" },
59-
])
60-
61-
return contextMenu
62-
}
63-
6433
/**
6534
* This is the logic that will be executed in the *electron-main*
6635
* process for tray menu registration. This will be invoked by our
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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 { CreateWindowFunction } from "@kui-shell/core"
18+
19+
import { productName } from "@kui-shell/client/config.d/name.json"
20+
import { bugs, homepage, version } from "@kui-shell/client/package.json"
21+
22+
import profilesMenu from "./profiles"
23+
import { bugIcon, powerOffIcon } from "../icons"
24+
25+
/** @return an Electron `Menu` model for our tray menu */
26+
export default async function buildContextMenu(createWindow: CreateWindowFunction): Promise<import("electron").Menu> {
27+
const { Menu } = await import("electron")
28+
29+
const contextMenu = Menu.buildFromTemplate([
30+
{ label: `Open CodeFlare`, click: () => createWindow([]) },
31+
{ type: "separator" },
32+
await profilesMenu(createWindow),
33+
{ type: "separator" },
34+
{ label: `Version ${version}`, enabled: false },
35+
{ label: `Report a Bug`, icon: bugIcon, click: () => import("open").then((_) => _.default(bugs.url)) },
36+
{ label: `About CodeFlare`, click: () => import("open").then((_) => _.default(homepage)) },
37+
{ type: "separator" },
38+
{ label: `Quit ${productName}`, icon: powerOffIcon, role: "quit" },
39+
])
40+
41+
return contextMenu
42+
}

plugins/plugin-codeflare/src/tray/profiles.ts renamed to plugins/plugin-codeflare/src/tray/menus/profiles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { Choices, Profiles } from "madwizard"
1818
import { MenuItemConstructorOptions } from "electron"
1919
import { CreateWindowFunction } from "@kui-shell/core"
2020

21-
import windowOptions from "./window"
22-
import { profileIcon, bootIcon, shutDownIcon } from "./icons"
21+
import windowOptions from "../window"
22+
import { profileIcon, bootIcon, shutDownIcon } from "../icons"
2323

2424
/** Handler for booting up a profile */
2525
async function boot(profile: string, createWindow: CreateWindowFunction) {

0 commit comments

Comments
 (0)