From 1717eb6a5af85ea0d3688b95b32527a2dccdb031 Mon Sep 17 00:00:00 2001 From: Oliver Schwendener Date: Tue, 6 Aug 2019 18:41:00 +0200 Subject: [PATCH] Removed windows-system-icon dependency --- package.json | 3 +- .../application-icon-helpers.ts | 30 ---------- .../windows-app-icon-generator.ts | 59 +++++++++++++++++++ .../production/production-search-engine.ts | 2 +- yarn.lock | 47 ++++++++++----- 5 files changed, 94 insertions(+), 47 deletions(-) create mode 100644 src/main/plugins/application-search-plugin/windows-app-icon-generator.ts diff --git a/package.json b/package.json index 4135789db..3c85acf3b 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@types/jest": "^24.0.13", "@types/lodash": "^4.14.130", "@types/mathjs": "^5.0.1", + "@types/node-powershell": "^3.1.0", "@types/vue-color": "^2.4.2", "axios": "^0.18.0", "electron": "^5.0.5", @@ -51,6 +52,7 @@ "jest": "^24.8.0", "lodash": "^4.17.11", "mathjs": "^5.10.3", + "node-powershell": "^4.0.0", "simple-plist": "^1.0.0", "ts-jest": "^24.0.2", "ts-loader": "^6.0.1", @@ -60,7 +62,6 @@ "vue-color": "^2.7.0", "webpack": "^4.32.2", "webpack-cli": "^3.3.2", - "windows-system-icon": "0.0.5", "winston": "^3.2.1" }, "dependencies": { diff --git a/src/main/plugins/application-search-plugin/application-icon-helpers.ts b/src/main/plugins/application-search-plugin/application-icon-helpers.ts index 63846ebb3..925624448 100644 --- a/src/main/plugins/application-search-plugin/application-icon-helpers.ts +++ b/src/main/plugins/application-search-plugin/application-icon-helpers.ts @@ -1,9 +1,7 @@ import { join, basename, extname } from "path"; import { createHash } from "crypto"; -import { FileHelpers } from "../../../common/helpers/file-helpers"; import { ueliTempFolder } from "../../../common/helpers/ueli-helpers"; import { StringHelpers } from "../../../common/helpers/string-helpers"; -import { generateIcons, Icon } from "windows-system-icon"; export const applicationIconLocation = join(ueliTempFolder, "application-icons"); export const powershellScriptFilePath = join(ueliTempFolder, "generate-icons.ps1"); @@ -13,31 +11,3 @@ export function getApplicationIconFilePath(applicationFilePath: string): string const fileName = `${StringHelpers.replaceWhitespace(basename(applicationFilePath).replace(extname(applicationFilePath), "").toLowerCase(), "-")}-${hash}`; return `${join(applicationIconLocation, fileName)}.png`; } - -export function generateWindowsAppIcons(applicationFilePaths: string[]): Promise { - return new Promise((resolve, reject) => { - if (applicationFilePaths.length === 0) { - resolve(); - } - - FileHelpers.fileExists(applicationIconLocation) - .then((fileExists) => { - if (!fileExists) { - FileHelpers.createFolderSync(applicationIconLocation); - } - - const icons = applicationFilePaths.map((applicationFilePath): Icon => { - return { - inputFilePath: applicationFilePath, - outputFilePath: getApplicationIconFilePath(applicationFilePath), - outputFormat: "Png", - }; - }); - - generateIcons(icons) - .then(() => resolve()) - .catch((err) => reject(err)); - }) - .catch((err) => reject(err)); - }); -} diff --git a/src/main/plugins/application-search-plugin/windows-app-icon-generator.ts b/src/main/plugins/application-search-plugin/windows-app-icon-generator.ts new file mode 100644 index 000000000..1467c2f37 --- /dev/null +++ b/src/main/plugins/application-search-plugin/windows-app-icon-generator.ts @@ -0,0 +1,59 @@ +import { FileHelpers } from "../../../common/helpers/file-helpers"; +import { applicationIconLocation, getApplicationIconFilePath } from "./application-icon-helpers"; +import * as Shell from "node-powershell"; + +interface Icon { + inputFilePath: string; + outputFilePath: string; + outputFormat: string; +} + +export function generateWindowsAppIcons(applicationFilePaths: string[]): Promise { + return new Promise((resolve, reject) => { + if (applicationFilePaths.length === 0) { + resolve(); + } + + FileHelpers.fileExists(applicationIconLocation) + .then((fileExists) => { + if (!fileExists) { + FileHelpers.createFolderSync(applicationIconLocation); + } + + const icons = applicationFilePaths.map((applicationFilePath): Icon => { + return { + inputFilePath: applicationFilePath, + outputFilePath: getApplicationIconFilePath(applicationFilePath), + outputFormat: "Png", + }; + }); + + generateIcons(icons) + .then(() => resolve()) + .catch((err) => reject(err)); + }) + .catch((err) => reject(err)); + }); +} + +function generateIcons(icons: Icon[], followShortcuts?: boolean): Promise { + return new Promise((resolve, reject) => { + const ps = new Shell({ + executionPolicy: "Bypass", + noProfile: true, + }); + + ps.addCommand(`Add-Type -AssemblyName System.Drawing`); + + icons.forEach((icon) => { + ps.addCommand(`$fileExists = Test-Path -Path "${icon.inputFilePath}";`); + ps.addCommand(`if($fileExists) { $icon = [System.Drawing.Icon]::ExtractAssociatedIcon("${icon.inputFilePath}"); }`); + ps.addCommand(`if($fileExists) { $bitmap = $icon.ToBitmap().save("${icon.outputFilePath}", [System.Drawing.Imaging.ImageFormat]::${icon.outputFormat}); }`); + }); + + ps.invoke() + .then(() => resolve()) + .catch((err) => reject(err)) + .finally(() => ps.dispose()); + }); +} diff --git a/src/main/production/production-search-engine.ts b/src/main/production/production-search-engine.ts index e547f5598..3435e1fbf 100644 --- a/src/main/production/production-search-engine.ts +++ b/src/main/production/production-search-engine.ts @@ -2,7 +2,7 @@ import { ApplicationSearchPlugin } from "../plugins/application-search-plugin/ap import { UserConfigOptions } from "../../common/config/user-config-options"; import { FileApplicationRepository } from "../plugins/application-search-plugin/file-application-repository"; import { ApplicationIconService } from "../plugins/application-search-plugin/application-icon-service"; -import { generateWindowsAppIcons } from "../plugins/application-search-plugin/application-icon-helpers"; +import { generateWindowsAppIcons } from "../plugins/application-search-plugin/windows-app-icon-generator"; import { generateMacAppIcons } from "../plugins/application-search-plugin/mac-os-app-icon-generator"; import { UeliCommandSearchPlugin } from "../plugins/ueli-command-search-plugin/ueli-command-search-plugin"; import { ShortcutsSearchPlugin } from "../plugins/shortcuts-search-plugin/shortcuts-search-plugin"; diff --git a/yarn.lock b/yarn.lock index 0652601e8..4672e949f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -389,6 +389,18 @@ dependencies: decimal.js "^10.0.0" +"@types/node-powershell@^3.1.0": + version "3.1.0" + resolved "https://registry.yarnpkg.com/@types/node-powershell/-/node-powershell-3.1.0.tgz#09a8d69b8238154eefec220c9318b3e199fa6d58" + integrity sha1-CajWm4I4FU7v7CIMkxiz4Zn6bVg= + dependencies: + "@types/node" "*" + +"@types/node@*": + version "12.6.9" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.6.9.tgz#ffeee23afdc19ab16e979338e7b536fdebbbaeaf" + integrity sha512-+YB9FtyxXGyD54p8rXwWaN1EWEyar5L58GlGWgtH2I9rGmLGBQcw63+0jw+ujqVavNuO47S1ByAjm9zdHMnskw== + "@types/node@^10.12.18": version "10.14.10" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.14.10.tgz#e491484c6060af8d461e12ec81c0da8a3282b8de" @@ -935,7 +947,7 @@ bluebird-lst@^1.0.7, bluebird-lst@^1.0.9: dependencies: bluebird "^3.5.5" -bluebird@^3.5.0, bluebird@^3.5.1, bluebird@^3.5.5: +bluebird@^3.5.0, bluebird@^3.5.5: version "3.5.5" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f" integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w== @@ -1268,7 +1280,7 @@ caseless@~0.12.0: resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw= -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.1.0, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.3.0, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -4196,6 +4208,11 @@ nan@^2.12.1: resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c" integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg== +nanoid@^2.0.0: + version "2.0.3" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.0.3.tgz#dde999e173bc9d7bd2ee2746b89909ade98e075e" + integrity sha512-NbaoqdhIYmY6FXDRB4eYtDVC9Z9eCbn8TyaiC16LNKtpPv/aqa0tOPD8y6gNE4yUNnaZ7LLhYtXOev/6+cBtfw== + nanomatch@^1.2.9: version "1.2.13" resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119" @@ -4287,13 +4304,13 @@ node-notifier@^5.2.1: shellwords "^0.1.1" which "^1.3.0" -node-powershell@^3.3.1: - version "3.3.1" - resolved "https://registry.yarnpkg.com/node-powershell/-/node-powershell-3.3.1.tgz#bbf76b29f091ed83eae16ad9e7a180a13f36d113" - integrity sha1-u/drKfCR7YPq4WrZ56GAoT820RM= +node-powershell@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/node-powershell/-/node-powershell-4.0.0.tgz#f3a0b1ec4f5619b501b66005f8a663c8373e8da8" + integrity sha512-WCZMLgwkjW9G/DZsZwyCEAXhMMzShLRUlnYS+EETRqRLSdUMbuO4xiQxIOeAutwQgvj75NvC58CorHFlx0olIA== dependencies: - bluebird "^3.5.1" - chalk "^2.1.0" + chalk "^2.4.1" + shortid "^2.2.14" node-pre-gyp@^0.12.0: version "0.12.0" @@ -5388,6 +5405,13 @@ shellwords@^0.1.1: resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== +shortid@^2.2.14: + version "2.2.14" + resolved "https://registry.yarnpkg.com/shortid/-/shortid-2.2.14.tgz#80db6aafcbc3e3a46850b3c88d39e051b84c8d18" + integrity sha512-4UnZgr9gDdA1kaKj/38IiudfC3KHKhDc1zi/HSxd9FQDR0VLwH3/y79tZJLsVYPsJgIjeHjqIWaWVRJUj9qZOQ== + dependencies: + nanoid "^2.0.0" + signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" @@ -6402,13 +6426,6 @@ widest-line@^2.0.0: dependencies: string-width "^2.1.1" -windows-system-icon@0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/windows-system-icon/-/windows-system-icon-0.0.5.tgz#a1d5a7ca728d9934c48d8ae1006d0b2786737775" - integrity sha512-fHYpfMc/xnPj3WftYPB1eRtUUdG2EqfavM46mun/Wl/28m/NqCozZ7GL/jU/7lOlFfcnM5vKFYYb+YqtmW+Cbg== - dependencies: - node-powershell "^3.3.1" - winston-transport@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/winston-transport/-/winston-transport-4.3.0.tgz#df68c0c202482c448d9b47313c07304c2d7c2c66"