diff options
author | Andrew Dolgov <[email protected]> | 2019-03-13 16:26:48 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2019-03-13 16:26:48 +0300 |
commit | 56d04a5a631c897169ba32a7a385844135599483 (patch) | |
tree | a4715cfd3fc4b31e76f40869c6bb1f095b709f74 | |
parent | 215ac541007eb25d3c7c1d193f0e9326cf5e56cf (diff) |
disable menu items when needed, etc
-rwxr-xr-x | app.js | 26 | ||||
-rwxr-xr-x | reader.html | 2 | ||||
-rwxr-xr-x | reader.js | 38 |
3 files changed, 58 insertions, 8 deletions
@@ -31,14 +31,14 @@ function createWindow() { } }); - mainWindow.maximize(); + //mainWindow.maximize(); const menu = Menu.buildFromTemplate([ { label: 'File', submenu: [ {label: 'Open...', accelerator: 'Ctrl+O', click: () => { openFileDialog(); }}, - {label: 'Close', click: () => { mainWindow.webContents.send("close-file"); }}, + {id: 'F-CLOSE', label: 'Close', click: () => { mainWindow.webContents.send("close-file"); }}, {type: 'separator'}, {label: 'Exit', click: () => { app.quit(); }} ] @@ -46,18 +46,30 @@ function createWindow() { { label: 'Location', submenu: [ - {label: 'Go to...', accelerator: 'Ctrl+G', click: () => { mainWindow.webContents.send("open-location"); }}, - {label: 'Sync to last page read', click: () => { mainWindow.webContents.send("sync-to-last"); }}, + {id: 'F-GO', label: 'Go to...', accelerator: 'Ctrl+G', click: () => { mainWindow.webContents.send("open-location"); }}, + {id: 'F-SYNC', label: 'Sync to last page read', click: () => { mainWindow.webContents.send("sync-to-last"); }}, {type: 'separator'}, - {label: 'Clear last read', click: () => { mainWindow.webContents.send("clear-last-read"); }}, - {label: 'Mark as read', accelerator: 'Ctrl+M', click: () => { mainWindow.webContents.send("mark-as-read"); }}, + {id: 'F-CLEAR', label: 'Clear last read', click: () => { mainWindow.webContents.send("clear-last-read"); }}, + {id: 'F-MARK', label: 'Mark as read', accelerator: 'Ctrl+M', click: () => { mainWindow.webContents.send("mark-as-read"); }}, ] }, { + label: 'Reading', + submenu: [ + {id: 'F-FIT', label: 'Fit to width', type: 'checkbox', click: () => { mainWindow.webContents.send("fit-to-width"); }}, + {type: 'separator'}, + {id: 'F-SINGLE', label: 'Single column', type: 'checkbox', click: () => { mainWindow.webContents.send("single-column"); }}, + {id: 'F-FLIP', label: 'Mirror (manga mode)', type: 'checkbox', click: () => { mainWindow.webContents.send("flip-columns"); }}, + ] + }, + + { label: 'Tools', submenu: [ {label: 'Options', click: () => { mainWindow.webContents.send("open-settings"); }}, {label: 'Toggle fullscreen', accelerator: 'F11', click: () => { mainWindow.setFullScreen(!mainWindow.isFullScreen()); }}, + {type: 'separator'}, + {label: 'Developer tools', accelerator: 'F12', click: () => { mainWindow.webContents.openDevTools(); }}, ] }, ]); @@ -68,7 +80,7 @@ function createWindow() { mainWindow.loadFile('reader.html'); // Open the DevTools. - mainWindow.webContents.openDevTools(); + //mainWindow.webContents.openDevTools(); // Emitted when the window is closed. mainWindow.on('closed', function () { diff --git a/reader.html b/reader.html index d2edd8c..36d3fad 100755 --- a/reader.html +++ b/reader.html @@ -48,7 +48,7 @@ <div class="checkbox"> <label title="Applies for active file"><input class="single-column-cb" type="checkbox" data-bind="attr: { checked: singleColumn }"> - Force single column</label> + Single column</label> </div> <div class="checkbox"> @@ -209,6 +209,32 @@ function Model() { remote.getCurrentWindow().setProgressBar(progress/100); }); + self._updateMenu = ko.computed(function() { + const enabled = self.fileName() != ""; + const { remote } = require('electron'); + const menu = remote.Menu.getApplicationMenu(); + + $.each(menu.items, (i,g) => { + $.each(g.submenu.items, (i,m) => { + if (m.id && m.id.indexOf("F-") == 0) { + m.enabled = enabled; + + switch (m.id) { + case "F-FIT": + m.checked = self.fitToWidth(); + break; + case "F-SINGLE": + m.checked = self.singleColumn(); + break; + case "F-FLIP": + m.checked = self.flipColumns(); + break; + } + } + }); + }); + }); + self.getLeftPage = ko.computed(function () { const page = self.currentPage(); @@ -272,6 +298,18 @@ $(document).ready(function () { model.closeFile(); }); + ipcRenderer.on("fit-to-width", (event, args) => { + model.fitToWidth(!model.fitToWidth()); + }); + + ipcRenderer.on("single-column", (event, args) => { + model.singleColumn(!model.singleColumn()); + }); + + ipcRenderer.on("flip-columns", (event, args) => { + model.flipColumns(!model.flipColumns()); + }); + ipcRenderer.on("clear-last-read", (event, args) => { if (confirm("Clear stored last read position?")) { localforage.setItem(model.cacheKey("POSITION"), 0).then(() => { |