Skip to content

Commit

Permalink
feat: add mousewheel zoom for electron
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesjo committed Nov 23, 2018
1 parent eb01a6b commit 55a79cd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class AppComponent implements OnInit {
if (IS_ELECTRON) {
this._electronService.ipcRenderer.send(IPC_APP_READY);
this._initElectronErrorHandler();
this._initMousewheelZoomForElectron();

this._electronService.ipcRenderer.on(IPC_TRANSFER_SETTINGS_REQUESTED, () => {
this._electronService.ipcRenderer.send(IPC_TRANSFER_SETTINGS_TO_ELECTRON, this._configService.cfg);
Expand Down Expand Up @@ -152,4 +153,19 @@ export class AppComponent implements OnInit {
console.error(data);
});
}

private _initMousewheelZoomForElectron() {
const ZOOM_DELTA = 0.05;
const webFrame = this._electronService.webFrame;
document.addEventListener('mousewheel', (event: MouseWheelEvent) => {
if (event && event.ctrlKey) {
const zoomFactor = webFrame.getZoomFactor();
if (event.deltaY > 0) {
webFrame.setZoomFactor(zoomFactor + ZOOM_DELTA);
} else if (event.deltaY < 0) {
webFrame.setZoomFactor(zoomFactor - ZOOM_DELTA);
}
}
}, false);
}
}

0 comments on commit 55a79cd

Please sign in to comment.