dsh-folia 2.5.0 → 2.5.1

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.
Files changed (2) hide show
  1. package/lib/client.js +43 -29
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -16231,30 +16231,38 @@ window.__ModuleLoader__.load({
16231
16231
  }
16232
16232
 
16233
16233
  /**
16234
- * 把一套皮肤的样式**当场**挂进文档:`<link id="folia-skin-hot">` 追加到 `<head>` 末尾。
16234
+ * 把一套皮肤的样式**当场**挂进文档。
16235
16235
  *
16236
- * 为什么不用"刷新页面":皮肤中心只在页面加载时应用皮肤,而桌面壳里 `location.reload()`
16237
- * 常常被吞掉(用户看到的就是"点了没反应")。直接注入 CSS 不依赖它 —— 后加载的规则
16238
- * 覆盖先前的,于是不刷新也能换肤。代价:皮肤自带的 `hooks.mjs`(粒子等动效)不会跑,
16239
- * 那部分仍然只有整页重载/重启才会生效;这一点在下方的提示里如实写明。
16236
+ * 为什么是 `<style>` 而不是 `<link>`:
16237
+ * · `<link rel=stylesheet>` 是**异步**的,加载完成的时机不定,容易输给皮肤中心随后
16238
+ * 重新注入的那份;
16239
+ * · `<style>` 一赋值就参与样式计算,且追加到 `<body>` **末尾** ⇒ 文档顺序最后,
16240
+ * 同等特异性下后写的赢。这是"不刷新换肤"能真正看见的关键。
16241
+ *
16242
+ * 仍然不跑 `hooks.mjs`(粒子等动效),那部分只有整页重载才生效。
16240
16243
  *
16241
16244
  * @param {string} id 皮肤 id
16245
+ * @returns {Promise<{ bytes: number, rules: number }>}
16242
16246
  */
16243
- function applySkinCss(id) {
16244
- try {
16245
- const href = apiUrl("/skins/css?id=" + encodeURIComponent(id) + "&t=" + Date.now());
16246
- let el = document.getElementById("folia-skin-hot");
16247
- if (!el) {
16248
- el = document.createElement("link");
16249
- el.id = "folia-skin-hot";
16250
- el.rel = "stylesheet";
16251
- document.head.appendChild(el);
16252
- }
16253
- el.href = href; // 带时间戳:绕过缓存,换皮肤立刻拿到新样式
16254
- return true;
16255
- } catch {
16256
- return false;
16257
- }
16247
+ async function applySkinCss(id) {
16248
+ const resp = await apiFetch("/skins/css?id=" + encodeURIComponent(id) + "&t=" + Date.now(), {
16249
+ parse: false,
16250
+ cache: "no-store",
16251
+ });
16252
+ if (!resp || !resp.ok || !resp.response) throw new Error("css-http-" + ((resp && resp.status) || 0));
16253
+ const css = await resp.response.text();
16254
+ if (!css || !css.trim()) throw new Error("css-empty");
16255
+ let el = document.getElementById("folia-skin-hot");
16256
+ if (!el) {
16257
+ el = document.createElement("style");
16258
+ el.id = "folia-skin-hot";
16259
+ // 挂 body 末尾(不是 head):文档顺序最后 ⇒ 同等特异性下覆盖先前的规则。
16260
+ (document.body || document.head).appendChild(el);
16261
+ }
16262
+ el.textContent = css;
16263
+ let rules = 0;
16264
+ try { rules = (el.sheet && el.sheet.cssRules && el.sheet.cssRules.length) || 0; } catch { /* 读不到就报 0 */ }
16265
+ return { bytes: css.length, rules };
16258
16266
  }
16259
16267
 
16260
16268
  function SkinsTabPanel() {
@@ -16319,14 +16327,22 @@ window.__ModuleLoader__.load({
16319
16327
  setNote({ kind: "ok", text: weT("已安装:") + label });
16320
16328
  await load(true);
16321
16329
  } else if (kind === "activate") {
16322
- // **当场换肤**:把皮肤样式直接注入文档,不刷新、不重启。
16323
- // (背景:皮肤中心只在页面加载时应用皮肤,而桌面壳会吞掉 location.reload。)
16324
- const applied = applySkinCss(id);
16330
+ // **当场换肤**:把皮肤样式同步注入文档,不刷新、不重启。
16331
+ // 注入结果直接写进提示里(字节数 / 规则条数):万一样式还是没盖住皮肤中心,
16332
+ // 这一行就是判断"是没注入"还是"注入了但被压住"的依据,不用再猜。
16333
+ let info = null;
16334
+ let applyErr = "";
16335
+ try {
16336
+ info = await applySkinCss(id);
16337
+ } catch (e) {
16338
+ applyErr = String((e && e.message) || e);
16339
+ }
16325
16340
  setNote({
16326
- kind: "ok",
16327
- text: applied
16328
- ? weT("已切换到「") + label + weT("」—— 样式已即时应用")
16329
- : weT("已切换为「") + label + weT("」,但样式注入失败,请重启 DSH"),
16341
+ kind: applyErr ? "err" : "ok",
16342
+ text: applyErr
16343
+ ? weT("已切换为「") + label + weT("」,但样式注入失败:") + applyErr
16344
+ : weT("已切换到「") + label + weT("」—— 已注入 ")
16345
+ + Math.round(info.bytes / 1024) + " KB / " + info.rules + weT(" 条样式规则"),
16330
16346
  // hooks(粒子等动效)只有整页重载才会跑:给一个可选入口,不强制。
16331
16347
  reload: true,
16332
16348
  });
@@ -16528,8 +16544,6 @@ window.__ModuleLoader__.load({
16528
16544
  : React.createElement("div", { style: SKINS_STYLE.thumb }),
16529
16545
  React.createElement("div", { style: SKINS_STYLE.body },
16530
16546
  React.createElement("div", { style: SKINS_STYLE.title }, s.name || s.id),
16531
- React.createElement("div", { style: SKINS_STYLE.meta },
16532
- (s.author ? s.author : weT("未知作者")) + " · " + skinsFmtBytes(s.zipBytes)),
16533
16547
  s.tagline ? React.createElement("div", { style: SKINS_STYLE.meta }, s.tagline) : null,
16534
16548
  (s.tags || []).length
16535
16549
  ? React.createElement("div", { style: SKINS_STYLE.tags },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
- "version": "2.5.0",
3
+ "version": "2.5.1",
4
4
  "description": "Folia 壁纸引擎:把本机 Wallpaper Engine 壁纸搬进 DSH 界面(场景实时渲染 / 视频 / 网页),内置液态玻璃与 Folia 吉祥物,并可从自建站点拉取壁纸。单包形态(组件已合并)。",
5
5
  "type": "module",
6
6
  "engines": {