缩略图自动生成背景服务插件

This commit is contained in:
Yeomai committed 2026-09-20 20:34:17 +08:00
1 parent c28adf9fae
commit 065b6466f1
27 files changed
+81166

No files matched your search

@@ -0,0 +1,41 @@
// 插件设置持久化。默认关闭自动生成——Eagle 审核标准要求「批量或不可逆的变更
// 必须事先明确说明并获得确认」,所以必须由用户主动打开这个开关。
(function () {
'use strict';
const fs = require('fs');
const path = require('path');
const DEFAULTS = { enabled: false };
/** 存放在 Eagle 的 userData 目录,不写进素材库,卸载时可直接删掉。 */
async function resolveFile() {
const userData = await eagle.app.getPath('userData');
return path.join(userData, 'SpineThumbnailGenerateServer', 'settings.json');
}
async function read() {
const file = await resolveFile();
try {
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
return { ...DEFAULTS, ...data };
} catch (error) {
if (error && error.code === 'ENOENT') return { ...DEFAULTS };
throw error;
}
}
async function write(next) {
const file = await resolveFile();
fs.mkdirSync(path.dirname(file), { recursive: true });
const body = JSON.stringify({ ...DEFAULTS, ...next }, null, 2) + '\n';
const temp = file + '.' + process.pid + '.tmp';
fs.writeFileSync(temp, body, 'utf8');
fs.renameSync(temp, file);
}
const api = { read, write, resolveFile, DEFAULTS };
if (typeof window !== 'undefined') window.SpineThumbSettings = api;
else if (typeof module !== 'undefined' && module.exports) module.exports = api;
})();