|
1 | 1 | // todo https://github.com/electron/electron/issues/7476
|
2 | 2 | // require("update-electron-app")();
|
| 3 | +const fs = require("fs"); |
| 4 | +const path = require("path"); |
3 | 5 |
|
| 6 | +const data = fs.readFileSync(__dirname + '/package.json', 'utf8'); |
| 7 | +let pkg = JSON.parse(data); |
4 | 8 | const {menubar} = require("menubar");
|
5 | 9 | const Analytics = require('electron-google-analytics4').default;
|
6 | 10 | const analytics = new Analytics('G-5WHLLLW38Y', 'LDGJbEmcR1-1naJDfemQFQ');
|
7 | 11 | analytics.setParams({"engagement_time_msec": 1});
|
8 | 12 |
|
9 |
| -const path = require("path"); |
10 | 13 | const {
|
11 | 14 | app, nativeImage, Tray, Menu, globalShortcut, shell,
|
12 | 15 | } = require("electron");
|
@@ -42,30 +45,38 @@ app.on("ready", () => {
|
42 | 45 | app.dock.hide();
|
43 | 46 | }
|
44 | 47 |
|
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 | + },]; |
69 | 80 |
|
70 | 81 | tray.on("right-click", () => {
|
71 | 82 | mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate));
|
|
0 commit comments