Skip to content

Commit 5686ba9

Browse files
committed
add Always On Top
1 parent ec293a8 commit 5686ba9

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

index.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// todo https://github.com/electron/electron/issues/7476
22
// require("update-electron-app")();
3+
const fs = require("fs");
4+
const path = require("path");
35

6+
const data = fs.readFileSync(__dirname + '/package.json', 'utf8');
7+
let pkg = JSON.parse(data);
48
const {menubar} = require("menubar");
59
const Analytics = require('electron-google-analytics4').default;
610
const analytics = new Analytics('G-5WHLLLW38Y', 'LDGJbEmcR1-1naJDfemQFQ');
711
analytics.setParams({"engagement_time_msec": 1});
812

9-
const path = require("path");
1013
const {
1114
app, nativeImage, Tray, Menu, globalShortcut, shell,
1215
} = require("electron");
@@ -42,30 +45,38 @@ app.on("ready", () => {
4245
app.dock.hide();
4346
}
4447

45-
const contextMenuTemplate = [// add links to github repo and vince's twitter
46-
{
47-
label: "Quit", accelerator: "Command+Q", click: () => {
48-
app.quit();
49-
},
50-
}, {
51-
label: "Reload", accelerator: "Command+R", click: () => {
52-
window.reload();
53-
},
54-
}, {
55-
label: "Open in browser", click: () => {
56-
shell.openExternal("https://kimi.moonshot.cn/");
57-
},
58-
}, {
59-
type: "separator",
60-
}, {
61-
label: "View on GitHub", click: () => {
62-
shell.openExternal("https://github.com/hocgin/kimi-app");
63-
},
64-
}, {
65-
label: "Author on Twitter", click: () => {
66-
shell.openExternal("https://twitter.com/hocgin");
67-
},
68-
},];
48+
const contextMenuTemplate = [{
49+
label: 'Always On Top', type: 'checkbox', checked: false,
50+
click: (menuItem, browserWindow, event) => {
51+
let newChecked = menuItem.checked;
52+
contextMenuTemplate[0].checked = newChecked;
53+
let mainWindow = mb.window;
54+
mainWindow.setAlwaysOnTop(newChecked);
55+
mb.tray.closeContextMenu();
56+
}
57+
}, {
58+
label: "Quit", accelerator: "Command+Q", click: () => {
59+
app.quit();
60+
},
61+
}, {
62+
label: "Reload", accelerator: "Command+R", click: () => {
63+
window.reload();
64+
},
65+
}, {
66+
label: "Open in Browser", click: () => {
67+
shell.openExternal("https://kimi.moonshot.cn/");
68+
},
69+
}, {
70+
type: "separator",
71+
}, {
72+
label: "Home Page", click: () => {
73+
shell.openExternal(`https://logspot.hocgin.top/${pkg.name}`);
74+
},
75+
}, {
76+
label: "More", click: () => {
77+
shell.openExternal("https://logspot.hocgin.top/");
78+
},
79+
},];
6980

7081
tray.on("right-click", () => {
7182
mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate));

0 commit comments

Comments
 (0)