mirror of
https://github.com/fofolee/uTools-ProcessKiller.git
synced 2025-06-08 05:57:49 +08:00
增加读取 MacOS 图标的模块
This commit is contained in:
parent
a0078108c8
commit
ffd41b882e
BIN
node_modules/file-icon/file-icon
generated
vendored
Normal file
BIN
node_modules/file-icon/file-icon
generated
vendored
Normal file
Binary file not shown.
63
node_modules/file-icon/index.js
generated
vendored
Normal file
63
node_modules/file-icon/index.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
'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);
|
||||
};
|
9
node_modules/file-icon/license
generated
vendored
Normal file
9
node_modules/file-icon/license
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.
|
83
node_modules/file-icon/package.json
generated
vendored
Normal file
83
node_modules/file-icon/package.json
generated
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
{
|
||||
"_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"
|
||||
}
|
98
node_modules/file-icon/readme.md
generated
vendored
Normal file
98
node_modules/file-icon/readme.md
generated
vendored
Normal file
@ -0,0 +1,98 @@
|
||||
# file-icon [](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<Buffer>` 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`<br>
|
||||
Default: `1024`<br>
|
||||
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`<br>
|
||||
Default: `1024`<br>
|
||||
Maximum: `1024`
|
||||
|
||||
Size of the returned icon.
|
||||
|
||||
#### destination
|
||||
|
||||
*Required*<br>
|
||||
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)
|
5
package-lock.json
generated
5
package-lock.json
generated
@ -2,6 +2,11 @@
|
||||
"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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user