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

Zooming options support #19

Merged
merged 1 commit into from
Jan 11, 2018
Merged
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
40 changes: 40 additions & 0 deletions browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
const electron = require('electron');
const config = require('./config');

const ipc = electron.ipcRenderer;
const webFrame = electron.webFrame;

ipc.on('zoom-in', () => {
// Get zoom factor and increase it
const currentZoomFactor = webFrame.getZoomFactor();
const zoomFactor = currentZoomFactor + 0.05;
// Upper bound check
if (zoomFactor < 1.3) {
webFrame.setZoomFactor(zoomFactor);
config.set('zoomFactor', zoomFactor);
}
});

ipc.on('zoom-out', () => {
// Get zoom factor and decrease it
const currentZoomFactor = webFrame.getZoomFactor();
const zoomFactor = currentZoomFactor - 0.05;
// Lower bound check
if (zoomFactor > 0.7) {
webFrame.setZoomFactor(zoomFactor);
config.set('zoomFactor', zoomFactor);
}
});

ipc.on('zoom-reset', () => {
// Reset zoom factor
webFrame.setZoomFactor(1.0);
config.set('zoomFactor', 1.0);
});

document.addEventListener('DOMContentLoaded', () => {
// Preserve zoom factor
const zoomFactor = config.get('zoomFactor');
webFrame.setZoomFactor(zoomFactor);
});
52 changes: 52 additions & 0 deletions menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ const electron = require('electron');
const app = electron.app;
const shell = electron.shell;
const appName = app.getName();
const BrowserWindow = electron.BrowserWindow;

function activate(command) {
const appWindow = BrowserWindow.getAllWindows()[0];
// Extra measure in order to be shown
appWindow.show();
appWindow.webContents.send(command);
}

const helpSubmenu = [{
label: `${appName} Website`,
Expand Down Expand Up @@ -96,6 +104,28 @@ const darwinTpl = [{
focusedWindow.reload();
}
}
}, {
type: 'separator'
}, {
label: 'Make Text Larger',
accelerator: 'CmdOrCtrl+Plus',
click() {
activate('zoom-in');
}
}, {
label: 'Make Text Smaller',
accelerator: 'CmdOrCtrl+-',
click() {
activate('zoom-out');
}
}, {
label: 'Reset Zoom Level',
accelerator: 'CmdOrCtrl+0',
click() {
activate('zoom-reset');
}
}, {
type: 'separator'
}, {
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
Expand Down Expand Up @@ -170,6 +200,28 @@ const otherTpl = [{
focusedWindow.reload();
}
}
}, {
type: 'separator'
}, {
label: 'Make Text Larger',
accelerator: 'CmdOrCtrl+Plus',
click() {
activate('zoom-in');
}
}, {
label: 'Make Text Smaller',
accelerator: 'CmdOrCtrl+-',
click() {
activate('zoom-out');
}
}, {
label: 'Reset Zoom Level',
accelerator: 'CmdOrCtrl+0',
click() {
activate('zoom-reset');
}
}, {
type: 'separator'
}, {
label: 'Toggle Full Screen',
accelerator: 'F11',
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ brew cask install whale

[Download](https://github.com/1000ch/whale/releases) and extract `.zip`, and move `Whale` to some location.

## Keyboard shortcuts

Description | Keys
-------------------------- | --------------------------
Reset Zoom Level | <kbd>Cmd/Ctrl</kbd> <kbd>0</kbd>
Make Text Smaller | <kbd>Cmd/Ctrl</kbd> <kbd>-</kbd>
Make Text Larger | <kbd>Cmd/Ctrl</kbd> <kbd>Shift</kbd> <kbd>=</kbd>

## License

[MIT](https://1000ch.mit-license.org) © [Shogo Sensui](https://github.com/1000ch)