diff --git a/package.json b/package.json index 731df3535..52c4753c4 100644 --- a/package.json +++ b/package.json @@ -39,14 +39,12 @@ "package:publish": "./node_modules/.bin/electron-builder --config electron-builder-config.yml --publish onTag" }, "devDependencies": { - "@types/cheerio": "^0.22.13", "@types/color": "^3.0.0", "@types/jest": "^24.0.17", "@types/mathjs": "^5.0.1", "@types/node-powershell": "^3.1.0", "@types/vue-color": "^2.4.2", "axios": "^0.19.0", - "cheerio": "^1.0.0-rc.3", "color": "^3.1.2", "electron": "^5.0.9", "electron-builder": "^21.2.0", diff --git a/src/common/config/browser-bookmarks-options.ts b/src/common/config/browser-bookmarks-options.ts index e86d67e7c..ea27cce82 100644 --- a/src/common/config/browser-bookmarks-options.ts +++ b/src/common/config/browser-bookmarks-options.ts @@ -3,11 +3,9 @@ import { Browser } from "../../main/plugins/browser-bookmarks-plugin/browser"; export interface BrowserBookmarksOptions { isEnabled: boolean; browser: Browser; - useFavicons: boolean; } export const defaultBrowserBookmarksOptions: BrowserBookmarksOptions = { browser: Browser.GoogleChrome, isEnabled: true, - useFavicons: false, }; diff --git a/src/main/main.ts b/src/main/main.ts index 81fefcf4b..8f86ab40f 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -299,6 +299,7 @@ function updateMainWindowSize(searchResultCount: number, appearanceOptions: Appe function reloadApp() { updateMainWindowSize(0, config.appearanceOptions); searchEngine = getProductionSearchEngine(config, translationSet, logger); + refreshAllIndexes(); mainWindow.reload(); } diff --git a/src/main/plugins/browser-bookmarks-plugin/browser-bookmark-repository.ts b/src/main/plugins/browser-bookmarks-plugin/browser-bookmark-repository.ts index 5563112e1..84a8a44ab 100644 --- a/src/main/plugins/browser-bookmarks-plugin/browser-bookmark-repository.ts +++ b/src/main/plugins/browser-bookmarks-plugin/browser-bookmark-repository.ts @@ -6,5 +6,4 @@ export interface BrowserBookmarkRepository { browser: Browser; defaultIcon: Icon; getBrowserBookmarks(): Promise; - updateUseFaviconOption(useNativeIcons: boolean): void; } diff --git a/src/main/plugins/browser-bookmarks-plugin/browser-bookmark.ts b/src/main/plugins/browser-bookmarks-plugin/browser-bookmark.ts index c91a6b579..5a9e0bd7a 100644 --- a/src/main/plugins/browser-bookmarks-plugin/browser-bookmark.ts +++ b/src/main/plugins/browser-bookmarks-plugin/browser-bookmark.ts @@ -1,7 +1,4 @@ -import { Icon } from "../../../common/icon/icon"; - export interface BrowserBookmark { name: string; url: string; - icon: Icon; } diff --git a/src/main/plugins/browser-bookmarks-plugin/browser-bookmarks-plugin.ts b/src/main/plugins/browser-bookmarks-plugin/browser-bookmarks-plugin.ts index 4ac87c02d..e801c372f 100644 --- a/src/main/plugins/browser-bookmarks-plugin/browser-bookmarks-plugin.ts +++ b/src/main/plugins/browser-bookmarks-plugin/browser-bookmarks-plugin.ts @@ -64,15 +64,8 @@ export class BrowserBookmarksPlugin implements SearchPlugin { this.translations = translationSet; const browserChanged = updatedConfig.browserBookmarksOptions.browser !== this.config.browser; - const useFaviconsOptionChanged = updatedConfig.browserBookmarksOptions.useFavicons !== this.config.useFavicons; - if (useFaviconsOptionChanged) { - this.browserBookmarkRepositories.forEach((browserBookmarkRepository) => { - browserBookmarkRepository.updateUseFaviconOption(updatedConfig.browserBookmarksOptions.useFavicons); - }); - } - - if (useFaviconsOptionChanged || browserChanged) { + if (browserChanged) { this.config = updatedConfig.browserBookmarksOptions; this.refreshIndex() .then(() => resolve()) @@ -106,7 +99,7 @@ export class BrowserBookmarksPlugin implements SearchPlugin { : `${this.config.browser} ${this.translations.browserBookmark}`, executionArgument: browserBookmark.url, hideMainWindowAfterExecution: true, - icon: browserBookmark.icon, + icon: this.getMatchingBrowserBookmarkRepository().defaultIcon, name: browserBookmark.name || browserBookmark.url, needsUserConfirmationBeforeExecution: false, originPluginType: this.pluginType, diff --git a/src/main/plugins/browser-bookmarks-plugin/google-chrome-bookmark-repository.ts b/src/main/plugins/browser-bookmarks-plugin/google-chrome-bookmark-repository.ts index 2b513d946..1a8dd99d2 100644 --- a/src/main/plugins/browser-bookmarks-plugin/google-chrome-bookmark-repository.ts +++ b/src/main/plugins/browser-bookmarks-plugin/google-chrome-bookmark-repository.ts @@ -3,8 +3,6 @@ import { BrowserBookmark } from "./browser-bookmark"; import { FileHelpers } from "../../../common/helpers/file-helpers"; import { isValidUrl } from "../../../common/helpers/url-helpers"; import { Browser } from "./browser"; -import axios from "axios"; -import * as cheerio from "cheerio"; import { IconType } from "../../../common/icon/icon-type"; import { Icon } from "../../../common/icon/icon"; @@ -16,11 +14,9 @@ export class GoogleChromeBookmarkRepository implements BrowserBookmarkRepository }; private readonly bookmarkFilePath: string; - private useFavicons: boolean; - constructor(bookmarkFilePath: string, useFavicons: boolean) { + constructor(bookmarkFilePath: string) { this.bookmarkFilePath = bookmarkFilePath; - this.useFavicons = useFavicons; } public getBrowserBookmarks(): Promise { @@ -32,11 +28,7 @@ export class GoogleChromeBookmarkRepository implements BrowserBookmarkRepository .then((data) => { const jsonParsed = JSON.parse(data); const bookmarks: BrowserBookmark[] = this.getBookmarksFromObject(jsonParsed.roots.bookmark_bar); - this.getIcons(bookmarks) - .then((result) => { - resolve(result); - }) - .catch((err) => reject(err)); + resolve(bookmarks); }) .catch((err) => reject(`Can't read bookmarks file: ${err}`)); } else { @@ -47,10 +39,6 @@ export class GoogleChromeBookmarkRepository implements BrowserBookmarkRepository }); } - public updateUseFaviconOption(useFavicons: boolean) { - this.useFavicons = useFavicons; - } - private getBookmarksFromObject(data: any): any[] { let result: any[] = []; @@ -76,65 +64,4 @@ export class GoogleChromeBookmarkRepository implements BrowserBookmarkRepository return result; } - - private getIcons(bookmarks: BrowserBookmark[]): Promise { - return new Promise((resolve, reject) => { - if (bookmarks.length === 0) { - resolve([]); - } else { - const promises = bookmarks.map((bookmark) => this.getIcon(bookmark)); - Promise.all(promises) - .then((result) => { - resolve(result); - }) - .catch((err) => reject(err)); - } - }); - } - - private getIcon(bookmark: BrowserBookmark): Promise { - return new Promise((resolve) => { - const handleResult = (icon?: Icon) => { - if (icon) { - bookmark.icon = icon; - } else { - bookmark.icon = this.defaultIcon; - } - resolve(bookmark); - }; - - if (this.useFavicons) { - axios.get(bookmark.url) - .then((data) => { - const $ = cheerio.load(data.data); - const favicons = $(`link[rel="icon"]`).toArray(); - if (favicons.length > 0) { - if (favicons[0].attribs && favicons[0].attribs.href) { - handleResult({ - parameter: this.getFaviconUrl(favicons[0].attribs.href, bookmark), - type: IconType.URL, - }); - } else { - handleResult(); - } - } else { - handleResult(); - } - }) - .catch(() => handleResult()); - } else { - handleResult(); - } - }); - } - - private getFaviconUrl(faviconUrl: string, bookmark: BrowserBookmark): string { - if (!faviconUrl.startsWith("http://") && - !faviconUrl.startsWith("https://") && - !faviconUrl.startsWith("www.")) { - const slash = faviconUrl.startsWith("/") ? "" : "/"; - faviconUrl = `http://${new URL(bookmark.url).host}${slash}${faviconUrl}`; - } - return faviconUrl; - } } diff --git a/src/main/production/production-search-engine.ts b/src/main/production/production-search-engine.ts index 37fda12aa..f41c64be5 100644 --- a/src/main/production/production-search-engine.ts +++ b/src/main/production/production-search-engine.ts @@ -120,7 +120,7 @@ export function getProductionSearchEngine(config: UserConfigOptions, translation new BrowserBookmarksPlugin( config.browserBookmarksOptions, translationSet, - [new GoogleChromeBookmarkRepository(chromeBookmarksFilePath, config.browserBookmarksOptions.useFavicons)], + [new GoogleChromeBookmarkRepository(chromeBookmarksFilePath)], urlExecutor, ), ]; diff --git a/yarn.lock b/yarn.lock index d8d4f7c70..085f3d945 100644 --- a/yarn.lock +++ b/yarn.lock @@ -348,13 +348,6 @@ dependencies: "@babel/types" "^7.3.0" -"@types/cheerio@^0.22.13": - version "0.22.13" - resolved "https://registry.yarnpkg.com/@types/cheerio/-/cheerio-0.22.13.tgz#5eecda091a24514185dcba99eda77e62bf6523e6" - integrity sha512-OZd7dCUOUkiTorf97vJKwZnSja/DmHfuBAroe1kREZZTCf/tlFecwHhsOos3uVHxeKGZDwzolIrCUApClkdLuA== - dependencies: - "@types/node" "*" - "@types/color-convert@*": version "1.9.0" resolved "https://registry.yarnpkg.com/@types/color-convert/-/color-convert-1.9.0.tgz#bfa8203e41e7c65471e9841d7e306a7cd8b5172d" @@ -980,11 +973,6 @@ bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" integrity sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA== -boolbase@~1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e" - integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24= - boxen@^3.0.0: version "3.2.0" resolved "https://registry.yarnpkg.com/boxen/-/boxen-3.2.0.tgz#fbdff0de93636ab4450886b6ff45b92d098f45eb" @@ -1298,18 +1286,6 @@ chalk@2.4.2, chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4. escape-string-regexp "^1.0.5" supports-color "^5.3.0" -cheerio@^1.0.0-rc.3: - version "1.0.0-rc.3" - resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.3.tgz#094636d425b2e9c0f4eb91a46c05630c9a1a8bf6" - integrity sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA== - dependencies: - css-select "~1.2.0" - dom-serializer "~0.1.1" - entities "~1.1.1" - htmlparser2 "^3.9.1" - lodash "^4.15.0" - parse5 "^3.0.1" - chokidar@^2.0.2: version "2.1.6" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-2.1.6.tgz#b6cad653a929e244ce8a834244164d241fa954c5" @@ -1667,21 +1643,6 @@ crypto-random-string@^1.0.0: resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-1.0.0.tgz#a230f64f568310e1498009940790ec99545bca7e" integrity sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4= -css-select@~1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/css-select/-/css-select-1.2.0.tgz#2b3a110539c5355f1cd8d314623e870b121ec858" - integrity sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg= - dependencies: - boolbase "~1.0.0" - css-what "2.1" - domutils "1.5.1" - nth-check "~1.0.1" - -css-what@2.1: - version "2.1.3" - resolved "https://registry.yarnpkg.com/css-what/-/css-what-2.1.3.tgz#a6d7604573365fe74686c3f311c56513d88285f2" - integrity sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg== - cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0": version "0.3.8" resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.8.tgz#9f1276f5b2b463f2114d3f2c75250af8c1a36f4a" @@ -1895,37 +1856,11 @@ dmg-builder@21.2.0: js-yaml "^3.13.1" sanitize-filename "^1.6.2" -dom-serializer@0: - version "0.2.1" - resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.2.1.tgz#13650c850daffea35d8b626a4cfc4d3a17643fdb" - integrity sha512-sK3ujri04WyjwQXVoK4PU3y8ula1stq10GJZpqHIUgoGZdsGzAGu65BnU3d08aTVSvO7mGPZUc0wTEDL+qGE0Q== - dependencies: - domelementtype "^2.0.1" - entities "^2.0.0" - -dom-serializer@~0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.1.1.tgz#1ec4059e284babed36eec2941d4a970a189ce7c0" - integrity sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA== - dependencies: - domelementtype "^1.3.0" - entities "^1.1.1" - domain-browser@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.2.0.tgz#3d31f50191a6749dd1375a7f522e823d42e54eda" integrity sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA== -domelementtype@1, domelementtype@^1.3.0, domelementtype@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.1.tgz#d048c44b37b0d10a7f2a3d5fee3f4333d790481f" - integrity sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w== - -domelementtype@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.0.1.tgz#1f8bdfe91f5a78063274e803b4bdcedf6e94f94d" - integrity sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ== - domexception@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/domexception/-/domexception-1.0.1.tgz#937442644ca6a31261ef36e3ec677fe805582c90" @@ -1933,29 +1868,6 @@ domexception@^1.0.1: dependencies: webidl-conversions "^4.0.2" -domhandler@^2.3.0: - version "2.4.2" - resolved "https://registry.yarnpkg.com/domhandler/-/domhandler-2.4.2.tgz#8805097e933d65e85546f726d60f5eb88b44f803" - integrity sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA== - dependencies: - domelementtype "1" - -domutils@1.5.1: - version "1.5.1" - resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.5.1.tgz#dcd8488a26f563d61079e48c9f7b7e32373682cf" - integrity sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8= - dependencies: - dom-serializer "0" - domelementtype "1" - -domutils@^1.5.1: - version "1.7.0" - resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.7.0.tgz#56ea341e834e06e6748af7a1cb25da67ea9f8c2a" - integrity sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg== - dependencies: - dom-serializer "0" - domelementtype "1" - dot-prop@^4.1.0: version "4.2.0" resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-4.2.0.tgz#1f19e0c2e1aa0e32797c49799f2837ac6af69c57" @@ -2132,16 +2044,6 @@ enhanced-resolve@4.1.0, enhanced-resolve@^4.0.0, enhanced-resolve@^4.1.0: memory-fs "^0.4.0" tapable "^1.0.0" -entities@^1.1.1, entities@~1.1.1: - version "1.1.2" - resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56" - integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== - -entities@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/entities/-/entities-2.0.0.tgz#68d6084cab1b079767540d80e56a39b423e4abf4" - integrity sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw== - env-paths@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0" @@ -2874,18 +2776,6 @@ html-encoding-sniffer@^1.0.2: dependencies: whatwg-encoding "^1.0.1" -htmlparser2@^3.9.1: - version "3.10.1" - resolved "https://registry.yarnpkg.com/htmlparser2/-/htmlparser2-3.10.1.tgz#bd679dc3f59897b6a34bb10749c855bb53a9392f" - integrity sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ== - dependencies: - domelementtype "^1.3.1" - domhandler "^2.3.0" - domutils "^1.5.1" - entities "^1.1.1" - inherits "^2.0.1" - readable-stream "^3.1.1" - http-cache-semantics@^4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.0.3.tgz#495704773277eeef6e43f9ab2c2c7d259dda25c5" @@ -3942,7 +3832,7 @@ lodash.throttle@^4.0.0: resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4" integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ= -lodash@^4.15.0, lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14: +lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14: version "4.17.15" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== @@ -4481,13 +4371,6 @@ npmlog@^4.0.2: gauge "~2.7.3" set-blocking "~2.0.0" -nth-check@~1.0.1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.2.tgz#b2bd295c37e3dd58a3bf0700376663ba4d9cf05c" - integrity sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg== - dependencies: - boolbase "~1.0.0" - nugget@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/nugget/-/nugget-2.0.1.tgz#201095a487e1ad36081b3432fa3cada4f8d071b0" @@ -4738,13 +4621,6 @@ parse5@4.0.0: resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608" integrity sha512-VrZ7eOd3T1Fk4XWNXMgiGBK/z0MG48BWG2uQNU4I72fkQuKUTZpl+u9k+CxEG0twMVzSmXEEz12z5Fnw1jIQFA== -parse5@^3.0.1: - version "3.0.3" - resolved "https://registry.yarnpkg.com/parse5/-/parse5-3.0.3.tgz#042f792ffdd36851551cf4e9e066b3874ab45b5c" - integrity sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA== - dependencies: - "@types/node" "*" - pascalcase@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"