mirror of
https://github.com/fofolee/uTools-ProcessKiller.git
synced 2025-12-20 18:42:24 +08:00
增加读取 MacOS 图标的模块
This commit is contained in:
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);
|
||||
};
|
||||
Reference in New Issue
Block a user