dsh-pighub 0.9.68 → 0.9.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/client.js +16 -16
- package/lib/index.js +1 -1
- package/lib/themes.js +24 -0
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -628,6 +628,19 @@ window.__ModuleLoader__.load({
|
|
|
628
628
|
catch (error) { set({ error: String((error && error.message) || error) }); }
|
|
629
629
|
}
|
|
630
630
|
|
|
631
|
+
/* 主题切换/删除(用户口径 2026-11-14)。
|
|
632
|
+
* 必须定义在这里:设置浮层的 JSX 里直接调 request 会 ReferenceError
|
|
633
|
+
* (「点不动」的根因就是这个——探针实测 onClick 抛错 request is not defined)。 */
|
|
634
|
+
async function setTheme(name) {
|
|
635
|
+
try { apply(await request({ action: 'theme', name })); }
|
|
636
|
+
catch (error) { set({ error: String((error && error.message) || error) }); }
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
async function removeTheme(name) {
|
|
640
|
+
try { apply(await request({ action: 'theme-delete', name })); }
|
|
641
|
+
catch (error) { set({ error: String((error && error.message) || error) }); }
|
|
642
|
+
}
|
|
643
|
+
|
|
631
644
|
async function refreshCatalog() {
|
|
632
645
|
try {
|
|
633
646
|
set({ phase: state.data ? state.phase : 'loading' });
|
|
@@ -641,6 +654,7 @@ window.__ModuleLoader__.load({
|
|
|
641
654
|
|
|
642
655
|
return {
|
|
643
656
|
get, set, subscribe, toast, load, syncRev, draw, sort, setPet, place, setMotion, savePosition, updatePrefs, refreshCatalog,
|
|
657
|
+
setTheme, removeTheme,
|
|
644
658
|
// 拖动期间给 body 挂全局禁选:拖到面板外面时,选区不会落到下面的聊天区。
|
|
645
659
|
beginDrag: (drag) => { setBodyDragging(true); set({ drag }); },
|
|
646
660
|
moveDrag: (x, y, drag) => set({ drag: Object.assign({}, drag, { x, y }) }),
|
|
@@ -1735,14 +1749,7 @@ window.__ModuleLoader__.load({
|
|
|
1735
1749
|
type: 'button',
|
|
1736
1750
|
className: 'pighub-ghostbtn',
|
|
1737
1751
|
'aria-pressed': activeTheme.name === item.name ? 'true' : 'false',
|
|
1738
|
-
onClick: () =>
|
|
1739
|
-
request({ action: 'theme', name: item.name })
|
|
1740
|
-
.then((payload) => {
|
|
1741
|
-
if (payload && payload.ok === false) { set({ phase: 'error', error: String(payload.error || 'theme_failed') }); return; }
|
|
1742
|
-
return load();
|
|
1743
|
-
})
|
|
1744
|
-
.catch((error) => set({ phase: 'error', error: String((error && error.message) || error) }));
|
|
1745
|
-
},
|
|
1752
|
+
onClick: () => STORE.setTheme(item.name),
|
|
1746
1753
|
}, (activeTheme.name === item.name ? '✓ ' : '') + (item.title || item.name)),
|
|
1747
1754
|
item.name === 'classic'
|
|
1748
1755
|
? h('span', { className: 'pighub-themedel is-disabled' }, '内置')
|
|
@@ -1750,14 +1757,7 @@ window.__ModuleLoader__.load({
|
|
|
1750
1757
|
type: 'button',
|
|
1751
1758
|
className: 'pighub-themedel',
|
|
1752
1759
|
title: '删除这个主题(当前主题会回落 classic)',
|
|
1753
|
-
onClick: () =>
|
|
1754
|
-
request({ action: 'theme-delete', name: item.name })
|
|
1755
|
-
.then((payload) => {
|
|
1756
|
-
if (payload && payload.ok === false) { set({ phase: 'error', error: String(payload.error || 'theme_delete_failed') }); return; }
|
|
1757
|
-
return load();
|
|
1758
|
-
})
|
|
1759
|
-
.catch((error) => set({ phase: 'error', error: String((error && error.message) || error) }));
|
|
1760
|
-
},
|
|
1760
|
+
onClick: () => STORE.removeTheme(item.name),
|
|
1761
1761
|
}, '删除'),
|
|
1762
1762
|
),
|
|
1763
1763
|
),
|
package/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ export const inject = ['tools'];
|
|
|
44
44
|
import { startDesktopPet, stopDesktopPet, syncDesktopPet, desktopPetState, sayOnDesktop, reclaimStaleSessions } from './desktop-pet.js';
|
|
45
45
|
|
|
46
46
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
47
|
-
const VERSION = '0.9.
|
|
47
|
+
const VERSION = '0.9.69';
|
|
48
48
|
/** 桌面桌宠的精灵边长(CSS px 基准,= manifest 里 sizeRatio 的中位数)。 */
|
|
49
49
|
const DESKTOP_PET_SIZE = 96;
|
|
50
50
|
/** 全局尺寸系数(用户口径 2026-11-13:「整体猪猪缩小到 75% 大小」)。三层一起乘。 */
|
package/lib/themes.js
CHANGED
|
@@ -98,6 +98,11 @@ export function listThemes(builtinDir, userThemesDir) {
|
|
|
98
98
|
try { isDir = statSync(dir).isDirectory(); } catch { isDir = false; }
|
|
99
99
|
if (!isDir) continue;
|
|
100
100
|
seen.add(entry);
|
|
101
|
+
/* 用户口径 2026-11-14:「被拒绝的非法场景应该直接不出现在列表」。
|
|
102
|
+
* 所以这里对目录也走一遍准入校验:不合规的主题**根本不列出来**,
|
|
103
|
+
* 而不是列出来、点了一下什么都不发生。 */
|
|
104
|
+
const check = validateThemeDir(dir, entry);
|
|
105
|
+
if (!check.ok) continue;
|
|
101
106
|
const theme = readThemeDir(dir, entry);
|
|
102
107
|
items.push({ name: entry, title: theme.title || entry, builtin: false });
|
|
103
108
|
}
|
|
@@ -157,3 +162,22 @@ export function validateThemePack(meta, files, prefix) {
|
|
|
157
162
|
}
|
|
158
163
|
return { ok: true, reason: '', name };
|
|
159
164
|
}
|
|
165
|
+
|
|
166
|
+
/** 目录版准入校验:读目录里的文件清单 → 复用 validateThemePack。不合规的主题不进列表。 */
|
|
167
|
+
export function validateThemeDir(dir, name) {
|
|
168
|
+
try {
|
|
169
|
+
if (!dir || !existsSync(dir)) return { ok: false, reason: 'dir_missing' };
|
|
170
|
+
const jsonPath = join(dir, 'theme.json');
|
|
171
|
+
if (!existsSync(jsonPath)) return { ok: false, reason: 'theme_json_missing' };
|
|
172
|
+
let meta;
|
|
173
|
+
try { meta = JSON.parse(readFileSync(jsonPath, 'utf8')); } catch { return { ok: false, reason: 'theme_json_invalid' }; }
|
|
174
|
+
const files = [];
|
|
175
|
+
for (const entry of readdirSync(dir)) {
|
|
176
|
+
try { if (!statSync(join(dir, entry)).isFile()) continue; } catch { continue; }
|
|
177
|
+
files.push({ name: entry, data: null });
|
|
178
|
+
}
|
|
179
|
+
return validateThemePack(meta, files, '');
|
|
180
|
+
} catch (error) {
|
|
181
|
+
return { ok: false, reason: 'dir_read_error:' + String((error && error.message) || error).slice(0, 80) };
|
|
182
|
+
}
|
|
183
|
+
}
|