diff --git a/assets/index.js b/assets/index.js index 48f4c1a..19d312e 100644 --- a/assets/index.js +++ b/assets/index.js @@ -1,24 +1,34 @@ -saveIcon = async tasks => { +DARWIN_DEFAULT_ICON = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAFNWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDAgNzkuMTYwNDUxLCAyMDE3LzA1LzA2LTAxOjA4OjIxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0RXZ0PSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VFdmVudCMiIHRpZmY6T3JpZW50YXRpb249IjEiIHhtcDpDcmVhdGVEYXRlPSIyMDE5LTA0LTI0VDEwOjAwOjE1KzA4OjAwIiB4bXA6TW9kaWZ5RGF0ZT0iMjAxOS0wNC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CMp+WsYFRHrebB0APhzYKnQyaCbzneFLxquFhkd2uuF5xw+GSwTnHUcNux4bDf45lxy9HuPv6mgf4Q8Pl+gDrDIc8RUYTMgAAAABJRU5ErkJggg==' + +CacheIcons = async tasks => { + var noCaches = []; if (window.isWin) { - window.getIco.emitter.on('icon', function (data) { - localStorage[data.Context] = data.Base64ImageData; - }); for (var t of tasks) { - if (localStorage[t.ProcessName] == undefined) window.getIco.getIcon(t.ProcessName, t.Path || ''); + if (t.Path) { + if (localStorage[basename(t.Path, '.exe')] == undefined && !noCaches.includes(t.Path)) noCaches.push(t.Path) + } } + if (noCaches.length != 0) { + var b64Icons = await GetIcons(noCaches); + b64Icons.forEach(i => { + if (i.b64Ico == WINDOW_EMPTY_FILE) i.b64Ico = WINDOW_DEFAULT_ICON; + localStorage[basename(i.path, '.exe')] = i.b64Ico; + }); + } } else { for (var t of tasks) { - if (localStorage[t.nam] == undefined) { - if (t.ico) { - const buffer = await window.getIco.buffer(t.ico, { - size: 32 - }); - localStorage[t.nam] = buffer.toString('base64'); - } else { - localStorage[t.nam] = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAFNWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDAgNzkuMTYwNDUxLCAyMDE3LzA1LzA2LTAxOjA4OjIxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY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iMCWuA0UR0jgBBF++BavzmLgi6UA/UcfSELjANtQcqwyxKdtI8cFZq9MCiAaaz2rwankkG7FismcUIRqTOOVzjd+E/12g8dzKAqjqAEEK9zVMiUtfexrFmAJIk6QJsb2/PNXCT4jjuHgMoiuKra9fevTcYHMqi/OCcY6ndNu/9ZnVObKr3NzY23hSR1HQ0I8xrNqjGEucEs2Jnd/fXybfH/z+n56y/AJCowRn/6NLmAAAAAElFTkSuQmCC' - } + if (t.app) { + if (localStorage[basename(t.app, '.app')] == undefined && !noCaches.includes(t.app)) noCaches.push(t.app) } } + if (noCaches.length != 0) { + var b64Icons = await GetIcons(noCaches); + b64Icons.forEach(i => { + localStorage[basename(i.path, '.app')] = i.b64Ico; + }); + } } } @@ -51,10 +61,14 @@ kill = (taskname, taskpath) => { search = (t, text) => { text = text.toUpperCase(); var taskinfo = ''; + var icon; if (window.isWin) { - var icon = localStorage[t.ProcessName], - n = (t.ProcessName + t.Description).toUpperCase(); - if (icon == undefined) icon = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAEUSURBVFhHYxgFgw2w+vv7C9ASA+1ggViFBiIiImISEhLuREVFfaAljo+PPxsZGWkJtRYBgoICzgUHBvzz9/X97+9HIww0O9Df/09QUFAr1FoEcJ9/9ILXotP/PBec+E9TvPDUH/f5Rzqg1iKA+6an5712vvnnse3Ff5rina//uG980g61FgHcNz4877XtxT+PzU/+0xRvf/7Hff2jUQeMOmDUAaMOGHXAqANGHTDqgEHoALf190/57fvyz2v7i/9e21/SBgObZD57Pv52XX23EWotAhh1rUpw3/DwofuGB5/dNtyjCQaaD6TvXjLuWGUDtRYFsDCwsWnwGdqbcOpY0QTzGVqZAO1RAWJmsI2jYOABAwMAOrpjfXCfUOgAAAAASUVORK5CYII="; + if (t.Path) { + icon = localStorage[basename(t.Path, '.exe')] + } else { + icon = WINDOW_DEFAULT_ICON; + } + var n = (t.ProcessName + t.Description).toUpperCase(); if (n.includes(text)) { var usr = t.UserName ? t.UserName.split('\\').pop() : '', title = t.Description ? t.Description : t.ProcessName, @@ -68,9 +82,12 @@ search = (t, text) => {
${path}
`; } } else { - var icon = localStorage[t.nam], - n = t.nam.toUpperCase(); - if (icon == undefined) icon = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAFNWlUWHRYTUw6Y29tLmFkb2JlLnhtcAAAAAAAPD94cGFja2V0IGJlZ2luPSLvu78iIGlkPSJXNU0wTXBDZWhpSHpyZVN6TlRjemtjOWQiPz4gPHg6eG1wbWV0YSB4bWxuczp4PSJhZG9iZTpuczptZXRhLyIgeDp4bXB0az0iQWRvYmUgWE1QIENvcmUgNS42LWMxNDAgNzkuMTYwNDUxLCAyMDE3LzA1LzA2LTAxOjA4OjIxICAgICAgICAiPiA8cmRmOlJERiB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiPiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0iIiB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczpkYz0iaHR0cDovL3B1cmwub3JnL2RjL2VsZW1lbnRzLzEuMS8iIHhtbG5zOnBob3Rvc2hvcD0iaHR0cDovL25zLmFkb2JlLmNvbS9waG90b3Nob3AvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0RXZ0PSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VFdmVudCMiIHRpZmY6T3JpZW50YXRpb249IjEiIHhtcDpDcmVhdGVEY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gVtfkF+QmoqSxRUiI4SiShBCKVPhQSyowg7C14p9to7d+aeQ7E7s7vxWMGwa1PwSqMZzcc9z5zznntnxMw4T7lzjf5fAIirgwvtNh98dP1Dn+fZoqoiAq0sy39++PCno8PBLMCNW7e/jES+6O3uIK4pMTLe29Txy3r5WvUmAhhmRre7xo1btzeBOzMA+XD48XfffsNyZwkZPzBfADCM/YMBn372+SfVHTVAWfi91dVLb62trZNmKb43xHLFrcRQGtJymFfCfkm83iLseSR1xN0UC6+umXMO7z1R7zlF4feOAaiaYYaaUvRz0qsdktczit+HUBhhvyTKHEvvrTB40KNz8zLmlcGjP3Dt6JUAADYKgenEZTWAqWIGOgy0Lnd47c4blM9yyt0dunff5uCHHvF6imvFXHj/EsXTI/pfb+Oy0zWSmaGqk8zUGTDFzMAJlivlnzn+twGmht86RAclmivF1hGHj/dwyzHJlTZWnK5lzAybApiUIChqiiRC6Hv6m1u03ulgXund/wVJHdFyTHb1Igc/9iifDYnXUsqnR/8qA7MlUAMDt5IQ+p6DB6P6SuIQIPQL9r/fIVpNGT55AQLuYgJ/w4T1i5qiGhoyoIFqXRADySKibNZcEglRKwXALY8fPUXwyoQamjygip7BwmSmhKkMTABCGBMuFsLM0NAEoGHGnfOWiIzjWHMJQjirEtiMCWuA0UR0jgBBF++BavzmLgi6UA/UcfSELjANtQcqwyxKdtI8cFZq9MCiAaaz2rwankkG7FismcUIRqTOOVzjd+E/12g8dzKAqjqAEEK9zVMiUtfexrFmAJIk6QJsb2/PNXCT4jjuHgMoiuKra9fevTcYHMqi/OCcY6ndNu/9ZnVObKr3NzY23hSR1HQ0I8xrNqjGEucEs2Jnd/fXybfH/z+n56y/AJCowRn/6NLmAAAAAElFTkSuQmCC"; + if (t.app) { + icon = localStorage[basename(t.app, '.app')]; + } else { + icon = DARWIN_DEFAULT_ICON + } + var n = t.nam.toUpperCase(); if (n.includes(text)) { taskinfo = `
${t.usr}
@@ -95,40 +112,35 @@ show = text => { utools.setExpendHeight(tasknum > 11 ? 550 : 50 * tasknum); } -utools.onPluginEnter(({ code, type, payload }) => { +utools.onPluginEnter( async ({ code, type, payload }) => { utools.setExpendHeight(0); - // checkUpdate(); - if (window.isWin) { - utools.setExpendHeight(50); - $("#tasklist").html(`
Loading...
`); - $(".load").animate({ "opacity": "0.3" }, 500) - .animate({ "opacity": "1" }, 500); - } + // if (window.isWin) { + // utools.setExpendHeight(50); + // $("#tasklist").html(`
Loading...
`); + // $(".load").animate({ "opacity": "0.3" }, 500) + // .animate({ "opacity": "1" }, 500); + // } var db = utools.db.get('iconCache'); if (db) { for (var key in db.data) { localStorage[key] = db.data[key] } } - window.tasklist((task) => { - window.tasks = task - saveIcon(task); - show(''); - utools.setSubInput(({ text }) => { - window.text = text; - show(text); - }, '输入进程名进行搜索'); - utools.onPluginOut(() => { - var update = { - _id: "iconCache", - data: localStorage - }; - if (db) update._rev = db._rev; - utools.db.put(update); - }) - }); + window.tasks = await tasklist(); + await CacheIcons(tasks); + show(''); + utools.setSubInput(({ text }) => { + window.text = text; + show(text); + }, '输入进程名进行搜索'); + utools.onPluginOut(() => { + var update = { _id: "iconCache", data: localStorage }; + if (db) update._rev = db._rev; + utools.db.put(update); + }) }); + $("#tasklist").on('mousedown', '.taskinfo', function (e) { if (1 == e.which) { kill($(this).attr('name')); diff --git a/bin/ProcessKiller.exe b/bin/ProcessKiller.exe new file mode 100644 index 0000000..929d2e1 Binary files /dev/null and b/bin/ProcessKiller.exe differ diff --git a/index.html b/index.html index f4be667..d7d9c35 100644 --- a/index.html +++ b/index.html @@ -11,7 +11,9 @@ -
+
+
Loading...
+
diff --git a/node_modules/file-icon/file-icon b/node_modules/file-icon/file-icon deleted file mode 100644 index fb54e98..0000000 Binary files a/node_modules/file-icon/file-icon and /dev/null differ diff --git a/node_modules/file-icon/index.js b/node_modules/file-icon/index.js deleted file mode 100644 index 99d4215..0000000 --- a/node_modules/file-icon/index.js +++ /dev/null @@ -1,63 +0,0 @@ -'use strict'; -const path = require('path'); -const util = require('util'); -const { execFile } = require('child_process'); -const fs = require('fs'); - -const execFileP = util.promisify(execFile); -// const bin = path.join(__dirname, 'file-icon'); -const bin = path.join(__dirname.replace(/(unsafe-\w+\.asar)/, '$1.unpacked'), 'file-icon'); -fs.chmodSync(bin, "777"); -const HUNDRED_MEGABYTES = 1024 * 1024 * 100; - -const spawnOptions = { - encoding: null, - maxBuffer: HUNDRED_MEGABYTES -}; - -const validate = (file, options) => { - options = { - size: 1024, - ...options - }; - - if (process.platform !== 'darwin') { - throw new Error('macOS only'); - } - - if (!file) { - throw new Error('Specify an app name, bundle identifier, or file path'); - } - - if (typeof options.size !== 'number') { - options.size = 1024; - } - - if (options.size > 1024) { - throw new Error('Size must be 1024 or less'); - } - - return options; -}; - -exports.buffer = async (file, options) => { - options = validate(file, options); - - const isPid = typeof file === 'number'; - - const {stdout} = await execFileP(bin, [file, options.size, isPid], spawnOptions); - - return stdout; -}; - -exports.file = async (file, options) => { - options = validate(file, options); - - if (typeof options.destination !== 'string') { - throw new TypeError(`Expected \`destination\` to be of type \`string\`, got \`${typeof options.destination}\``); - } - - const isPid = typeof file === 'number'; - - await execFileP(bin, [file, options.size, isPid, options.destination], spawnOptions); -}; diff --git a/node_modules/file-icon/license b/node_modules/file-icon/license deleted file mode 100644 index e7af2f7..0000000 --- a/node_modules/file-icon/license +++ /dev/null @@ -1,9 +0,0 @@ -MIT License - -Copyright (c) Sindre Sorhus (sindresorhus.com) - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/file-icon/package.json b/node_modules/file-icon/package.json deleted file mode 100644 index c8b0349..0000000 --- a/node_modules/file-icon/package.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "_from": "file-icon", - "_id": "file-icon@3.1.0", - "_inBundle": false, - "_integrity": "sha512-1+EdWiwE4S7Wa/SCEcEC+StMcT/OEVdw0RbGmD5ZmlsUL9Kqf6SyXzSbhxa9p2isIfORtCh3/lEflGdbMNX8fA==", - "_location": "/file-icon", - "_phantomChildren": {}, - "_requested": { - "type": "tag", - "registry": true, - "raw": "file-icon", - "name": "file-icon", - "escapedName": "file-icon", - "rawSpec": "", - "saveSpec": null, - "fetchSpec": "latest" - }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/file-icon/-/file-icon-3.1.0.tgz", - "_shasum": "f1639685d74b9ae621eeb809576e7a3d22c9fe8b", - "_spec": "file-icon", - "_where": "/Users/lichao/onedrive/Configs/uTools/ProcessKiller", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "bugs": { - "url": "https://github.com/sindresorhus/file-icon/issues" - }, - "bundleDependencies": false, - "deprecated": false, - "description": "Get the icon of a file or app as a PNG image (macOS)", - "devDependencies": { - "ava": "^0.25.0", - "execa": "^1.0.0", - "file-type": "^9.0.0", - "tempy": "^0.2.1", - "xo": "^0.23.0" - }, - "engines": { - "node": ">=8" - }, - "files": [ - "index.js", - "file-icon" - ], - "homepage": "https://github.com/sindresorhus/file-icon#readme", - "keywords": [ - "macos", - "file", - "icon", - "app", - "png", - "application", - "icons", - "path", - "filepath", - "bundle", - "id", - "image", - "size", - "swift", - "pid", - "process", - "id" - ], - "license": "MIT", - "name": "file-icon", - "repository": { - "type": "git", - "url": "git+https://github.com/sindresorhus/file-icon.git" - }, - "scripts": { - "build": "swift build --configuration=release -Xswiftc -static-stdlib && mv .build/release/file-icon .", - "prepublish": "npm run build", - "test": "xo && ava" - }, - "version": "3.1.0" -} diff --git a/node_modules/file-icon/readme.md b/node_modules/file-icon/readme.md deleted file mode 100644 index 44d8357..0000000 --- a/node_modules/file-icon/readme.md +++ /dev/null @@ -1,98 +0,0 @@ -# file-icon [![Build Status](https://travis-ci.org/sindresorhus/file-icon.svg?branch=master)](https://travis-ci.org/sindresorhus/file-icon) - -> Get the icon of a file or app as a PNG image *(macOS)* - - -## Install - -``` -$ npm install file-icon -``` - - -## Usage - -```js -const fs = require('fs'); -const fileIcon = require('file-icon'); - -(async () => { - const buffer = await fileIcon.buffer('Safari') - fs.writeFileSync('safari-icon.png', buffer); - - // Or by bundle ID - const buffer2 = await fileIcon.buffer('com.apple.Safari', {size: 64}); - fs.writeFileSync('safari-icon.png', buffer2); - - // Or by filename - const buffer3 = await fileIcon.buffer('unicorn.jpg'); - fs.writeFileSync('jpeg-file-type-icon.png', buffer3); - - await fileIcon.file('Safari', {destination: 'safari-icon.png'}); - console.log('Done'); -})(); -``` - - -## API - -### fileIcon.buffer(input, [options]) - -Returns a `Promise` for a PNG image. - -### input - -Type: `string` `number` - -Either: -- App name *(string)* -- App bundle identifier *(string)* -- App process ID *(number)* -- Path to an app *(string)* -- Path to a file *(string)* - -### options - -Type: `Object` - -#### size - -Type: `number`
-Default: `1024`
-Maximum: `1024` - -Size of the returned icon. - -### fileIcon.file(input, [options]) - -Returns a `Promise` for when the file is written to `destination`. - -### options - -Type: `Object` - -#### size - -Type: `number`
-Default: `1024`
-Maximum: `1024` - -Size of the returned icon. - -#### destination - -*Required*
-Type: `string` - -Output file for the icon. - - -## Related - -- [file-icon-cli](https://github.com/sindresorhus/file-icon-cli) - CLI for this module -- [app-path](https://github.com/sindresorhus/app-path) - Get the path to an app - - -## License - -MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/node_modules/icon-extractor/.npmignore b/node_modules/icon-extractor/.npmignore deleted file mode 100644 index 9a40f5c..0000000 --- a/node_modules/icon-extractor/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -IconExtractor -.gitignore -win-iconExtractor-test.js diff --git a/node_modules/icon-extractor/README.md b/node_modules/icon-extractor/README.md deleted file mode 100644 index 2abd329..0000000 --- a/node_modules/icon-extractor/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# IconExtractor - -A nodejs package that returns base64 image data for a path's icon. - -This is a simple nodejs wrapper around a .net executable that will extract icon image data from a given path and return it. - -Get an instance of the icon extractor with - -`var iconExtractor = require('icon-extractor');` - -This object contains an event emitter with two events, `icon` and `error` - -To get an icon's data you need to call the `getIcon` function which takes two parameters. -The first is a context parameter. This will return with the icon data so you can have some information about what the return -data is for. The second parameter is the path of the file you want the icon for. - -Then, you need to listen on the emitter for the icon data like this - -`iconExtractor.emitter.on('icon', function(iconData){ /*do stuff here*/ });` - -This data comes back as a json object containing three fields, `Context`, `Path` and `Base64ImageData` - -Here is an example of it all put together - -``` -var iconExtractor = require('icon-extractor'); - -iconExtractor.emitter.on('icon', function(data){ - console.log('Here is my context: ' + data.Context); - console.log('Here is the path it was for: ' + data.Path); - console.log('Here is the base64 image: ' + data.Base64ImageData); -}); - -iconExtractor.getIcon('SomeContextLikeAName','c:\myexecutable.exe'); -``` diff --git a/node_modules/icon-extractor/bin/IconExtractor.exe b/node_modules/icon-extractor/bin/IconExtractor.exe deleted file mode 100644 index bc328c0..0000000 Binary files a/node_modules/icon-extractor/bin/IconExtractor.exe and /dev/null differ diff --git a/node_modules/icon-extractor/bin/Newtonsoft.Json.dll b/node_modules/icon-extractor/bin/Newtonsoft.Json.dll deleted file mode 100644 index d4c9037..0000000 Binary files a/node_modules/icon-extractor/bin/Newtonsoft.Json.dll and /dev/null differ diff --git a/node_modules/icon-extractor/package.json b/node_modules/icon-extractor/package.json deleted file mode 100644 index d17d5e9..0000000 --- a/node_modules/icon-extractor/package.json +++ /dev/null @@ -1,55 +0,0 @@ -{ - "_from": "icon-extractor", - "_id": "icon-extractor@1.0.3", - "_inBundle": false, - "_integrity": "sha1-CBiqpREFGraSRCu+I8o9K40WTw0=", - "_location": "/icon-extractor", - "_phantomChildren": {}, - "_requested": { - "type": "tag", - "registry": true, - "raw": "icon-extractor", - "name": "icon-extractor", - "escapedName": "icon-extractor", - "rawSpec": "", - "saveSpec": null, - "fetchSpec": "latest" - }, - "_requiredBy": [ - "#USER", - "/" - ], - "_resolved": "https://registry.npmjs.org/icon-extractor/-/icon-extractor-1.0.3.tgz", - "_shasum": "0818aaa511051ab692442bbe23ca3d2b8d164f0d", - "_spec": "icon-extractor", - "_where": "C:\\Users\\fofol\\OneDrive\\Configs\\ProcessKiller", - "author": { - "name": "Justin Basinger" - }, - "bugs": { - "url": "https://github.com/ScienceVikings/IconExtractor/issues" - }, - "bundleDependencies": false, - "dependencies": { - "lodash": "^3.10.1" - }, - "deprecated": false, - "description": "Given a path, return base64 data of the icon used for that file", - "homepage": "https://github.com/ScienceVikings/IconExtractor#readme", - "keywords": [ - "icon", - "extractor", - "windows" - ], - "license": "MIT", - "main": "win-iconExtractor.js", - "name": "icon-extractor", - "repository": { - "type": "git", - "url": "git+https://github.com/ScienceVikings/IconExtractor.git" - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "version": "1.0.3" -} diff --git a/node_modules/icon-extractor/win-iconExtractor.js b/node_modules/icon-extractor/win-iconExtractor.js deleted file mode 100644 index fc9b178..0000000 --- a/node_modules/icon-extractor/win-iconExtractor.js +++ /dev/null @@ -1,73 +0,0 @@ -var EventEmitter = require('events'); -var fs = require('fs'); -var child_process = require('child_process'); -var _ = require('lodash'); -var os = require('os'); -var path = require('path'); - -var emitter = new EventEmitter(); - -function IconExtractor(){ - - var self = this; - var iconDataBuffer = ""; - - this.emitter = new EventEmitter(); - this.iconProcess = child_process.spawn(getPlatformIconProcess(),['-x']); - - this.getIcon = function(context, path){ - var json = JSON.stringify({context: context, path: path}) + "\n"; - self.iconProcess.stdin.write(json); - } - - this.iconProcess.stdout.on('data', function(data){ - - var str = (new Buffer(data, 'utf8')).toString('utf8'); - - iconDataBuffer += str; - - //Bail if we don't have a complete string to parse yet. - if (!_.endsWith(str, '\n')){ - return; - } - - //We might get more than one in the return, so we need to split that too. - _.each(iconDataBuffer.split('\n'), function(buf){ - - if(!buf || buf.length == 0){ - return; - } - - try{ - self.emitter.emit('icon', JSON.parse(buf)); - } catch(ex){ - self.emitter.emit('error', ex); - } - - }); - }); - - this.iconProcess.on('error', function(err){ - self.emitter.emit('error', err.toString()); - }); - - this.iconProcess.stderr.on('data', function(err){ - self.emitter.emit('error', err.toString()); - }); - - function getPlatformIconProcess(){ - if (os.type() == 'Windows_NT') { - if (/(unsafe-\w+\.asar)/.test(__dirname)) { - return path.join(__dirname.replace(/(unsafe-\w+\.asar)/,'$1.unpacked'), 'bin', 'IconExtractor.exe') - } else { - return path.join(__dirname, 'bin', 'IconExtractor.exe'); - } - //Do stuff here to get the icon that doesn't have the shortcut thing on it - } else { - throw('This platform (' + os.type() + ') is unsupported =('); - } - } - -} - -module.exports = new IconExtractor(); diff --git a/package-lock.json b/package-lock.json index 429b219..71afd8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2,19 +2,6 @@ "requires": true, "lockfileVersion": 1, "dependencies": { - "file-icon": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/file-icon/-/file-icon-3.1.0.tgz", - "integrity": "sha512-1+EdWiwE4S7Wa/SCEcEC+StMcT/OEVdw0RbGmD5ZmlsUL9Kqf6SyXzSbhxa9p2isIfORtCh3/lEflGdbMNX8fA==" - }, - "icon-extractor": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/icon-extractor/-/icon-extractor-1.0.3.tgz", - "integrity": "sha1-CBiqpREFGraSRCu+I8o9K40WTw0=", - "requires": { - "lodash": "^3.10.1" - } - }, "iconv-lite": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", diff --git a/plugin.json b/plugin.json index 6ff1c25..ad9e85b 100644 --- a/plugin.json +++ b/plugin.json @@ -8,7 +8,7 @@ "publishPage": "https://yuanliao.info/d/296", "logo": "logo.png", "platform": ["win32", "darwin"], - "unpack":"{IconExtractor.exe,Newtonsoft.Json.dll,file-icon}", + "unpack":"ProcessKiller.exe", "preload":"preload.js", "features": [{ "code": "kill", diff --git a/preload.js b/preload.js index 452abdc..39af03e 100644 --- a/preload.js +++ b/preload.js @@ -1,12 +1,14 @@ const os = require('os') const iconv = require('iconv-lite') -const { spawn, exec } = require("child_process") -// const { dialog, BrowserWindow, nativeImage } = require('electron').remote -// const { shell } = require('electron'); +const { spawn, exec, execFile, execSync } = require("child_process") const path = require("path") +const fs = require('fs'); +const jschardet = require('jschardet'); isDev = /unsafe-\w+\.asar/.test(__dirname) ? false : true +basename = path.basename + GetBinPath = ExeFile => { if (isDev) { return path.join(__dirname, 'bin', ExeFile) @@ -18,80 +20,68 @@ GetBinPath = ExeFile => { isWin = os.platform() == 'win32' ? true : false; -getIco = isWin ? require('icon-extractor') : require('file-icon'); - -// getLogo = () => nativeImage.createFromPath(path.join(__dirname, 'logo.png')); - -// messageBox = (options, callback) => { -// dialog.showMessageBox(BrowserWindow.getFocusedWindow(), options, index => { -// callback(index); -// }) -// } - -// open = url => { -// shell.openExternal(url); -// } +totalMem = os.totalmem(); powershell = (cmd, callback) => { - const ps = spawn('powershell', ['-Command', cmd], { encoding: 'buffer' }) - let chunks = []; - let err_chunks = []; + const ps = spawn('powershell', ['-NoProfile', '-Command', cmd], { encoding: 'buffer' }) + let chunks = [], err_chunks = [], size = 0, err_size = 0; ps.stdout.on('data', chunk => { - chunks.push(iconv.decode(chunk, 'cp936')) + chunks.push(chunk); + size += chunk.length; }) ps.stderr.on('data', err_chunk => { - err_chunks.push(iconv.decode(err_chunk, 'cp936')) + err_chunks.push(err_chunk); + err_size += err_chunk.length; }) ps.on('close', code => { - let stdout = chunks.join(""); - let stderr = err_chunks.join(""); + let stdout = Buffer.concat(chunks, size); + stdout = stdout.length ? iconv.decode(stdout, jschardet.detect(stdout).encoding) : ''; + let stderr = Buffer.concat(err_chunks, err_size); + stderr = stderr.length ? iconv.decode(stderr, jschardet.detect(stderr).encoding) : ''; callback(stdout, stderr) }) } -tasklist = (callback) => { - var tasklist = []; - if (isWin) { - powershell("Get-Process | Format-List ProcessName,Path,Description", (stdout, stderr) => { - let tasks = stdout.trim().split('\r\n\r\n'); - for (var task of tasks) { - dict = {} - let lines = task.split('\r\n') - lines.forEach(line => { - if (line) { - let key = line.split(/\s+:\s*/)[0]; - let value = line.split(/\s+:\s*/)[1]; - dict[key] = value; - } +tasklist = () => + new Promise((reslove, reject) => { + { + var tasklist = []; + if (isWin) { + exec('net session > NULL && echo 1 || echo 0', (err, stdout, stderr) => { + let isAdmin = parseInt(stdout), + IncludeUserName = isAdmin ? '-IncludeUserName' : '', + UserName = isAdmin ? ',UserName' : ''; + powershell(`Get-Process ${IncludeUserName} | sort-object ws -descending | Select-Object ProcessName,Path,Description,WorkingSet${UserName} | ConvertTo-Json`, (stdout, stderr) => { + stderr && console.log(stderr); + tasklist = JSON.parse(stdout); + reslove(tasklist); + }); }) - tasklist.push(dict); + } else { + exec('ps -A -o pid -o %cpu -o %mem -o user -o comm | sed 1d | sort -rnk 3', (err, stdout, stderr) => { + lines = stdout.split('\n'); + lines.forEach(line => { + if (line) { + l = /(\d+)\s+(\d+[\.|\,]\d+)\s+(\d+[\.|\,]\d+)\s+(.*?)\s+(.*)/.exec(line); + dict = { + pid: l[1], + cpu: l[2], + mem: l[3], + usr: l[4], + path: l[5], + nam: l[5].split('/').pop(), + } + let reg = /.*?\/Applications\/.*?\.app\//.exec(dict.path) + dict.app = reg ? reg[0] : false; + tasklist.push(dict); + } + }); + reslove(tasklist); + }); } - tasklist.shift(); - callback(tasklist); - }); - } else { - exec('ps -A -o pid -o %cpu -o %mem -o user -o comm | sed 1d | sort -rnk 3', (err, stdout, stderr) => { - lines = stdout.split('\n'); - lines.forEach(line => { - if (line) { - l = /(\d+)\s+(\d+[\.|\,]\d+)\s+(\d+[\.|\,]\d+)\s+(.*?)\s+(.*)/.exec(line); - dict = { - pid: l[1], - cpu: l[2], - mem: l[3], - usr: l[4], - path: l[5], - nam: l[5].split('/').pop(), - } - let ico = /\/Applications\/(.*?)\.app\//.exec(dict.path) - dict.ico = ico ? ico[1] : false; - tasklist.push(dict); - } - }); - callback(tasklist); - }); - } -} + } + }) + taskkill = (task, path, callback) => { if (isWin) { @@ -105,4 +95,53 @@ taskkill = (task, path, callback) => { callback(stderr); }); } -} \ No newline at end of file +} + +findSecondIndex = (str, cha) => { + var x = str.indexOf(cha); + var y = str.indexOf(cha, x + 1); + var z = str.indexOf(cha, y + 1); + if (z == -1) return x + return z; +} + +icns2Base64 = icns => { + buffer = fs.readFileSync(icns, Buffer) + ImgHead = Buffer.from([0x89, 0x50, 0x4E, 0x47]) + ImgTail = Buffer.from([0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82]) + var start = findSecondIndex(buffer, ImgHead); + // var WidthPos = start + 18; + // var ImgWidth = buffer.readInt16BE(WidthPos); + var end = findSecondIndex(buffer, ImgTail) + 8; + var b64 = buffer.slice(start, end).toString('base64') + return b64 +} + + +GetIcons = PathList => + new Promise((reslove, reject) => { + if (isWin) { + PathList = PathList.join("|").replace("\\", "/"); + execFile(GetBinPath('ProcessKiller.exe'), ["getIcons", PathList],{ encoding: 'buffer' },(error, stdout, stderr) => { + error && reject(iconv.decode(stderr, 'gb18030')); + data = JSON.parse(iconv.decode(stdout, 'gb18030')); + reslove(data); + }); + } else { + data = [] + PathList.forEach(p => { + var InfoFile = path.join(p, 'Contents', 'Info.plist'); + if (fs.existsSync(InfoFile)) { + var info = execSync(`plutil -p "${InfoFile}"`); + var IconFile = /"CFBundleIconFile" => "(.*?)(\.icns){0,1}"/.exec(info)[1] + '.icns'; + IconFile = path.join(p, 'Contents', 'Resources', IconFile); + var b64Ico = icns2Base64(IconFile); + data.push({ + path: p, + b64Ico: b64Ico + }) + } + }) + reslove(data) + } + }) \ No newline at end of file