From c88459a4a8962ae7468d875c18a7595fffbe9931 Mon Sep 17 00:00:00 2001 From: Wesley McCann Date: Sun, 7 Oct 2018 22:07:44 -0600 Subject: [PATCH 1/4] Added prompt when saving html page Fixed an issue that emerged when implementing this. I don't believe when downloading an `.html` page that we'd want the browser toolbar to open. The one with Downloads, History, etc. If we do want that to open, we can easily update this pull request to allow that. --- app/background-process/ui/downloads.js | 4 +- app/background-process/ui/window-menu.js | 192 ++++++++++++----------- 2 files changed, 102 insertions(+), 94 deletions(-) diff --git a/app/background-process/ui/downloads.js b/app/background-process/ui/downloads.js index a654d95186..97a0b743e8 100644 --- a/app/background-process/ui/downloads.js +++ b/app/background-process/ui/downloads.js @@ -61,7 +61,9 @@ export function registerListener (win, opts = {}) { } downloads.push(item) - downloadsEvents.emit('new-download', toJSON(item)) + + if(!item.name.includes(".html")) + downloadsEvents.emit('new-download', toJSON(item)) // update dock-icon progress bar var lastBytes = 0 diff --git a/app/background-process/ui/window-menu.js b/app/background-process/ui/window-menu.js index 6733a41e0e..fd98dd2dec 100644 --- a/app/background-process/ui/window-menu.js +++ b/app/background-process/ui/window-menu.js @@ -1,11 +1,13 @@ import * as beakerCore from '@beaker/core' import { app, BrowserWindow, dialog, ipcMain, Menu } from 'electron' import { createShellWindow, getFocusedDevToolsHost } from './windows' +import path from 'path' +import { download } from './downloads' // exported APIs // = -export function setup () { +export function setup() { setApplicationMenu() // watch for changes to the window's @@ -18,7 +20,7 @@ export function setup () { // rebuild as needed if (requiresRebuild(url)) { - setApplicationMenu({url}) + setApplicationMenu({ url }) } }) @@ -30,7 +32,7 @@ export function setup () { // rebuild as needed if (requiresRebuild(url)) { - setApplicationMenu({url}) + setApplicationMenu({ url }) } } catch (e) { // `pages` not set yet @@ -38,11 +40,11 @@ export function setup () { }) } -export function setApplicationMenu (opts = {}) { +export function setApplicationMenu(opts = {}) { Menu.setApplicationMenu(Menu.buildFromTemplate(buildWindowMenu(opts))) } -export function buildWindowMenu (opts = {}) { +export function buildWindowMenu(opts = {}) { const isDat = opts.url && opts.url.startsWith('dat://') var darwinMenu = { @@ -51,7 +53,7 @@ export function buildWindowMenu (opts = {}) { { label: 'Preferences', accelerator: 'Command+,', - click (item, win) { + click(item, win) { if (win) win.webContents.send('command', 'file:new-tab', 'beaker://settings') } }, @@ -62,7 +64,7 @@ export function buildWindowMenu (opts = {}) { { label: 'Hide Others', accelerator: 'Command+Alt+H', role: 'hideothers' }, { label: 'Show All', role: 'unhide' }, { type: 'separator' }, - { label: 'Quit', accelerator: 'Command+Q', click () { app.quit() }, reserved: true } + { label: 'Quit', accelerator: 'Command+Q', click() { app.quit() }, reserved: true } ] } @@ -116,7 +118,11 @@ export function buildWindowMenu (opts = {}) { accelerator: 'CmdOrCtrl+S', click: async (item, win) => { const url = await win.webContents.executeJavaScript(`pages.getActive().getIntendedURL()`) - win.webContents.downloadURL(url, true) + const title = await win.webContents.executeJavaScript(`pages.getActive().title`) + const defaultPath = path.join(app.getPath('downloads'), path.basename(title)) + dialog.showSaveDialog({ title: `Save ${title} as...`, defaultPath: defaultPath }, filepath => { + if (filepath) download(win, win.webContents, url, { saveAs: filepath }) + }) } }, { @@ -199,103 +205,103 @@ export function buildWindowMenu (opts = {}) { }, reserved: true }, - { - label: 'Hard Reload (Clear Cache)', - accelerator: 'CmdOrCtrl+Shift+R', - click: function (item, win) { - // HACK - // this is *super* lazy but it works - // clear all dat-dns cache on hard reload, to make sure the next - // load is fresh - // -prf - beakerCore.dat.dns.flushCache() + { + label: 'Hard Reload (Clear Cache)', + accelerator: 'CmdOrCtrl+Shift+R', + click: function (item, win) { + // HACK + // this is *super* lazy but it works + // clear all dat-dns cache on hard reload, to make sure the next + // load is fresh + // -prf + beakerCore.dat.dns.flushCache() - if (win) win.webContents.send('command', 'view:hard-reload') - }, - reserved: true + if (win) win.webContents.send('command', 'view:hard-reload') }, + reserved: true + }, { type: 'separator' }, - { - label: 'Zoom In', - accelerator: 'CmdOrCtrl+Plus', - reserved: true, - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-in') - } - }, - { - label: 'Zoom Out', - accelerator: 'CmdOrCtrl+-', - reserved: true, - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-out') + { + label: 'Zoom In', + accelerator: 'CmdOrCtrl+Plus', + reserved: true, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:zoom-in') + } + }, + { + label: 'Zoom Out', + accelerator: 'CmdOrCtrl+-', + reserved: true, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:zoom-out') + } + }, + { + label: 'Actual Size', + accelerator: 'CmdOrCtrl+0', + click: function (item, win) { + if (win) win.webContents.send('command', 'view:zoom-reset') + } + }, + { type: 'separator' }, + { + type: 'submenu', + label: 'Advanced Tools', + submenu: [{ + label: 'Reload Shell-Window', + accelerator: 'CmdOrCtrl+alt+shift+R', + click: function () { + BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache() } - }, - { - label: 'Actual Size', - accelerator: 'CmdOrCtrl+0', - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-reset') + }, { + label: 'Toggle Shell-Window DevTools', + accelerator: 'CmdOrCtrl+alt+shift+I', + click: function () { + BrowserWindow.getFocusedWindow().toggleDevTools() } }, - { type: 'separator' }, - { - type: 'submenu', - label: 'Advanced Tools', - submenu: [{ - label: 'Reload Shell-Window', - accelerator: 'CmdOrCtrl+alt+shift+R', - click: function () { - BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache() - } - }, { - label: 'Toggle Shell-Window DevTools', - accelerator: 'CmdOrCtrl+alt+shift+I', - click: function () { - BrowserWindow.getFocusedWindow().toggleDevTools() - } - }, { type: 'separator' }, - { - label: 'Open Archives Debug Page', - click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://internal-archives/') - } - }, { - label: 'Open Dat-DNS Cache Page', - click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://dat-dns-cache/') - } - }, { - label: 'Open Debug Log Page', - click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://debug-log/') - } - }] - }, { - label: 'Toggle DevTools', - accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+I' : 'Shift+CmdOrCtrl+I', + label: 'Open Archives Debug Page', click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-dev-tools') - }, - reserved: true - }, - { - label: 'Toggle Javascript Console', - accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+J' : 'Shift+CmdOrCtrl+J', + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://internal-archives/') + } + }, { + label: 'Open Dat-DNS Cache Page', click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-javascript-console') - }, - reserved: true - }, - { - label: 'Toggle Live Reloading', - enabled: !!isDat, + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://dat-dns-cache/') + } + }, { + label: 'Open Debug Log Page', click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-live-reloading') + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://debug-log/') } }] + }, + { + label: 'Toggle DevTools', + accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+I' : 'Shift+CmdOrCtrl+I', + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-dev-tools') + }, + reserved: true + }, + { + label: 'Toggle Javascript Console', + accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+J' : 'Shift+CmdOrCtrl+J', + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-javascript-console') + }, + reserved: true + }, + { + label: 'Toggle Live Reloading', + enabled: !!isDat, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-live-reloading') + } + }] } var showHistoryAccelerator = 'Ctrl+h' @@ -421,7 +427,7 @@ export function buildWindowMenu (opts = {}) { // = var lastURLProtocol = false -function requiresRebuild (url) { +function requiresRebuild(url) { const urlProtocol = url ? url.split(':')[0] : false // check if this is a change of protocol const b = (lastURLProtocol !== urlProtocol) From a79db76a9bdb3c0e567623252ebc0dd82eb3f771 Mon Sep 17 00:00:00 2001 From: Wesley McCann Date: Sun, 7 Oct 2018 22:07:44 -0600 Subject: [PATCH 2/4] Added prompt when saving html page Fixed an issue that emerged when implementing this. I don't believe when downloading an `.html` page that we'd want the browser toolbar to open. The one with Downloads, History, etc. If we do want that to open, we can easily update this pull request to allow that. --- app/background-process/ui/downloads.js | 4 +- app/background-process/ui/window-menu.js | 192 ++++++++++++----------- 2 files changed, 102 insertions(+), 94 deletions(-) diff --git a/app/background-process/ui/downloads.js b/app/background-process/ui/downloads.js index a654d95186..97a0b743e8 100644 --- a/app/background-process/ui/downloads.js +++ b/app/background-process/ui/downloads.js @@ -61,7 +61,9 @@ export function registerListener (win, opts = {}) { } downloads.push(item) - downloadsEvents.emit('new-download', toJSON(item)) + + if(!item.name.includes(".html")) + downloadsEvents.emit('new-download', toJSON(item)) // update dock-icon progress bar var lastBytes = 0 diff --git a/app/background-process/ui/window-menu.js b/app/background-process/ui/window-menu.js index 6733a41e0e..fd98dd2dec 100644 --- a/app/background-process/ui/window-menu.js +++ b/app/background-process/ui/window-menu.js @@ -1,11 +1,13 @@ import * as beakerCore from '@beaker/core' import { app, BrowserWindow, dialog, ipcMain, Menu } from 'electron' import { createShellWindow, getFocusedDevToolsHost } from './windows' +import path from 'path' +import { download } from './downloads' // exported APIs // = -export function setup () { +export function setup() { setApplicationMenu() // watch for changes to the window's @@ -18,7 +20,7 @@ export function setup () { // rebuild as needed if (requiresRebuild(url)) { - setApplicationMenu({url}) + setApplicationMenu({ url }) } }) @@ -30,7 +32,7 @@ export function setup () { // rebuild as needed if (requiresRebuild(url)) { - setApplicationMenu({url}) + setApplicationMenu({ url }) } } catch (e) { // `pages` not set yet @@ -38,11 +40,11 @@ export function setup () { }) } -export function setApplicationMenu (opts = {}) { +export function setApplicationMenu(opts = {}) { Menu.setApplicationMenu(Menu.buildFromTemplate(buildWindowMenu(opts))) } -export function buildWindowMenu (opts = {}) { +export function buildWindowMenu(opts = {}) { const isDat = opts.url && opts.url.startsWith('dat://') var darwinMenu = { @@ -51,7 +53,7 @@ export function buildWindowMenu (opts = {}) { { label: 'Preferences', accelerator: 'Command+,', - click (item, win) { + click(item, win) { if (win) win.webContents.send('command', 'file:new-tab', 'beaker://settings') } }, @@ -62,7 +64,7 @@ export function buildWindowMenu (opts = {}) { { label: 'Hide Others', accelerator: 'Command+Alt+H', role: 'hideothers' }, { label: 'Show All', role: 'unhide' }, { type: 'separator' }, - { label: 'Quit', accelerator: 'Command+Q', click () { app.quit() }, reserved: true } + { label: 'Quit', accelerator: 'Command+Q', click() { app.quit() }, reserved: true } ] } @@ -116,7 +118,11 @@ export function buildWindowMenu (opts = {}) { accelerator: 'CmdOrCtrl+S', click: async (item, win) => { const url = await win.webContents.executeJavaScript(`pages.getActive().getIntendedURL()`) - win.webContents.downloadURL(url, true) + const title = await win.webContents.executeJavaScript(`pages.getActive().title`) + const defaultPath = path.join(app.getPath('downloads'), path.basename(title)) + dialog.showSaveDialog({ title: `Save ${title} as...`, defaultPath: defaultPath }, filepath => { + if (filepath) download(win, win.webContents, url, { saveAs: filepath }) + }) } }, { @@ -199,103 +205,103 @@ export function buildWindowMenu (opts = {}) { }, reserved: true }, - { - label: 'Hard Reload (Clear Cache)', - accelerator: 'CmdOrCtrl+Shift+R', - click: function (item, win) { - // HACK - // this is *super* lazy but it works - // clear all dat-dns cache on hard reload, to make sure the next - // load is fresh - // -prf - beakerCore.dat.dns.flushCache() + { + label: 'Hard Reload (Clear Cache)', + accelerator: 'CmdOrCtrl+Shift+R', + click: function (item, win) { + // HACK + // this is *super* lazy but it works + // clear all dat-dns cache on hard reload, to make sure the next + // load is fresh + // -prf + beakerCore.dat.dns.flushCache() - if (win) win.webContents.send('command', 'view:hard-reload') - }, - reserved: true + if (win) win.webContents.send('command', 'view:hard-reload') }, + reserved: true + }, { type: 'separator' }, - { - label: 'Zoom In', - accelerator: 'CmdOrCtrl+Plus', - reserved: true, - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-in') - } - }, - { - label: 'Zoom Out', - accelerator: 'CmdOrCtrl+-', - reserved: true, - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-out') + { + label: 'Zoom In', + accelerator: 'CmdOrCtrl+Plus', + reserved: true, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:zoom-in') + } + }, + { + label: 'Zoom Out', + accelerator: 'CmdOrCtrl+-', + reserved: true, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:zoom-out') + } + }, + { + label: 'Actual Size', + accelerator: 'CmdOrCtrl+0', + click: function (item, win) { + if (win) win.webContents.send('command', 'view:zoom-reset') + } + }, + { type: 'separator' }, + { + type: 'submenu', + label: 'Advanced Tools', + submenu: [{ + label: 'Reload Shell-Window', + accelerator: 'CmdOrCtrl+alt+shift+R', + click: function () { + BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache() } - }, - { - label: 'Actual Size', - accelerator: 'CmdOrCtrl+0', - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-reset') + }, { + label: 'Toggle Shell-Window DevTools', + accelerator: 'CmdOrCtrl+alt+shift+I', + click: function () { + BrowserWindow.getFocusedWindow().toggleDevTools() } }, - { type: 'separator' }, - { - type: 'submenu', - label: 'Advanced Tools', - submenu: [{ - label: 'Reload Shell-Window', - accelerator: 'CmdOrCtrl+alt+shift+R', - click: function () { - BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache() - } - }, { - label: 'Toggle Shell-Window DevTools', - accelerator: 'CmdOrCtrl+alt+shift+I', - click: function () { - BrowserWindow.getFocusedWindow().toggleDevTools() - } - }, { type: 'separator' }, - { - label: 'Open Archives Debug Page', - click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://internal-archives/') - } - }, { - label: 'Open Dat-DNS Cache Page', - click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://dat-dns-cache/') - } - }, { - label: 'Open Debug Log Page', - click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://debug-log/') - } - }] - }, { - label: 'Toggle DevTools', - accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+I' : 'Shift+CmdOrCtrl+I', + label: 'Open Archives Debug Page', click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-dev-tools') - }, - reserved: true - }, - { - label: 'Toggle Javascript Console', - accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+J' : 'Shift+CmdOrCtrl+J', + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://internal-archives/') + } + }, { + label: 'Open Dat-DNS Cache Page', click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-javascript-console') - }, - reserved: true - }, - { - label: 'Toggle Live Reloading', - enabled: !!isDat, + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://dat-dns-cache/') + } + }, { + label: 'Open Debug Log Page', click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-live-reloading') + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://debug-log/') } }] + }, + { + label: 'Toggle DevTools', + accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+I' : 'Shift+CmdOrCtrl+I', + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-dev-tools') + }, + reserved: true + }, + { + label: 'Toggle Javascript Console', + accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+J' : 'Shift+CmdOrCtrl+J', + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-javascript-console') + }, + reserved: true + }, + { + label: 'Toggle Live Reloading', + enabled: !!isDat, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-live-reloading') + } + }] } var showHistoryAccelerator = 'Ctrl+h' @@ -421,7 +427,7 @@ export function buildWindowMenu (opts = {}) { // = var lastURLProtocol = false -function requiresRebuild (url) { +function requiresRebuild(url) { const urlProtocol = url ? url.split(':')[0] : false // check if this is a change of protocol const b = (lastURLProtocol !== urlProtocol) From 0a6ecf04388559033d49fa6812f7e76ba608f174 Mon Sep 17 00:00:00 2001 From: Wesley McCann Date: Sun, 7 Oct 2018 22:07:44 -0600 Subject: [PATCH 3/4] Revert "Added prompt when saving html page" This reverts commit c88459a4a8962ae7468d875c18a7595fffbe9931. --- app/background-process/ui/downloads.js | 4 +- app/background-process/ui/window-menu.js | 192 +++++++++++------------ 2 files changed, 94 insertions(+), 102 deletions(-) diff --git a/app/background-process/ui/downloads.js b/app/background-process/ui/downloads.js index 97a0b743e8..a654d95186 100644 --- a/app/background-process/ui/downloads.js +++ b/app/background-process/ui/downloads.js @@ -61,9 +61,7 @@ export function registerListener (win, opts = {}) { } downloads.push(item) - - if(!item.name.includes(".html")) - downloadsEvents.emit('new-download', toJSON(item)) + downloadsEvents.emit('new-download', toJSON(item)) // update dock-icon progress bar var lastBytes = 0 diff --git a/app/background-process/ui/window-menu.js b/app/background-process/ui/window-menu.js index fd98dd2dec..6733a41e0e 100644 --- a/app/background-process/ui/window-menu.js +++ b/app/background-process/ui/window-menu.js @@ -1,13 +1,11 @@ import * as beakerCore from '@beaker/core' import { app, BrowserWindow, dialog, ipcMain, Menu } from 'electron' import { createShellWindow, getFocusedDevToolsHost } from './windows' -import path from 'path' -import { download } from './downloads' // exported APIs // = -export function setup() { +export function setup () { setApplicationMenu() // watch for changes to the window's @@ -20,7 +18,7 @@ export function setup() { // rebuild as needed if (requiresRebuild(url)) { - setApplicationMenu({ url }) + setApplicationMenu({url}) } }) @@ -32,7 +30,7 @@ export function setup() { // rebuild as needed if (requiresRebuild(url)) { - setApplicationMenu({ url }) + setApplicationMenu({url}) } } catch (e) { // `pages` not set yet @@ -40,11 +38,11 @@ export function setup() { }) } -export function setApplicationMenu(opts = {}) { +export function setApplicationMenu (opts = {}) { Menu.setApplicationMenu(Menu.buildFromTemplate(buildWindowMenu(opts))) } -export function buildWindowMenu(opts = {}) { +export function buildWindowMenu (opts = {}) { const isDat = opts.url && opts.url.startsWith('dat://') var darwinMenu = { @@ -53,7 +51,7 @@ export function buildWindowMenu(opts = {}) { { label: 'Preferences', accelerator: 'Command+,', - click(item, win) { + click (item, win) { if (win) win.webContents.send('command', 'file:new-tab', 'beaker://settings') } }, @@ -64,7 +62,7 @@ export function buildWindowMenu(opts = {}) { { label: 'Hide Others', accelerator: 'Command+Alt+H', role: 'hideothers' }, { label: 'Show All', role: 'unhide' }, { type: 'separator' }, - { label: 'Quit', accelerator: 'Command+Q', click() { app.quit() }, reserved: true } + { label: 'Quit', accelerator: 'Command+Q', click () { app.quit() }, reserved: true } ] } @@ -118,11 +116,7 @@ export function buildWindowMenu(opts = {}) { accelerator: 'CmdOrCtrl+S', click: async (item, win) => { const url = await win.webContents.executeJavaScript(`pages.getActive().getIntendedURL()`) - const title = await win.webContents.executeJavaScript(`pages.getActive().title`) - const defaultPath = path.join(app.getPath('downloads'), path.basename(title)) - dialog.showSaveDialog({ title: `Save ${title} as...`, defaultPath: defaultPath }, filepath => { - if (filepath) download(win, win.webContents, url, { saveAs: filepath }) - }) + win.webContents.downloadURL(url, true) } }, { @@ -205,103 +199,103 @@ export function buildWindowMenu(opts = {}) { }, reserved: true }, - { - label: 'Hard Reload (Clear Cache)', - accelerator: 'CmdOrCtrl+Shift+R', - click: function (item, win) { - // HACK - // this is *super* lazy but it works - // clear all dat-dns cache on hard reload, to make sure the next - // load is fresh - // -prf - beakerCore.dat.dns.flushCache() + { + label: 'Hard Reload (Clear Cache)', + accelerator: 'CmdOrCtrl+Shift+R', + click: function (item, win) { + // HACK + // this is *super* lazy but it works + // clear all dat-dns cache on hard reload, to make sure the next + // load is fresh + // -prf + beakerCore.dat.dns.flushCache() - if (win) win.webContents.send('command', 'view:hard-reload') + if (win) win.webContents.send('command', 'view:hard-reload') + }, + reserved: true }, - reserved: true - }, - { type: 'separator' }, - { - label: 'Zoom In', - accelerator: 'CmdOrCtrl+Plus', - reserved: true, - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-in') - } - }, - { - label: 'Zoom Out', - accelerator: 'CmdOrCtrl+-', - reserved: true, - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-out') - } - }, - { - label: 'Actual Size', - accelerator: 'CmdOrCtrl+0', - click: function (item, win) { - if (win) win.webContents.send('command', 'view:zoom-reset') - } - }, { type: 'separator' }, - { - type: 'submenu', - label: 'Advanced Tools', - submenu: [{ - label: 'Reload Shell-Window', - accelerator: 'CmdOrCtrl+alt+shift+R', - click: function () { - BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache() - } - }, { - label: 'Toggle Shell-Window DevTools', - accelerator: 'CmdOrCtrl+alt+shift+I', - click: function () { - BrowserWindow.getFocusedWindow().toggleDevTools() + { + label: 'Zoom In', + accelerator: 'CmdOrCtrl+Plus', + reserved: true, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:zoom-in') } }, - { type: 'separator' }, { - label: 'Open Archives Debug Page', + label: 'Zoom Out', + accelerator: 'CmdOrCtrl+-', + reserved: true, click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://internal-archives/') + if (win) win.webContents.send('command', 'view:zoom-out') } - }, { - label: 'Open Dat-DNS Cache Page', + }, + { + label: 'Actual Size', + accelerator: 'CmdOrCtrl+0', click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://dat-dns-cache/') + if (win) win.webContents.send('command', 'view:zoom-reset') } - }, { - label: 'Open Debug Log Page', + }, + { type: 'separator' }, + { + type: 'submenu', + label: 'Advanced Tools', + submenu: [{ + label: 'Reload Shell-Window', + accelerator: 'CmdOrCtrl+alt+shift+R', + click: function () { + BrowserWindow.getFocusedWindow().webContents.reloadIgnoringCache() + } + }, { + label: 'Toggle Shell-Window DevTools', + accelerator: 'CmdOrCtrl+alt+shift+I', + click: function () { + BrowserWindow.getFocusedWindow().toggleDevTools() + } + }, + { type: 'separator' }, + { + label: 'Open Archives Debug Page', + click: function (item, win) { + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://internal-archives/') + } + }, { + label: 'Open Dat-DNS Cache Page', + click: function (item, win) { + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://dat-dns-cache/') + } + }, { + label: 'Open Debug Log Page', + click: function (item, win) { + if (win) win.webContents.send('command', 'file:new-tab', 'beaker://debug-log/') + } + }] + }, + { + label: 'Toggle DevTools', + accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+I' : 'Shift+CmdOrCtrl+I', click: function (item, win) { - if (win) win.webContents.send('command', 'file:new-tab', 'beaker://debug-log/') - } - }] - }, - { - label: 'Toggle DevTools', - accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+I' : 'Shift+CmdOrCtrl+I', - click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-dev-tools') + if (win) win.webContents.send('command', 'view:toggle-dev-tools') + }, + reserved: true }, - reserved: true - }, - { - label: 'Toggle Javascript Console', - accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+J' : 'Shift+CmdOrCtrl+J', - click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-javascript-console') + { + label: 'Toggle Javascript Console', + accelerator: (process.platform === 'darwin') ? 'Alt+CmdOrCtrl+J' : 'Shift+CmdOrCtrl+J', + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-javascript-console') + }, + reserved: true }, - reserved: true - }, - { - label: 'Toggle Live Reloading', - enabled: !!isDat, - click: function (item, win) { - if (win) win.webContents.send('command', 'view:toggle-live-reloading') - } - }] + { + label: 'Toggle Live Reloading', + enabled: !!isDat, + click: function (item, win) { + if (win) win.webContents.send('command', 'view:toggle-live-reloading') + } + }] } var showHistoryAccelerator = 'Ctrl+h' @@ -427,7 +421,7 @@ export function buildWindowMenu(opts = {}) { // = var lastURLProtocol = false -function requiresRebuild(url) { +function requiresRebuild (url) { const urlProtocol = url ? url.split(':')[0] : false // check if this is a change of protocol const b = (lastURLProtocol !== urlProtocol) From 71f50304eee496da05a365a1e6487f9c7fd9ac48 Mon Sep 17 00:00:00 2001 From: Wesley McCann Date: Mon, 8 Oct 2018 14:01:21 -0600 Subject: [PATCH 4/4] PR Fixes Removed the plethora of whitespace changes. Added code comments about the suppression of `new-download` event. --- app/background-process/ui/downloads.js | 7 ++++++- app/background-process/ui/window-menu.js | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/background-process/ui/downloads.js b/app/background-process/ui/downloads.js index a654d95186..e38e8fc887 100644 --- a/app/background-process/ui/downloads.js +++ b/app/background-process/ui/downloads.js @@ -61,7 +61,12 @@ export function registerListener (win, opts = {}) { } downloads.push(item) - downloadsEvents.emit('new-download', toJSON(item)) + + // This is to prevent the browser-dropdown-menu from opening + // For now it is being used when downloading `.html` pages + if (!opts.suppressNewDownloadEvent) { + downloadsEvents.emit('new-download', toJSON(item)) + } // update dock-icon progress bar var lastBytes = 0 diff --git a/app/background-process/ui/window-menu.js b/app/background-process/ui/window-menu.js index 6733a41e0e..74632f13af 100644 --- a/app/background-process/ui/window-menu.js +++ b/app/background-process/ui/window-menu.js @@ -1,6 +1,7 @@ import * as beakerCore from '@beaker/core' import { app, BrowserWindow, dialog, ipcMain, Menu } from 'electron' import { createShellWindow, getFocusedDevToolsHost } from './windows' +import download from './downloads' // exported APIs // = @@ -116,7 +117,10 @@ export function buildWindowMenu (opts = {}) { accelerator: 'CmdOrCtrl+S', click: async (item, win) => { const url = await win.webContents.executeJavaScript(`pages.getActive().getIntendedURL()`) - win.webContents.downloadURL(url, true) + const title = await win.webContents.executeJavaScript(`pages.getActive().title`) + dialog.showSaveDialog({ title: `Save ${title} as...`, defaultPath: app.getPath('downloads') }, filepath => { + if (filepath) download(win, win.webContents, url, { saveAs: filepath, suppressNewDownloadEvent: true }) + }) } }, {