mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-11-10 15:21:03 +00:00
Implement changing of zoom which fixes #17
- Take note that the keyboard shortcut for zoom in appears to be 'command + =', due to a bug in atom/electron#1507
This commit is contained in:
parent
4089cd36cb
commit
0e68fd61dc
@ -2,7 +2,7 @@ var electron = require('electron');
|
||||
var Menu = electron.Menu;
|
||||
var shell = electron.shell;
|
||||
|
||||
module.exports = function (mainWindow, nativefierVersion, onQuit) {
|
||||
module.exports = function (mainWindow, nativefierVersion, onQuit, onZoomIn, onZoomOut) {
|
||||
if (Menu.getApplicationMenu())
|
||||
return;
|
||||
|
||||
@ -69,6 +69,30 @@ module.exports = function (mainWindow, nativefierVersion, onQuit) {
|
||||
focusedWindow.setFullScreen(!focusedWindow.isFullScreen());
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Zoom In',
|
||||
accelerator: (function() {
|
||||
if (process.platform == 'darwin')
|
||||
return 'Command+=';
|
||||
else
|
||||
return 'Ctrl+=';
|
||||
})(),
|
||||
click: function() {
|
||||
onZoomIn();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Zoom Out',
|
||||
accelerator: (function() {
|
||||
if (process.platform == 'darwin')
|
||||
return 'Command+-';
|
||||
else
|
||||
return 'Ctrl+-';
|
||||
})(),
|
||||
click: function() {
|
||||
onZoomOut();
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'Toggle Window Developer Tools',
|
||||
accelerator: (function() {
|
||||
|
@ -17,8 +17,7 @@ var ipcMain = electron.ipcMain;
|
||||
var buildMenu = require('./components/menu/menu');
|
||||
|
||||
const APP_ARGS_FILE_PATH = path.join(__dirname, '..', 'nativefier.json');
|
||||
|
||||
var mainWindow = null;
|
||||
const ZOOM_INTERVAL = 0.1;
|
||||
|
||||
var appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8'));
|
||||
|
||||
@ -50,7 +49,9 @@ app.on('before-quit', () => {
|
||||
});
|
||||
|
||||
app.on('ready', function () {
|
||||
mainWindow = new BrowserWindow(
|
||||
var currentZoom = 1;
|
||||
|
||||
var mainWindow = new BrowserWindow(
|
||||
{
|
||||
width: appArgs.width || 1280,
|
||||
height: appArgs.height || 800,
|
||||
@ -63,7 +64,17 @@ app.on('ready', function () {
|
||||
}
|
||||
);
|
||||
|
||||
buildMenu(mainWindow, appArgs.nativefierVersion, app.quit);
|
||||
var onZoomIn = function () {
|
||||
currentZoom += ZOOM_INTERVAL;
|
||||
mainWindow.webContents.send('change-zoom', currentZoom);
|
||||
};
|
||||
|
||||
var onZoomOut = function () {
|
||||
currentZoom -= ZOOM_INTERVAL;
|
||||
mainWindow.webContents.send('change-zoom', currentZoom);
|
||||
};
|
||||
|
||||
buildMenu(mainWindow, appArgs.nativefierVersion, app.quit, onZoomIn, onZoomOut);
|
||||
|
||||
if (appArgs.userAgent) {
|
||||
mainWindow.webContents.setUserAgent(appArgs.userAgent);
|
||||
|
@ -2,7 +2,9 @@
|
||||
Preload file that will be executed in the renderer process
|
||||
*/
|
||||
|
||||
var ipc = require('electron').ipcRenderer;
|
||||
var electron = require('electron');
|
||||
var ipc = electron.ipcRenderer;
|
||||
var webFrame = electron.webFrame;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
// do things
|
||||
@ -12,3 +14,10 @@ ipc.on('params', function (event, message) {
|
||||
var appArgs = JSON.parse(message);
|
||||
console.log('nativefier.json', appArgs);
|
||||
});
|
||||
|
||||
|
||||
ipc.on('change-zoom', function (event, message) {
|
||||
console.log('new zom', message);
|
||||
webFrame.setZoomFactor(message);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user