diff options
author | 2021-05-15 18:34:25 +0530 | |
---|---|---|
committer | 2021-05-15 15:04:25 +0200 | |
commit | 8ef5380b941a8f1483ee5d30e61a5086e669b12e (patch) | |
tree | 8e4db26f558722622738c17c21f97187cdb23ea0 /src/webview | |
parent | Minor refactoring to have consistent command-line invocations. (diff) | |
download | ferdium-app-8ef5380b941a8f1483ee5d30e61a5086e669b12e.tar.gz ferdium-app-8ef5380b941a8f1483ee5d30e61a5086e669b12e.tar.zst ferdium-app-8ef5380b941a8f1483ee5d30e61a5086e669b12e.zip |
Adding DuckDuckGo as an alternative search engine (#1414)
* Adding DuckDuckGo as an alternative search engine.
* Fixing review comments.
* Fixing review comments.
Diffstat (limited to 'src/webview')
-rw-r--r-- | src/webview/contextMenu.js | 4 | ||||
-rw-r--r-- | src/webview/contextMenuBuilder.js | 9 | ||||
-rw-r--r-- | src/webview/recipe.js | 2 |
3 files changed, 9 insertions, 6 deletions
diff --git a/src/webview/contextMenu.js b/src/webview/contextMenu.js index 679bf5aaa..5858e89ef 100644 --- a/src/webview/contextMenu.js +++ b/src/webview/contextMenu.js | |||
@@ -3,7 +3,7 @@ import ContextMenuBuilder from './contextMenuBuilder'; | |||
3 | 3 | ||
4 | const webContents = remote.getCurrentWebContents(); | 4 | const webContents = remote.getCurrentWebContents(); |
5 | 5 | ||
6 | export default async function setupContextMenu(isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage) { | 6 | export default async function setupContextMenu(isSpellcheckEnabled, getDefaultSpellcheckerLanguage, getSpellcheckerLanguage, getSearchEngine) { |
7 | const contextMenuBuilder = new ContextMenuBuilder( | 7 | const contextMenuBuilder = new ContextMenuBuilder( |
8 | webContents, | 8 | webContents, |
9 | ); | 9 | ); |
@@ -11,7 +11,7 @@ export default async function setupContextMenu(isSpellcheckEnabled, getDefaultSp | |||
11 | webContents.on('context-menu', (e, props) => { | 11 | webContents.on('context-menu', (e, props) => { |
12 | // TODO?: e.preventDefault(); | 12 | // TODO?: e.preventDefault(); |
13 | contextMenuBuilder.showPopupMenu( | 13 | contextMenuBuilder.showPopupMenu( |
14 | props, | 14 | { ...props, searchEngine: getSearchEngine() }, |
15 | isSpellcheckEnabled(), | 15 | isSpellcheckEnabled(), |
16 | getDefaultSpellcheckerLanguage(), | 16 | getDefaultSpellcheckerLanguage(), |
17 | getSpellcheckerLanguage(), | 17 | getSpellcheckerLanguage(), |
diff --git a/src/webview/contextMenuBuilder.js b/src/webview/contextMenuBuilder.js index b5095915c..49c4550a9 100644 --- a/src/webview/contextMenuBuilder.js +++ b/src/webview/contextMenuBuilder.js | |||
@@ -8,6 +8,8 @@ | |||
8 | */ | 8 | */ |
9 | import { isMac } from '../environment'; | 9 | import { isMac } from '../environment'; |
10 | 10 | ||
11 | import { SEARCH_ENGINE_NAMES, SEARCH_ENGINE_URLS } from '../config'; | ||
12 | |||
11 | const { | 13 | const { |
12 | clipboard, nativeImage, remote, shell, | 14 | clipboard, nativeImage, remote, shell, |
13 | } = require('electron'); | 15 | } = require('electron'); |
@@ -27,7 +29,7 @@ const contextMenuStringTable = { | |||
27 | cut: () => 'Cut', | 29 | cut: () => 'Cut', |
28 | copy: () => 'Copy', | 30 | copy: () => 'Copy', |
29 | paste: () => 'Paste', | 31 | paste: () => 'Paste', |
30 | searchGoogle: () => 'Search with Google', | 32 | searchWith: ({ searchEngine }) => `Search with ${searchEngine}`, |
31 | openLinkUrl: () => 'Open Link', | 33 | openLinkUrl: () => 'Open Link', |
32 | openLinkInFerdiUrl: () => 'Open Link in Ferdi', | 34 | openLinkInFerdiUrl: () => 'Open Link in Ferdi', |
33 | openInBrowser: () => 'Open in Browser', | 35 | openInBrowser: () => 'Open in Browser', |
@@ -286,10 +288,9 @@ module.exports = class ContextMenuBuilder { | |||
286 | } | 288 | } |
287 | 289 | ||
288 | const search = new MenuItem({ | 290 | const search = new MenuItem({ |
289 | label: this.stringTable.searchGoogle(), | 291 | label: this.stringTable.searchWith({ searchEngine: SEARCH_ENGINE_NAMES[menuInfo.searchEngine] }), |
290 | click: () => { | 292 | click: () => { |
291 | const url = `https://www.google.com/search?q=${encodeURIComponent(menuInfo.selectionText)}`; | 293 | const url = SEARCH_ENGINE_URLS[menuInfo.searchEngine]({ searchTerm: encodeURIComponent(menuInfo.selectionText) }); |
292 | |||
293 | shell.openExternal(url); | 294 | shell.openExternal(url); |
294 | }, | 295 | }, |
295 | }); | 296 | }); |
diff --git a/src/webview/recipe.js b/src/webview/recipe.js index 2319e8e2a..2701603cb 100644 --- a/src/webview/recipe.js +++ b/src/webview/recipe.js | |||
@@ -152,6 +152,7 @@ class RecipeController { | |||
152 | () => this.settings.app.enableSpellchecking, | 152 | () => this.settings.app.enableSpellchecking, |
153 | () => this.settings.app.spellcheckerLanguage, | 153 | () => this.settings.app.spellcheckerLanguage, |
154 | () => this.spellcheckerLanguage, | 154 | () => this.spellcheckerLanguage, |
155 | () => this.settings.app.searchEngine, | ||
155 | ); | 156 | ); |
156 | 157 | ||
157 | autorun(() => this.update()); | 158 | autorun(() => this.update()); |
@@ -230,6 +231,7 @@ class RecipeController { | |||
230 | debug('System spellcheckerLanguage', this.settings.app.spellcheckerLanguage); | 231 | debug('System spellcheckerLanguage', this.settings.app.spellcheckerLanguage); |
231 | debug('Service spellcheckerLanguage', this.settings.service.spellcheckerLanguage); | 232 | debug('Service spellcheckerLanguage', this.settings.service.spellcheckerLanguage); |
232 | debug('darkReaderSettigs', this.settings.service.darkReaderSettings); | 233 | debug('darkReaderSettigs', this.settings.service.darkReaderSettings); |
234 | debug('searchEngine', this.settings.app.searchEngine); | ||
233 | 235 | ||
234 | if (this.userscript && this.userscript.internal_setSettings) { | 236 | if (this.userscript && this.userscript.internal_setSettings) { |
235 | this.userscript.internal_setSettings(this.settings); | 237 | this.userscript.internal_setSettings(this.settings); |