Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit f9ef102

Browse files
committed
working keyboard shorcuts
1 parent 0f4e66f commit f9ef102

File tree

5 files changed

+287
-64
lines changed

5 files changed

+287
-64
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ You can use Cmd+Shift+G to quickly open it from anywhere.
66

77
Download:
88

9-
- [Mac Arm64 .dmg](https://github.com/vincelwt/chatgpt-mac/releases/download/v0.0.3/ChatGPT-0.0.3-arm64.dmg)
10-
- [Mac Intel .dmg](https://github.com/vincelwt/chatgpt-mac/releases/download/v0.0.3/ChatGPT-0.0.3-x64.dmg)
9+
- [Mac Arm64 .dmg](https://github.com/vincelwt/chatgpt-mac/releases/download/v0.0.4/ChatGPT-0.0.4-arm64.dmg)
10+
- [Mac Intel .dmg](https://github.com/vincelwt/chatgpt-mac/releases/download/v0.0.4/ChatGPT-0.0.4-x64.dmg)
1111

1212
<p align="center">
1313
<img src="./images/screenshot.jpeg" width="500">

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</head>
88
<body class="myarrow">
99
<div class="page darwin">
10-
<webview id="wv1" src="https://chat.openai.com/chat" autosize="on" style="width:100%; height:530px">
10+
<webview id="wv1" src="https://chat.openai.com/chat" nodeintegration="on" autosize="on" style="width:100%; height:530px">
1111
</webview>
1212
</div>
1313
<script>

index.js

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
const { menubar } = require("menubar");
22

33
const path = require("path");
4-
const {
5-
app,
6-
nativeImage,
7-
shell,
8-
Tray,
9-
Menu,
10-
MenuItem,
11-
globalShortcut,
12-
} = require("electron");
4+
const { app, nativeImage, Tray, Menu, globalShortcut } = require("electron");
5+
const contextMenu = require("electron-context-menu");
136

147
const image = nativeImage.createFromPath(
158
path.join(__dirname, `images/newiconTemplate.png`)
169
);
1710

11+
const contextMenuTemplate = [
12+
{ role: "about" },
13+
{
14+
label: "Quit",
15+
accelerator: "Command+Q",
16+
click: function () {
17+
app.quit();
18+
},
19+
},
20+
];
21+
1822
app.on("ready", () => {
1923
const tray = new Tray(image);
2024

21-
const contextMenu = Menu.buildFromTemplate([
22-
{ role: "about" },
23-
{ type: "separator" },
24-
{ role: "quit" },
25-
]);
26-
2725
const mb = menubar({
2826
browserWindow: {
2927
icon: image,
@@ -36,6 +34,7 @@ app.on("ready", () => {
3634
height: 550,
3735
},
3836
tray,
37+
showOnAllWorkspaces: false,
3938
preloadWindow: true,
4039
showDockIcon: false,
4140
icon: image,
@@ -45,15 +44,13 @@ app.on("ready", () => {
4544
app.dock.hide();
4645

4746
tray.on("right-click", () => {
48-
mb.tray.popUpContextMenu(contextMenu);
47+
mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate));
4948
});
5049

5150
const { window } = mb;
52-
5351
const menu = new Menu();
5452

5553
globalShortcut.register("CommandOrControl+Shift+g", () => {
56-
console.log(window.isFocused(), window.isVisible());
5754
if (window.isVisible()) {
5855
mb.hideWindow();
5956
} else {
@@ -71,11 +68,40 @@ app.on("ready", () => {
7168
console.log("Menubar app is ready.");
7269
});
7370

71+
app.on("web-contents-created", (e, contents) => {
72+
if (contents.getType() == "webview") {
73+
// open link with external browser in webview
74+
contents.on("new-window", (e, url) => {
75+
e.preventDefault();
76+
shell.openExternal(url);
77+
});
78+
// set context menu in webview
79+
contextMenu({
80+
window: contents,
81+
});
82+
83+
// we can't set the native app menu with "menubar" so need to manually register these events
84+
// register cmd+c/cmd+v events
85+
contents.on("before-input-event", (event, input) => {
86+
const { control, meta, key } = input;
87+
if (!control && !meta) return;
88+
if (key === "c") contents.copy();
89+
if (key === "v") contents.paste();
90+
if (key === "a") contents.selectAll();
91+
if (key === "z") contents.undo();
92+
if (key === "y") contents.redo();
93+
if (key === "q") app.quit();
94+
if (key === "r") contents.reload();
95+
});
96+
}
97+
});
98+
99+
// restore focus to previous app on hiding
74100
mb.on("after-hide", () => {
75101
mb.app.hide();
76102
});
77103

78-
// open in new window
104+
// open links in new window
79105
// app.on("web-contents-created", (event, contents) => {
80106
// contents.on("will-navigate", (event, navigationUrl) => {
81107
// event.preventDefault();
@@ -89,7 +115,6 @@ app.on("ready", () => {
89115
"true"
90116
);
91117
});
92-
// restore focus to previous app on hiding
93118

94119
// Quit when all windows are closed, except on macOS. There, it's common
95120
// for applications and their menu bar to stay active until the user quits

0 commit comments

Comments
 (0)