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

Add Zoom controls to context menu and changed shortcuts #160

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,31 @@
</div>
<script>
const webview = document.getElementById('webview');
webview.addEventListener('dom-ready', function() {

// Store current zoom level
let currentZoom = 1.0;

// Add IPC listeners for zoom controls
require('electron').ipcRenderer.on('zoom-in', () => {
currentZoom += 0.1;
webview.setZoomFactor(currentZoom);
});

require('electron').ipcRenderer.on('zoom-out', () => {
currentZoom -= 0.1;
if (currentZoom < 0.3) currentZoom = 0.3; // Prevent too much zoom out
webview.setZoomFactor(currentZoom);
});

require('electron').ipcRenderer.on('zoom-reset', () => {
currentZoom = 1.0;
webview.setZoomFactor(currentZoom);
});

webview.addEventListener('dom-ready', function() {
// Set initial zoom if desired
// webview.setZoomFactor(0.6);

// hide message below text input, sidebar, suggestions on new chat
webview.insertCSS(`
.text-xs.text-center {
Expand Down
161 changes: 137 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,44 @@ app.on("ready", () => {
}

const contextMenuTemplate = [
// add links to github repo and vince's twitter
{
label: "Quit",
accelerator: "Command+Q",
label: "New Chat",
accelerator: "Command+N",
click: () => {
app.quit();
if (!window.isVisible()) return;
const webContents = mb.window.webContents;
webContents.executeJavaScript(`
document.querySelector('webview').executeJavaScript('document.querySelector(\\'[data-testid="create-new-chat-button"]\\').click()')
`);
},
},
{
label: "Reload",
accelerator: "Command+R",
label: "Open new chat in browser",
accelerator: "Command+Shift+N",
click: () => {
window.reload();
if (!window.isVisible()) return;
shell.openExternal('https://chat.openai.com/chat');
},
},
{
label: "Open in browser",
label: "Open current chat in browser",
accelerator: "Command+O",
click: () => {
shell.openExternal("https://chat.openai.com/chat");
if (!window.isVisible()) return;
const webContents = mb.window.webContents;
// Get the webview element's current URL
webContents.executeJavaScript(`
document.querySelector('webview')?.getAttribute('src') || 'https://chat.openai.com/chat'
`).then(currentUrl => {
shell.openExternal(currentUrl);
});
},
},
{
label: "Reload",
accelerator: "Command+R",
click: () => {
window.reload();
},
},
{
Expand All @@ -88,21 +107,59 @@ app.on("ready", () => {
shell.openExternal("https://twitter.com/vincelwt");
},
},
{
type: "separator",
},
{
label: "Zoom",
submenu: [
{
label: "Zoom In",
accelerator: "CommandOrControl+Plus",
click: () => {
const webContents = mb.window.webContents;
const currentZoom = webContents.getZoomFactor();
webContents.setZoomFactor(currentZoom + 0.1);
}
},
{
label: "Zoom Out",
accelerator: "CommandOrControl+-",
click: () => {
const webContents = mb.window.webContents;
const currentZoom = webContents.getZoomFactor();
const newZoom = Math.max(0.3, currentZoom - 0.1);
webContents.setZoomFactor(newZoom);
}
},
{
label: "Reset Zoom",
accelerator: "CommandOrControl+0",
click: () => {
mb.window.webContents.setZoomFactor(1.0);
}
}
]
},
{
type: "separator",
},
{
label: "Quit",
accelerator: "Command+Q",
click: () => {
app.quit();
},
},
];

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

tray.on("click", (e) => {
//check if ctrl or meta key is pressed while clicking
e.ctrlKey || e.metaKey
? mb.tray.popUpContextMenu(Menu.buildFromTemplate(contextMenuTemplate))
: null;
});
const menu = new Menu();

globalShortcut.register("CommandOrControl+Shift+g", () => {
globalShortcut.register("Command+Control+c", () => {
if (window.isVisible()) {
mb.hideWindow();
} else {
Expand All @@ -114,7 +171,48 @@ app.on("ready", () => {
}
});

Menu.setApplicationMenu(menu);
// Create application menu with shortcuts
const menuTemplate = [
{
label: 'File',
submenu: [
{
label: 'New Chat',
accelerator: 'Command+N',
click: () => {
if (!window.isVisible()) return;
const webContents = mb.window.webContents;
webContents.executeJavaScript(`
document.querySelector('webview').executeJavaScript('document.querySelector(\\'[data-testid="create-new-chat-button"]\\').click()')
`);
}
},
{
label: 'Open New Chat in Browser',
accelerator: 'Command+Shift+N',
click: () => {
if (!window.isVisible()) return;
shell.openExternal('https://chat.openai.com/chat');
}
},
{
label: 'Open Current Chat in Browser',
accelerator: 'Command+O',
click: () => {
if (!window.isVisible()) return;
const webContents = mb.window.webContents;
webContents.executeJavaScript(`
document.querySelector('webview')?.getAttribute('src') || 'https://chat.openai.com/chat'
`).then(currentUrl => {
shell.openExternal(currentUrl);
});
}
}
]
}
];

Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate));

// open devtools
// window.webContents.openDevTools();
Expand All @@ -139,13 +237,28 @@ app.on("ready", () => {
contents.on("before-input-event", (event, input) => {
const { control, meta, key } = input;
if (!control && !meta) return;
if (key === "c") contents.copy();
if (key === "v") contents.paste();
if (key === "a") contents.selectAll();
if (key === "z") contents.undo();
if (key === "y") contents.redo();
if (key === "q") app.quit();
if (key === "r") contents.reload();

switch(key) {
case "=":
case "+":
case "plus":
case "Equal":
contents.setZoomFactor(contents.getZoomFactor() + 0.1);
break;
case "-":
contents.setZoomFactor(Math.max(0.3, contents.getZoomFactor() - 0.1));
break;
case "0":
contents.setZoomFactor(1.0);
break;
case "c": contents.copy(); break;
case "v": contents.paste(); break;
case "a": contents.selectAll(); break;
case "z": contents.undo(); break;
case "y": contents.redo(); break;
case "q": app.quit(); break;
case "r": contents.reload(); break;
}
});
}
});
Expand Down