Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 2 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
71 changes: 57 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,49 @@ 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);
}
}
]
},
];

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", () => {
pbdco marked this conversation as resolved.
Show resolved Hide resolved
if (window.isVisible()) {
mb.hideWindow();
} else {
Expand Down Expand Up @@ -139,13 +167,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