lingshu-skill 5.30.0 → 5.31.0
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/CHANGELOG.md +79 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +341 -405
- package/assets/panel.html +490 -18
- package/cordis-plugin/lingshu-cron/plugin.js +195 -29
- package/docs//344/275/277/347/224/250/346/214/207/345/215/227.md +229 -0
- package/docs//345/256/241/346/240/270/346/224/271/350/277/233/345/276/205/345/212/236.md +73 -31
- package/docs//345/276/205/345/212/236/346/250/241/346/235/277.md +140 -0
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +20 -17
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +79 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +341 -405
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +490 -18
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +47 -18
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +32 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +7 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +14 -6
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +27 -5
- package/scripts/astrbot_plugin_lingshu/engine/scripts/mem_dialogue.py +15 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +462 -14
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_icon.py +220 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_launcher.py +114 -10
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +165 -41
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_shortcut.py +330 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_splash.py +181 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/persona.py +19 -5
- package/scripts/astrbot_plugin_lingshu/engine/scripts/safety_net.py +29 -3
- package/scripts/cli.py +47 -18
- package/scripts/core.py +32 -0
- package/scripts/dream.py +7 -1
- package/scripts/emotion.py +14 -6
- package/scripts/growth.py +27 -5
- package/scripts/mem_dialogue.py +15 -0
- package/scripts/memory.py +462 -14
- package/scripts/panel_icon.py +220 -0
- package/scripts/panel_launcher.py +114 -10
- package/scripts/panel_server.py +165 -41
- package/scripts/panel_shortcut.py +330 -0
- package/scripts/panel_splash.py +181 -0
- package/scripts/persona.py +19 -5
- package/scripts/safety_net.py +29 -3
|
@@ -785,9 +785,17 @@
|
|
|
785
785
|
<option value="300" selected>300 节点</option>
|
|
786
786
|
<option value="600">600 节点</option>
|
|
787
787
|
</select>
|
|
788
|
+
<select id="graph-color" style="width:104px" title="上色依据:重要度 = 越重要越暖;主题簇 = 同色即同一主题(社区检测)">
|
|
789
|
+
<option value="importance" selected>按重要度</option>
|
|
790
|
+
<option value="community">按主题簇</option>
|
|
791
|
+
</select>
|
|
792
|
+
<select id="graph-layout" style="width:110px" title="空间布局:力导向 = 按关联聚拢;时间轴 = 按写下的时间排开(可回看某一时刻的记忆网)">
|
|
793
|
+
<option value="force" selected>力导向</option>
|
|
794
|
+
<option value="timeline">时间轴</option>
|
|
795
|
+
</select>
|
|
788
796
|
<label class="sub" style="display:flex;align-items:center;gap:5px;cursor:pointer;user-select:none"
|
|
789
|
-
title="
|
|
790
|
-
<input type="checkbox" id="graph-hide-isolated"
|
|
797
|
+
title="默认全部显示:每条记忆都有人格连线,图不会断。取消勾选可只看有真实关联的记忆(更稀疏,适合记忆很多时找结构)">
|
|
798
|
+
<input type="checkbox" id="graph-hide-isolated">只看有联想的
|
|
791
799
|
</label>
|
|
792
800
|
<button class="ghost" id="btn-graph-reset">重置视角</button>
|
|
793
801
|
<button class="ghost" id="btn-graph-refresh">刷新</button>
|
|
@@ -800,6 +808,13 @@
|
|
|
800
808
|
<div id="graph-tip" class="sub" style="position:absolute;left:14px;bottom:12px;pointer-events:none;font-size:11.5px;color:var(--faint)"></div>
|
|
801
809
|
<div id="graph-loadtip" class="sub hidden" style="position:absolute;left:0;right:0;top:46%;text-align:center;pointer-events:none;font-size:13px;color:var(--faint)"></div>
|
|
802
810
|
<div id="graph-detail" class="card hidden" style="position:absolute;right:14px;top:14px;width:280px;max-height:80%;overflow:auto;background:rgba(17,21,26,.94);backdrop-filter:blur(6px)"></div>
|
|
811
|
+
<!-- 时间轴滑杆:只在「时间轴」布局下显示,拖动即回看某一时刻 -->
|
|
812
|
+
<div id="graph-time" class="hidden" style="position:absolute;left:16px;right:16px;bottom:38px;display:flex;gap:10px;align-items:center;
|
|
813
|
+
background:rgba(10,12,15,.82);border:1px solid var(--line);border-radius:10px;padding:8px 12px;backdrop-filter:blur(6px)">
|
|
814
|
+
<span class="sub" style="white-space:nowrap" id="graph-time-label">—</span>
|
|
815
|
+
<input type="range" id="graph-time-range" min="0" max="100" value="100" style="flex:1;accent-color:var(--amber)">
|
|
816
|
+
<span class="sub" style="white-space:nowrap" id="graph-time-count"></span>
|
|
817
|
+
</div>
|
|
803
818
|
</div>
|
|
804
819
|
<div class="card" style="margin-top:14px">
|
|
805
820
|
<div class="row"><h2 style="margin:0">关联明细</h2><span class="sub" id="graph-stat" style="margin-left:auto"></span></div>
|
|
@@ -984,6 +999,48 @@
|
|
|
984
999
|
</div>
|
|
985
1000
|
<div class="sub" id="home-msg" style="margin-top:8px"></div>
|
|
986
1001
|
</div>
|
|
1002
|
+
|
|
1003
|
+
<!-- 启动快捷键(写桌面快捷方式的全局热键) -->
|
|
1004
|
+
<div class="card" style="margin-bottom:14px">
|
|
1005
|
+
<div class="row" style="flex-wrap:wrap">
|
|
1006
|
+
<div>
|
|
1007
|
+
<h2 style="margin-bottom:4px">桌面快捷方式</h2>
|
|
1008
|
+
<div class="sub">换图标 + 设全局热键。写的是 Windows 快捷方式自带字段,不需要额外常驻进程。</div>
|
|
1009
|
+
</div>
|
|
1010
|
+
<button class="ghost" id="btn-hotkey-refresh" style="margin-left:auto">刷新</button>
|
|
1011
|
+
</div>
|
|
1012
|
+
|
|
1013
|
+
<div class="row" style="margin-top:14px;gap:14px;flex-wrap:wrap;align-items:flex-start">
|
|
1014
|
+
<div style="display:flex;flex-direction:column;align-items:center;gap:6px">
|
|
1015
|
+
<img id="icon-preview" alt="图标预览" width="64" height="64"
|
|
1016
|
+
style="width:64px;height:64px;border-radius:12px;border:1px solid var(--line);background:var(--surface2);object-fit:contain">
|
|
1017
|
+
<span class="sub" id="icon-state" style="font-size:11px">—</span>
|
|
1018
|
+
</div>
|
|
1019
|
+
<div style="flex:1;min-width:220px">
|
|
1020
|
+
<div class="sub" style="margin-bottom:8px">自定义图标:选一张图片(建议正方形、≥256×256),会自动生成 16/24/32/48/64/128/256 多尺寸 .ico。也可以直接选现成的 .ico。</div>
|
|
1021
|
+
<div class="row" style="flex-wrap:wrap;gap:8px">
|
|
1022
|
+
<button class="btn" id="btn-icon-pick">选择图片…</button>
|
|
1023
|
+
<button class="ghost" id="btn-icon-reset" style="color:var(--amber)" title="把快捷方式图标还原成灵枢出厂图标(会先让你确认)">↺ 还原默认图标</button>
|
|
1024
|
+
</div>
|
|
1025
|
+
<div class="sub" id="icon-msg" style="margin-top:8px"></div>
|
|
1026
|
+
</div>
|
|
1027
|
+
</div>
|
|
1028
|
+
|
|
1029
|
+
<div class="row" style="margin-top:16px;flex-wrap:wrap">
|
|
1030
|
+
<div>
|
|
1031
|
+
<h2 style="margin-bottom:4px">启动快捷键</h2>
|
|
1032
|
+
<div class="sub">在任何程序里按下都能唤起面板。至少要有 CTRL / ALT / SHIFT / WIN 之一。</div>
|
|
1033
|
+
</div>
|
|
1034
|
+
</div>
|
|
1035
|
+
<div id="hotkey-info" style="margin-top:12px"><div class="empty">读取中…</div></div>
|
|
1036
|
+
<div class="row" style="margin-top:10px;flex-wrap:wrap">
|
|
1037
|
+
<input type="text" id="hotkey-input" placeholder="例如 CTRL+ALT+L(至少一个修饰键)" style="flex:1;min-width:220px">
|
|
1038
|
+
<button class="btn" id="btn-hotkey-save">设为快捷键</button>
|
|
1039
|
+
<button class="ghost" id="btn-hotkey-clear">清除</button>
|
|
1040
|
+
<button class="ghost" id="btn-hotkey-repair" title="如果桌面图标变白、双击没反应(快捷方式被写坏了),点这里按标准值重建">修复快捷方式</button>
|
|
1041
|
+
</div>
|
|
1042
|
+
<div class="sub" id="hotkey-msg" style="margin-top:8px"></div>
|
|
1043
|
+
</div>
|
|
987
1044
|
</section>
|
|
988
1045
|
|
|
989
1046
|
<!-- 运行日志 -->
|
|
@@ -1216,6 +1273,19 @@ const progress = topProgress();
|
|
|
1216
1273
|
</div>
|
|
1217
1274
|
</div>
|
|
1218
1275
|
|
|
1276
|
+
<!-- 通用确认弹窗:破坏性/不可逆操作先问一句,防止点错。
|
|
1277
|
+
Esc = 取消,点遮罩 = 取消,默认焦点在「取消」上(手滑按回车不会执行)。 -->
|
|
1278
|
+
<div class="modal hidden" id="confirm-modal">
|
|
1279
|
+
<div class="box" style="width:min(440px,100%)">
|
|
1280
|
+
<h3 id="confirm-title">确认操作</h3>
|
|
1281
|
+
<div class="sub" id="confirm-text" style="line-height:1.75;white-space:pre-wrap"></div>
|
|
1282
|
+
<div class="row" style="margin-top:20px;justify-content:flex-end">
|
|
1283
|
+
<button class="ghost" id="confirm-cancel">取消</button>
|
|
1284
|
+
<button class="btn" id="confirm-ok">确定</button>
|
|
1285
|
+
</div>
|
|
1286
|
+
</div>
|
|
1287
|
+
</div>
|
|
1288
|
+
|
|
1219
1289
|
<script>
|
|
1220
1290
|
const S = { ov: null, tab: "overview", ws: null, memIndex: {} };
|
|
1221
1291
|
const $ = (id) => document.getElementById(id);
|
|
@@ -1763,12 +1833,19 @@ function renderDailyCards(){
|
|
|
1763
1833
|
const GRAPH = { data: null, pos: [], yaw: 0.6, pitch: -0.35, dist: 360,
|
|
1764
1834
|
focus: {x: 0, y: 0, z: 0}, target: {x: 0, y: 0, z: 0}, targetDist: 360,
|
|
1765
1835
|
selected: null, hover: null, loaded: false, nbrs: null, anim: null,
|
|
1766
|
-
pathEdges: null, hideIsolated:
|
|
1836
|
+
pathEdges: null, hideIsolated: false, stats: null, deg: null,
|
|
1837
|
+
colorBy: "importance", communityHue: null, communities: null,
|
|
1838
|
+
layout: "force", timePct: 100, timeMin: 0, timeMax: 0, hoverEdge: null };
|
|
1767
1839
|
const LAYER_COLOR = { cortex: "#d9a441", hippo: "#5fa8a0", dust: "#5d646e", archive: "#8f92b8" };
|
|
1768
1840
|
// 颜色 = 重要程度(与图例一致):红=很重要 / 金=较重要 / 青=一般 / 灰=不重要;人格星核专属暖金
|
|
1769
1841
|
// 主题跟随:取 --node-* RGB 三元组(浅色主题在 enhance.css 里覆盖为深色版本)
|
|
1770
1842
|
function nodeColor(n, P){
|
|
1771
1843
|
if (n.layer === "persona" || n.kind === "persona") return "rgb(" + P.persona + ")";
|
|
1844
|
+
// 按主题簇上色:同一社区同色,一眼看出"我的记忆分成哪几块"
|
|
1845
|
+
if (GRAPH.colorBy === "community" && n.community && GRAPH.communityHue){
|
|
1846
|
+
const hue = GRAPH.communityHue.get(n.community);
|
|
1847
|
+
if (hue != null) return `hsl(${hue},58%,62%)`;
|
|
1848
|
+
}
|
|
1772
1849
|
const imp = n.importance == null ? 0.5 : n.importance;
|
|
1773
1850
|
if (imp >= 0.8) return "rgb(" + P.high + ")";
|
|
1774
1851
|
if (imp >= 0.6) return "rgb(" + P.mid + ")";
|
|
@@ -1811,6 +1888,51 @@ function stopGraphAnim(){
|
|
|
1811
1888
|
|
|
1812
1889
|
// 持续物理模拟:斥力 + 弹簧 + 微弱噪声漂浮 + 阻尼。
|
|
1813
1890
|
// 总动能低于阈值自动休眠(省电省 CPU),autoWake() 唤醒——借鉴 Obsidian graph 的做法。
|
|
1891
|
+
// 时间轴布局:关掉物理,按「写下时间」横排、按主题簇分带。
|
|
1892
|
+
// 为什么不用力导向排时间轴:力导向追求"边长一致",会把时间顺序碾平;
|
|
1893
|
+
// 时间轴要的是**可读的顺序**,位置必须由时间决定,不能被弹簧拉动。
|
|
1894
|
+
function applyTimelineLayout(){
|
|
1895
|
+
const nodes = GRAPH.data.nodes;
|
|
1896
|
+
const t0 = GRAPH.timeMin || 0;
|
|
1897
|
+
const t1 = (GRAPH.timeMax && GRAPH.timeMax > t0) ? GRAPH.timeMax : t0 + 1;
|
|
1898
|
+
stopPhysics();
|
|
1899
|
+
// 每条横带 = 一个主题簇。带太少时补随机散开,避免全挤一条线上
|
|
1900
|
+
const cids = [...new Set(nodes.map(n => n.community).filter(Boolean))];
|
|
1901
|
+
const bandOf = new Map(cids.map((c, i) => [c, i]));
|
|
1902
|
+
const bands = Math.max(1, cids.length);
|
|
1903
|
+
const spreadX = 560;
|
|
1904
|
+
const spreadY = Math.min(460, Math.max(120, bands * 30));
|
|
1905
|
+
GRAPH.pos = nodes.map(n => {
|
|
1906
|
+
if (n.layer === "persona" || n.kind === "persona") return { x: 0, y: 0, z: 0 };
|
|
1907
|
+
const t = n.created || t0;
|
|
1908
|
+
const fx = (t - t0) / Math.max(1, t1 - t0); // 0..1 时间位置
|
|
1909
|
+
const bi = bandOf.get(n.community);
|
|
1910
|
+
const y = bi == null
|
|
1911
|
+
? (hashStr(n.id) - 0.5) * spreadY // 无簇:按 hash 散开
|
|
1912
|
+
: ((bands === 1 ? 0.5 : bi / (bands - 1)) - 0.5) * spreadY;
|
|
1913
|
+
return { x: (fx - 0.5) * spreadX, y, z: (hashStr(n.id + "z") - 0.5) * 50 };
|
|
1914
|
+
});
|
|
1915
|
+
GRAPH.vel = nodes.map(() => ({ x: 0, y: 0, z: 0 }));
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// 边上命中:点到线段的距离 < 5px 就算贴上。用 renderGraph 缓存的屏幕坐标,
|
|
1919
|
+
// 不重投影——600 节点时每次 mousemove 重投影会明显掉帧。
|
|
1920
|
+
function edgeHit(mx, my){
|
|
1921
|
+
const segs = GRAPH.edgeSegs;
|
|
1922
|
+
if (!segs || !segs.length) return null;
|
|
1923
|
+
let best = null, bestD = 5 * 5;
|
|
1924
|
+
for (const s of segs){
|
|
1925
|
+
const dx = s.x2 - s.x1, dy = s.y2 - s.y1;
|
|
1926
|
+
const len2 = dx * dx + dy * dy;
|
|
1927
|
+
let t = len2 ? ((mx - s.x1) * dx + (my - s.y1) * dy) / len2 : 0;
|
|
1928
|
+
t = Math.max(0, Math.min(1, t));
|
|
1929
|
+
const px = s.x1 + t * dx, py = s.y1 + t * dy;
|
|
1930
|
+
const d = (mx - px) * (mx - px) + (my - py) * (my - py);
|
|
1931
|
+
if (d < bestD){ bestD = d; best = s; }
|
|
1932
|
+
}
|
|
1933
|
+
return best;
|
|
1934
|
+
}
|
|
1935
|
+
|
|
1814
1936
|
function startPhysics(){
|
|
1815
1937
|
stopPhysics();
|
|
1816
1938
|
let idle = 0;
|
|
@@ -1882,8 +2004,16 @@ function startPhysics(){
|
|
|
1882
2004
|
vel[i].y = (vel[i].y + p.y * f) * 0.9;
|
|
1883
2005
|
vel[i].z = (vel[i].z + p.z * f) * 0.9;
|
|
1884
2006
|
}
|
|
2007
|
+
// 人格星核**钉死在原点**:它是全图的根,一旦自己也受力漂移,
|
|
2008
|
+
// 整个图会缓慢平移、旋转中心跟着跑,看起来就是"一团在晃"。
|
|
2009
|
+
// 它仍然对别人施加斥力/弹簧(位置固定即可),只是自己不动。
|
|
2010
|
+
if (nodes.length && (nodes[0].layer === "persona" || nodes[0].kind === "persona")){
|
|
2011
|
+
pos[0].x = 0; pos[0].y = 0; pos[0].z = 0;
|
|
2012
|
+
vel[0].x = 0; vel[0].y = 0; vel[0].z = 0;
|
|
2013
|
+
}
|
|
1885
2014
|
// 位置推进遍历全部节点(不能只推前 n 个,否则尾部节点被冻结在初始位置)
|
|
1886
2015
|
for (let i = 0; i < nodes.length; i++){
|
|
2016
|
+
if (i === 0 && (nodes[0].layer === "persona" || nodes[0].kind === "persona")) continue; // 星核不动
|
|
1887
2017
|
pos[i].x += vel[i].x; pos[i].y += vel[i].y; pos[i].z += vel[i].z;
|
|
1888
2018
|
if (i < n) energy += vel[i].x*vel[i].x + vel[i].y*vel[i].y + vel[i].z*vel[i].z;
|
|
1889
2019
|
}
|
|
@@ -1938,9 +2068,20 @@ async function loadGraph(limit){
|
|
|
1938
2068
|
GRAPH.data = await api("/api/graph?limit=" + (limit || 300)
|
|
1939
2069
|
+ (GRAPH.hideIsolated ? "&hide_isolated=1" : "&hide_isolated=0"));
|
|
1940
2070
|
GRAPH.stats = GRAPH.data.stats || null;
|
|
2071
|
+
// 社区色表:id -> hue。按主题簇上色时用
|
|
2072
|
+
GRAPH.communities = GRAPH.data.communities || [];
|
|
2073
|
+
GRAPH.communityHue = new Map(GRAPH.communities.map(c => [c.id, c.hue]));
|
|
2074
|
+
// 时间范围(时间轴视图 / 双时态过滤都靠它)
|
|
2075
|
+
// 注意用 GRAPH.data.nodes 而不是后面的 const nodes —— 那行在下面才声明,
|
|
2076
|
+
// 这里引用会踩 TDZ(ReferenceError 被 loadGraph 的 try 吞掉,整张图静默不加载)。
|
|
2077
|
+
const ts = GRAPH.data.nodes.map(n => n.created || 0).filter(t => t > 0);
|
|
2078
|
+
GRAPH.timeMin = ts.length ? Math.min(...ts) : 0;
|
|
2079
|
+
GRAPH.timeMax = ts.length ? Math.max(...ts) : 0;
|
|
1941
2080
|
// 节点从中心附近"绽放"散开(借鉴 Obsidian graph view 的加载动效)
|
|
1942
2081
|
GRAPH.vel = GRAPH.data.nodes.map(() => ({ x: 0, y: 0, z: 0 }));
|
|
1943
|
-
GRAPH.pos = GRAPH.data.nodes.map(n => {
|
|
2082
|
+
GRAPH.pos = GRAPH.data.nodes.map((n, i) => {
|
|
2083
|
+
// 人格星核从原点出发(它钉死在这里);其余记忆从外壳向内绽放
|
|
2084
|
+
if (n.layer === "persona" || n.kind === "persona") return { x: 0, y: 0, z: 0 };
|
|
1944
2085
|
const a = hashStr(n.id) * Math.PI * 2, b = Math.acos(2 * hashStr(n.id + "#") - 1);
|
|
1945
2086
|
const r0 = 10 + hashStr(n.id + "@") * 30;
|
|
1946
2087
|
return { x: Math.sin(b) * Math.cos(a) * r0, y: Math.sin(b) * Math.sin(a) * r0, z: Math.cos(b) * r0 };
|
|
@@ -1965,8 +2106,20 @@ async function loadGraph(limit){
|
|
|
1965
2106
|
if (b != null) GRAPH.deg[b]++;
|
|
1966
2107
|
});
|
|
1967
2108
|
GRAPH.loaded = true;
|
|
1968
|
-
|
|
1969
|
-
|
|
2109
|
+
if (GRAPH.layout === "timeline"){
|
|
2110
|
+
applyTimelineLayout(); // 时间轴:位置由时间决定,不跑物理
|
|
2111
|
+
renderGraph();
|
|
2112
|
+
} else {
|
|
2113
|
+
startPhysics(); // 持续物理模拟:节点像活物一样漂浮舒展
|
|
2114
|
+
renderGraph();
|
|
2115
|
+
}
|
|
2116
|
+
// 时间滑杆的范围/文案跟着数据走(时间轴视图用)
|
|
2117
|
+
const tr = $("graph-time-range");
|
|
2118
|
+
if (tr){
|
|
2119
|
+
tr.value = String(GRAPH.timePct);
|
|
2120
|
+
tr.max = "100";
|
|
2121
|
+
}
|
|
2122
|
+
updateTimeLabel();
|
|
1970
2123
|
// 库里没有可画的记忆时给明确的空态引导,别让一片空白被当成"加载失败"
|
|
1971
2124
|
if (!nodes.length){
|
|
1972
2125
|
if (loadTip){ loadTip.textContent = "还没有可联想的记忆节点"; loadTip.classList.remove("hidden"); }
|
|
@@ -1982,9 +2135,11 @@ async function loadGraph(limit){
|
|
|
1982
2135
|
const gb = (s.generic_buckets || []).slice(0, 3)
|
|
1983
2136
|
.map(b => `${b.name}(${b.count})`).join("、");
|
|
1984
2137
|
const bits = [`${nodes.length} 条记忆`, `${edges.length} 条关联`];
|
|
1985
|
-
if (s.auto_candidates != null) bits.push(
|
|
2138
|
+
if (s.auto_candidates != null) bits.push(`真实关联 候选 ${s.auto_candidates} → 保留 ${s.auto_kept}`);
|
|
1986
2139
|
if (gb) bits.push(`泛标签已忽略:${gb}${s.generic_bucket_count > 3 ? " 等" + s.generic_bucket_count + "个" : ""}`);
|
|
1987
|
-
if (s.
|
|
2140
|
+
if (s.boot_edges) bits.push(`自举 ${s.boot_orphans} 条孤立记忆(稀有词重叠接进网)`);
|
|
2141
|
+
if (s.orphan_count) bits.push(`⚠ ${s.orphan_count} 条连不到人格`);
|
|
2142
|
+
else bits.push("全部可追溯到人格(无断点)");
|
|
1988
2143
|
$("graph-hint").textContent = bits.join(" · ") + " · 点节点:以它为中心 + 激活相邻记忆";
|
|
1989
2144
|
$("graph-stat").textContent = `${nodes.length} 节点 · ${edges.length} 关联边 · 手动 ${edges.length - nAuto} / 自动 ${nAuto}`;
|
|
1990
2145
|
}
|
|
@@ -2026,7 +2181,23 @@ function renderGraph(){
|
|
|
2026
2181
|
const visSet = visible ? new Set(visible) : null;
|
|
2027
2182
|
const proj = GRAPH.pos.map(project);
|
|
2028
2183
|
const shown = new Set();
|
|
2029
|
-
|
|
2184
|
+
// 双时态时间闸:滑杆拖到 T,就只看"T 时刻已经存在、且还没失效"的记忆与关联。
|
|
2185
|
+
// 判据用边的 t_from / t_to(后端按记忆 created、forgotten_at 推出来的生效窗口)。
|
|
2186
|
+
const cut = (GRAPH.timePct >= 100 || !GRAPH.timeMax)
|
|
2187
|
+
? Infinity
|
|
2188
|
+
: GRAPH.timeMin + (GRAPH.timeMax - GRAPH.timeMin) * (GRAPH.timePct / 100);
|
|
2189
|
+
const inTimeNode = i => !isFinite(cut) || (nodes[i].created || 0) <= cut;
|
|
2190
|
+
const inTimeEdge = e => {
|
|
2191
|
+
if (!isFinite(cut)) return true;
|
|
2192
|
+
if (e.t_from && e.t_from > cut) return false; // 还没发生
|
|
2193
|
+
if (e.t_to && e.t_to <= cut) return false; // 已经失效
|
|
2194
|
+
return true;
|
|
2195
|
+
};
|
|
2196
|
+
proj.forEach((p, i) => {
|
|
2197
|
+
if (visSet && !visSet.has(i)) return;
|
|
2198
|
+
if (!inTimeNode(i)) return;
|
|
2199
|
+
if (p.z < GRAPH.dist * 0.9 && p.s > 0.12) shown.add(i);
|
|
2200
|
+
});
|
|
2030
2201
|
|
|
2031
2202
|
// 注意力焦点:选中的节点 + 它的直接邻居被"点亮",其余压暗(激活扩散 / 侧抑制)
|
|
2032
2203
|
const sel = GRAPH.selected;
|
|
@@ -2039,10 +2210,12 @@ function renderGraph(){
|
|
|
2039
2210
|
|
|
2040
2211
|
// 边:粗细随权重(联系强弱),焦点相关边更亮,无关边压暗
|
|
2041
2212
|
const idIdx = new Map(nodes.map((x, i) => [x.id, i]));
|
|
2213
|
+
GRAPH.edgeSegs = []; // 投影后的线段缓存:鼠标悬停时用来命中"最近的边"
|
|
2042
2214
|
edges.forEach(e => {
|
|
2043
2215
|
const ai = idIdx.get(e.src), bi = idIdx.get(e.dst);
|
|
2044
2216
|
if (ai == null || bi == null) return;
|
|
2045
2217
|
if (!shown.has(ai) || !shown.has(bi)) return;
|
|
2218
|
+
if (!inTimeEdge(e)) return; // 双时态:还没生效/已失效的边不画
|
|
2046
2219
|
const pa = proj[ai], pb = proj[bi];
|
|
2047
2220
|
const touchSel = sel != null && (ai === sel || bi === sel);
|
|
2048
2221
|
// hover 高亮:未选中节点时点亮与 hover 节点相连的边(选中态优先,hover 不覆盖)
|
|
@@ -2051,18 +2224,40 @@ function renderGraph(){
|
|
|
2051
2224
|
const onPath = GRAPH.pathEdges != null && GRAPH.pathEdges.includes(e._ei);
|
|
2052
2225
|
const edgeHot = sel == null || touchSel || (hot.has(ai) && hot.has(bi));
|
|
2053
2226
|
const w = Math.min(1.8, 0.3 + e.weight * 0.35);
|
|
2054
|
-
|
|
2227
|
+
// 边分三类,视觉上要能一眼分开:
|
|
2228
|
+
// anchor(人格接入点,很少几条) —— 实线偏亮,它是"根"
|
|
2229
|
+
// manual/auto(真实关联) —— 实线/虚线,主体
|
|
2230
|
+
// boot(孤立自举,稀有词重叠) —— 极淡虚线,只为连通,不抢注意力
|
|
2231
|
+
const spoke = !!e.anchor;
|
|
2232
|
+
const boot = !!e.boot;
|
|
2233
|
+
const isHoverEdge = GRAPH.hoverEdge && GRAPH.hoverEdge.e === e;
|
|
2234
|
+
ctx.lineWidth = (isHoverEdge || touchSel || onPath) ? w + 1.6 : (w + 0.5) * (edgeHot || touchHover ? 1 : 0.55);
|
|
2235
|
+
if (isHoverEdge){
|
|
2236
|
+
ctx.globalAlpha = 1;
|
|
2237
|
+
} else if (boot && !touchSel && !onPath){
|
|
2238
|
+
ctx.globalAlpha = sel != null && !hot.has(ai) && !hot.has(bi) ? 0.05 : 0.16;
|
|
2239
|
+
} else {
|
|
2240
|
+
ctx.globalAlpha = 1;
|
|
2241
|
+
}
|
|
2055
2242
|
// 路径边必须看清走向,用实线盖过自动联想的虚线
|
|
2056
2243
|
ctx.setLineDash(e.auto && !onPath ? [3, 5] : []);
|
|
2057
2244
|
ctx.strokeStyle = onPath
|
|
2058
2245
|
? "rgba(" + P.path + ",.9)"
|
|
2059
|
-
:
|
|
2246
|
+
: isHoverEdge
|
|
2247
|
+
? "rgba(" + P.path + ",.95)"
|
|
2248
|
+
: touchSel || touchHover
|
|
2060
2249
|
? "rgba(" + P.path + ",.85)"
|
|
2061
2250
|
: e.auto
|
|
2062
2251
|
? "rgba(" + P.edge + "," + (edgeHot ? 0.04 + Math.min(0.28, e.weight * 0.07) : 0.025 + Math.min(0.12, e.weight * 0.03)) + ")"
|
|
2063
2252
|
: "rgba(" + P.edge + "," + (edgeHot ? 0.05 + Math.min(0.4, e.weight * 0.1) : 0.03 + Math.min(0.18, e.weight * 0.04)) + ")";
|
|
2064
2253
|
ctx.beginPath(); ctx.moveTo(cx + pa.x, cy + pa.y); ctx.lineTo(cx + pb.x, cy + pb.y); ctx.stroke();
|
|
2065
2254
|
ctx.setLineDash([]);
|
|
2255
|
+
ctx.globalAlpha = 1; // 每轮复位:否则星形边的低透明度会漏到后面画的节点上
|
|
2256
|
+
// 缓存线段供悬停命中(只存屏幕坐标,避免每次 mousemove 重投影)
|
|
2257
|
+
GRAPH.edgeSegs.push({
|
|
2258
|
+
x1: cx + pa.x, y1: cy + pa.y, x2: cx + pb.x, y2: cy + pb.y,
|
|
2259
|
+
e, label: e.why || "",
|
|
2260
|
+
});
|
|
2066
2261
|
});
|
|
2067
2262
|
|
|
2068
2263
|
// 节点(先画非焦点,再画焦点;近的压在上面)
|
|
@@ -2105,11 +2300,47 @@ function renderGraph(){
|
|
|
2105
2300
|
};
|
|
2106
2301
|
order.forEach(i => { if (hot.size && !hot.has(i)) drawNode(i); });
|
|
2107
2302
|
order.forEach(i => { if (!hot.size || hot.has(i)) drawNode(i); });
|
|
2303
|
+
|
|
2304
|
+
// ---- 簇标签(LOD):缩远时在每簇重心写名字 ----
|
|
2305
|
+
// 为什么需要:171 个点 + 231 条边,缩到全景时单个节点的标签全挤在一起没法读。
|
|
2306
|
+
// 画在簇重心上,缩放越小越有用——这就是"语义缩放"(GraphRAG 的社区报告在
|
|
2307
|
+
// 视觉上的对应物:不展开内容,先告诉你"这一块讲什么")。
|
|
2308
|
+
if (GRAPH.colorBy === "community" && GRAPH.communities && GRAPH.communities.length){
|
|
2309
|
+
const acc = new Map(); // cid -> {x,y,n}
|
|
2310
|
+
proj.forEach((p, i) => {
|
|
2311
|
+
const cid = nodes[i].community;
|
|
2312
|
+
if (!cid || !shown.has(i)) return;
|
|
2313
|
+
const a = acc.get(cid) || { x: 0, y: 0, n: 0 };
|
|
2314
|
+
a.x += p.x; a.y += p.y; a.n++;
|
|
2315
|
+
acc.set(cid, a);
|
|
2316
|
+
});
|
|
2317
|
+
ctx.textAlign = "center";
|
|
2318
|
+
GRAPH.communities.forEach(c => {
|
|
2319
|
+
const a = acc.get(c.id);
|
|
2320
|
+
if (!a || a.n < 3) return; // 太小的簇不标注,免得满屏字
|
|
2321
|
+
const x = cx + a.x / a.n, y = cy + a.y / a.n;
|
|
2322
|
+
const label = `${c.label} · ${c.size}`;
|
|
2323
|
+
ctx.font = "600 12px system-ui,sans-serif";
|
|
2324
|
+
const w = ctx.measureText(label).width;
|
|
2325
|
+
ctx.globalAlpha = 0.9;
|
|
2326
|
+
ctx.fillStyle = "rgba(10,12,15,.72)";
|
|
2327
|
+
ctx.beginPath();
|
|
2328
|
+
if (ctx.roundRect) ctx.roundRect(x - w / 2 - 6, y - 10, w + 12, 20, 6);
|
|
2329
|
+
else ctx.rect(x - w / 2 - 6, y - 10, w + 12, 20);
|
|
2330
|
+
ctx.fill();
|
|
2331
|
+
ctx.fillStyle = `hsl(${c.hue},70%,72%)`;
|
|
2332
|
+
ctx.fillText(label, x, y + 4);
|
|
2333
|
+
ctx.globalAlpha = 1;
|
|
2334
|
+
});
|
|
2335
|
+
ctx.textAlign = "start";
|
|
2336
|
+
}
|
|
2108
2337
|
const t = $("graph-tip");
|
|
2109
|
-
if (t) t.textContent = GRAPH.
|
|
2110
|
-
?
|
|
2111
|
-
|
|
2112
|
-
|
|
2338
|
+
if (t) t.textContent = GRAPH.hoverEdge
|
|
2339
|
+
? "边:" + (GRAPH.hoverEdge.e.why || "关联")
|
|
2340
|
+
: (GRAPH.hover != null && nodes[GRAPH.hover]
|
|
2341
|
+
? docsOf(nodes[GRAPH.hover]) : (sel != null
|
|
2342
|
+
? "已聚焦 1 条记忆 + " + ((hot.size - 1) || 0) + " 条被激活的相邻记忆 · 按 Esc 或点「重置视角」回到全景"
|
|
2343
|
+
: "总记忆 " + nodes.length + " · 拖动旋转"));
|
|
2113
2344
|
}
|
|
2114
2345
|
|
|
2115
2346
|
// 搜索定位:按 gist/id 找节点,选中并聚焦到它;回车循环看下一条
|
|
@@ -2310,8 +2541,18 @@ function initGraphInteractions(){
|
|
|
2310
2541
|
scheduleGraph();
|
|
2311
2542
|
} else {
|
|
2312
2543
|
const rect = canvas.getBoundingClientRect();
|
|
2313
|
-
|
|
2314
|
-
|
|
2544
|
+
const mx = e.clientX - rect.left, my = e.clientY - rect.top;
|
|
2545
|
+
GRAPH.hover = graphHit(mx, my);
|
|
2546
|
+
// 没命中节点时,再看有没有贴着某条边——贴上了就把"为什么连"显示出来。
|
|
2547
|
+
// 边证据是这张图最有价值的部分之一:不解释的话,用户只能看到一堆凭空的线。
|
|
2548
|
+
GRAPH.hoverEdge = GRAPH.hover == null ? edgeHit(mx, my) : null;
|
|
2549
|
+
if (GRAPH.hoverEdge){
|
|
2550
|
+
canvas.style.cursor = "help";
|
|
2551
|
+
const t = $("graph-tip");
|
|
2552
|
+
if (t) t.textContent = "边:" + (GRAPH.hoverEdge.e.why || "关联");
|
|
2553
|
+
} else {
|
|
2554
|
+
canvas.style.cursor = GRAPH.hover != null ? "pointer" : "grab";
|
|
2555
|
+
}
|
|
2315
2556
|
scheduleGraph();
|
|
2316
2557
|
}
|
|
2317
2558
|
});
|
|
@@ -3308,7 +3549,7 @@ function switchTab(tab){
|
|
|
3308
3549
|
if (tab === "logs") loadLogs();
|
|
3309
3550
|
// 诊断页有两张随时间变化的卡:体检结果 + 数据目录位置,进页面时一起刷(以前只刷体检,
|
|
3310
3551
|
// 数据目录卡靠一段 class 判断写错的 MutationObserver,永远停在「加载中…」)
|
|
3311
|
-
if (tab === "diag") { loadDiagnostics(); loadHomeInfo(); renderDoctorHistory(); }
|
|
3552
|
+
if (tab === "diag") { loadDiagnostics(); loadHomeInfo(); renderDoctorHistory(); loadHotkey(); loadIcon(); }
|
|
3312
3553
|
if (tab === "persona") { loadSnapshots(); loadPersonaSuggest(); } // 切到人格页时顺手刷快照列表与画像归纳建议
|
|
3313
3554
|
// 概览/心情/梦 三页的数据都在 overview 里(心情与六欲是按时间衰减的活数值)。
|
|
3314
3555
|
// 以前只靠 30 秒轮询 + document.hidden 跳过,切过去可能看到最多 30 秒前的旧值。
|
|
@@ -3884,6 +4125,51 @@ $("graph-hide-isolated") && $("graph-hide-isolated").addEventListener("change",
|
|
|
3884
4125
|
GRAPH.hideIsolated = !!e.target.checked;
|
|
3885
4126
|
loadGraph(Number($("graph-limit").value || 300));
|
|
3886
4127
|
});
|
|
4128
|
+
// 上色依据:重要度 / 主题簇。只改渲染,不用重新拉数据
|
|
4129
|
+
$("graph-color") && $("graph-color").addEventListener("change", e => {
|
|
4130
|
+
GRAPH.colorBy = e.target.value === "community" ? "community" : "importance";
|
|
4131
|
+
renderGraph();
|
|
4132
|
+
});
|
|
4133
|
+
|
|
4134
|
+
// 布局切换:力导向 ↔ 时间轴。时间轴把物理关掉,位置由 created 决定
|
|
4135
|
+
$("graph-layout") && $("graph-layout").addEventListener("change", e => {
|
|
4136
|
+
GRAPH.layout = e.target.value === "timeline" ? "timeline" : "force";
|
|
4137
|
+
const tb = $("graph-time");
|
|
4138
|
+
if (tb) tb.classList.toggle("hidden", GRAPH.layout !== "timeline");
|
|
4139
|
+
if (!GRAPH.loaded) return;
|
|
4140
|
+
if (GRAPH.layout === "timeline"){
|
|
4141
|
+
applyTimelineLayout();
|
|
4142
|
+
renderGraph();
|
|
4143
|
+
} else {
|
|
4144
|
+
// 回力导向:位置打散后重新收敛,否则会从"时间横排"直接弹到力导向结果
|
|
4145
|
+
GRAPH.pos = GRAPH.data.nodes.map(n => {
|
|
4146
|
+
if (n.layer === "persona" || n.kind === "persona") return { x: 0, y: 0, z: 0 };
|
|
4147
|
+
const a = hashStr(n.id) * Math.PI * 2, b = Math.acos(2 * hashStr(n.id + "#") - 1);
|
|
4148
|
+
const r0 = 10 + hashStr(n.id + "@") * 30;
|
|
4149
|
+
return { x: Math.sin(b) * Math.cos(a) * r0, y: Math.sin(b) * Math.sin(a) * r0, z: Math.cos(b) * r0 };
|
|
4150
|
+
});
|
|
4151
|
+
GRAPH.vel = GRAPH.data.nodes.map(() => ({ x: 0, y: 0, z: 0 }));
|
|
4152
|
+
startPhysics();
|
|
4153
|
+
}
|
|
4154
|
+
});
|
|
4155
|
+
|
|
4156
|
+
// 时间滑杆:拖到某一刻 → 只看那一刻"已知且未失效"的记忆与关联(双时态)
|
|
4157
|
+
function updateTimeLabel(){
|
|
4158
|
+
const lb = $("graph-time-label"), ct = $("graph-time-count");
|
|
4159
|
+
if (!lb) return;
|
|
4160
|
+
if (!GRAPH.timeMax){ lb.textContent = "—"; if (ct) ct.textContent = ""; return; }
|
|
4161
|
+
const cut = GRAPH.timeMin + (GRAPH.timeMax - GRAPH.timeMin) * (GRAPH.timePct / 100);
|
|
4162
|
+
lb.textContent = new Date(cut * 1000).toLocaleString("zh-CN", { hour12: false }).slice(0, 16);
|
|
4163
|
+
if (ct && GRAPH.data){
|
|
4164
|
+
const n = GRAPH.data.nodes.filter(x => (x.created || 0) <= cut).length;
|
|
4165
|
+
ct.textContent = GRAPH.timePct >= 100 ? `全部 ${n} 条` : `当时 ${n} 条`;
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
$("graph-time-range") && $("graph-time-range").addEventListener("input", e => {
|
|
4169
|
+
GRAPH.timePct = Number(e.target.value);
|
|
4170
|
+
updateTimeLabel();
|
|
4171
|
+
renderGraph();
|
|
4172
|
+
});
|
|
3887
4173
|
// 图内搜索:输入即定位(300ms 防抖),回车看下一个命中
|
|
3888
4174
|
let _gsTimer = null;
|
|
3889
4175
|
$("graph-search").addEventListener("input", e => {
|
|
@@ -4266,6 +4552,192 @@ async function migrateHome(){
|
|
|
4266
4552
|
}
|
|
4267
4553
|
$("btn-home-refresh") && $("btn-home-refresh").addEventListener("click", loadHomeInfo);
|
|
4268
4554
|
$("btn-home-migrate") && $("btn-home-migrate").addEventListener("click", migrateHome);
|
|
4555
|
+
|
|
4556
|
+
// ---- 启动快捷键(桌面快捷方式的 Hotkey 字段)
|
|
4557
|
+
// 读一次就缓存:这一步要走 PowerShell COM,冷启动实测 4–30 秒。
|
|
4558
|
+
// 每次切到诊断页都重新读的话,卡片会长时间停在"读取中",看起来像坏了。
|
|
4559
|
+
let _hotkeyCache = null;
|
|
4560
|
+
async function loadHotkey(force){
|
|
4561
|
+
const box = $("hotkey-info"); if (!box) return;
|
|
4562
|
+
if (_hotkeyCache && !force){
|
|
4563
|
+
renderHotkey(_hotkeyCache);
|
|
4564
|
+
return;
|
|
4565
|
+
}
|
|
4566
|
+
box.innerHTML = `<div class="sub">读取中…(首次要调用系统 COM,可能需要几秒)</div>`;
|
|
4567
|
+
try {
|
|
4568
|
+
const d = await api("/api/panel-shortcut");
|
|
4569
|
+
if (d.error) throw new Error(d.error);
|
|
4570
|
+
_hotkeyCache = d;
|
|
4571
|
+
renderHotkey(d);
|
|
4572
|
+
} catch (e) {
|
|
4573
|
+
box.innerHTML = `<div class="empty">${esc(e.message)}</div>`;
|
|
4574
|
+
}
|
|
4575
|
+
}
|
|
4576
|
+
function renderHotkey(d){
|
|
4577
|
+
const box = $("hotkey-info"); if (!box) return;
|
|
4578
|
+
const cur = (d.hotkey || "").trim();
|
|
4579
|
+
// intact=false 意味着 .lnk 被写坏了:桌面图标会变白、双击没反应。
|
|
4580
|
+
// 这种状态必须显眼告警,并把「修复快捷方式」摆到眼前。
|
|
4581
|
+
const broken = d.intact === false;
|
|
4582
|
+
box.innerHTML =
|
|
4583
|
+
(broken
|
|
4584
|
+
? `<div class="sub" style="color:var(--red)">⚠ 快捷方式不完整(目标/参数/图标有缺失)——桌面图标可能已变白、双击没反应。点「修复快捷方式」重建。</div>`
|
|
4585
|
+
: "")
|
|
4586
|
+
+ `<div class="sub">快捷方式 <code>${esc(d.path || "")}</code> · 当前${
|
|
4587
|
+
cur ? ` <span class="chip good">${esc(cur)}</span>` : ' <span class="chip">未设置</span>'}</div>`;
|
|
4588
|
+
const inp = $("hotkey-input");
|
|
4589
|
+
if (inp && !inp.value && cur) inp.value = cur;
|
|
4590
|
+
}
|
|
4591
|
+
async function saveHotkey(value){
|
|
4592
|
+
const msg = $("hotkey-msg");
|
|
4593
|
+
msg.innerHTML = `<span class="chip">正在写入快捷方式…</span>`;
|
|
4594
|
+
try {
|
|
4595
|
+
const r = await post("/api/panel-shortcut", {hotkey: value});
|
|
4596
|
+
if (r.error) throw new Error(r.error);
|
|
4597
|
+
if (r.verified === false)
|
|
4598
|
+
msg.innerHTML = `<span class="chip bad">写入未生效(系统拒绝了这个组合),当前是「${esc(r.applied || "无")}」</span>`;
|
|
4599
|
+
else
|
|
4600
|
+
msg.innerHTML = `<span class="chip good">✔ ${r.applied ? "已设为 " + esc(r.applied) : "已清除快捷键"}</span>`;
|
|
4601
|
+
_hotkeyCache = null; // 写入后缓存失效,强制回读真实值
|
|
4602
|
+
loadHotkey(true);
|
|
4603
|
+
} catch (e) {
|
|
4604
|
+
msg.innerHTML = `<span class="chip bad">✘ ${esc(e.message)}</span>`;
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4607
|
+
$("btn-hotkey-refresh") && $("btn-hotkey-refresh").addEventListener("click", () => {
|
|
4608
|
+
loadHotkey(true);
|
|
4609
|
+
loadIcon(true);
|
|
4610
|
+
});
|
|
4611
|
+
|
|
4612
|
+
// ---- 通用确认弹窗(Promise<boolean>)
|
|
4613
|
+
// 为什么不用原生 confirm():原生框在深色面板里是一块突兀的白框,而且标题固定是
|
|
4614
|
+
// 浏览器域名,说不清"到底要还原什么"。这里用面板自己的 .modal 样式,
|
|
4615
|
+
// 并把焦点默认放在「取消」上——手滑按回车不会执行破坏性操作。
|
|
4616
|
+
function confirmDialog(title, text, okLabel){
|
|
4617
|
+
return new Promise(resolve => {
|
|
4618
|
+
const m = $("confirm-modal");
|
|
4619
|
+
if (!m) { resolve(window.confirm(text)); return; } // 兜底
|
|
4620
|
+
$("confirm-title").textContent = title || "确认操作";
|
|
4621
|
+
$("confirm-text").textContent = text || "";
|
|
4622
|
+
$("confirm-ok").textContent = okLabel || "确定";
|
|
4623
|
+
m.classList.remove("hidden");
|
|
4624
|
+
const done = (v) => {
|
|
4625
|
+
m.classList.add("hidden");
|
|
4626
|
+
$("confirm-ok").removeEventListener("click", onOk);
|
|
4627
|
+
$("confirm-cancel").removeEventListener("click", onNo);
|
|
4628
|
+
m.removeEventListener("click", onMask);
|
|
4629
|
+
document.removeEventListener("keydown", onKey, true);
|
|
4630
|
+
resolve(v);
|
|
4631
|
+
};
|
|
4632
|
+
const onOk = () => done(true);
|
|
4633
|
+
const onNo = () => done(false);
|
|
4634
|
+
const onMask = (e) => { if (e.target === m) done(false); };
|
|
4635
|
+
const onKey = (e) => {
|
|
4636
|
+
if (e.key === "Escape"){ e.stopPropagation(); done(false); }
|
|
4637
|
+
else if (e.key === "Enter"){ e.preventDefault(); done(true); }
|
|
4638
|
+
};
|
|
4639
|
+
$("confirm-ok").addEventListener("click", onOk);
|
|
4640
|
+
$("confirm-cancel").addEventListener("click", onNo);
|
|
4641
|
+
m.addEventListener("click", onMask);
|
|
4642
|
+
document.addEventListener("keydown", onKey, true);
|
|
4643
|
+
setTimeout(() => $("confirm-cancel").focus(), 0); // 默认落在取消
|
|
4644
|
+
});
|
|
4645
|
+
}
|
|
4646
|
+
|
|
4647
|
+
// ---- 自定义快捷方式图标
|
|
4648
|
+
// 选图由**服务端**弹 Windows 原生文件框(浏览器拿不到真实路径),
|
|
4649
|
+
// 用户可能慢慢挑,所以这一次请求要放宽超时(默认 15s 会先断)。
|
|
4650
|
+
let _iconCache = null;
|
|
4651
|
+
async function loadIcon(force){
|
|
4652
|
+
const img = $("icon-preview"), st = $("icon-state");
|
|
4653
|
+
if (!img) return;
|
|
4654
|
+
if (_iconCache && !force){ renderIcon(_iconCache); return; }
|
|
4655
|
+
st.textContent = "读取中…";
|
|
4656
|
+
try {
|
|
4657
|
+
const d = await api("/api/panel-icon");
|
|
4658
|
+
if (!d.ok) throw new Error(d.error || "读取失败");
|
|
4659
|
+
_iconCache = d;
|
|
4660
|
+
renderIcon(d);
|
|
4661
|
+
} catch (e) {
|
|
4662
|
+
st.textContent = "";
|
|
4663
|
+
$("icon-msg").innerHTML = `<span class="chip bad">${esc(e.message)}</span>`;
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
function renderIcon(d){
|
|
4667
|
+
const img = $("icon-preview"), st = $("icon-state");
|
|
4668
|
+
if (img && d.preview){ img.src = d.preview; img.style.visibility = "visible"; }
|
|
4669
|
+
if (st) st.textContent = d.using_custom ? "自定义" : "默认";
|
|
4670
|
+
if (!d.pillow){
|
|
4671
|
+
$("icon-msg").innerHTML = `<span class="chip">没有 Pillow,只能选现成的 .ico 文件</span>`;
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
async function pickIcon(){
|
|
4675
|
+
const msg = $("icon-msg");
|
|
4676
|
+
msg.innerHTML = `<span class="chip">已弹出文件选择框——请在弹出的窗口里选图片(选完这里会更新)</span>`;
|
|
4677
|
+
try {
|
|
4678
|
+
// 200s:用户在原生对话框里可能挑很久
|
|
4679
|
+
const r = await api("/api/panel-icon", {
|
|
4680
|
+
method: "POST",
|
|
4681
|
+
headers: {"Content-Type": "application/json"},
|
|
4682
|
+
body: JSON.stringify({action: "pick"}),
|
|
4683
|
+
timeoutMs: 200000,
|
|
4684
|
+
});
|
|
4685
|
+
if (r.cancelled){ msg.innerHTML = `<span class="chip">已取消,图标未改动</span>`; return; }
|
|
4686
|
+
if (!r.ok) throw new Error(r.error || "失败");
|
|
4687
|
+
msg.innerHTML = `<span class="chip good">✔ 图标已更新(${(r.sizes || []).length} 档尺寸)</span>`;
|
|
4688
|
+
_iconCache = null;
|
|
4689
|
+
loadIcon(true);
|
|
4690
|
+
} catch (e) {
|
|
4691
|
+
msg.innerHTML = `<span class="chip bad">✘ ${esc(e.message)}</span>`;
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
async function resetIcon(){
|
|
4695
|
+
const msg = $("icon-msg");
|
|
4696
|
+
// 还原是不可逆的(随手选的图会被默认图标顶掉),先问一句、默认停在「取消」
|
|
4697
|
+
const ok = await confirmDialog(
|
|
4698
|
+
"还原默认图标",
|
|
4699
|
+
"把桌面快捷方式的图标还原成灵枢出厂图标?\n\n"
|
|
4700
|
+
+ "· 当前自定义图标文件不会被删除,随时可以再选回来;\n"
|
|
4701
|
+
+ "· 桌面和任务栏上的图标会立刻变回原来的样子。",
|
|
4702
|
+
"还原");
|
|
4703
|
+
if (!ok){ msg.innerHTML = `<span class="chip">已取消,图标未改动</span>`; return; }
|
|
4704
|
+
msg.innerHTML = `<span class="chip">正在还原默认图标…</span>`;
|
|
4705
|
+
try {
|
|
4706
|
+
const r = await post("/api/panel-icon", {action: "reset"});
|
|
4707
|
+
if (!r.ok) throw new Error(r.error || "失败");
|
|
4708
|
+
msg.innerHTML = `<span class="chip good">✔ 已还原默认图标</span>`;
|
|
4709
|
+
_iconCache = null;
|
|
4710
|
+
loadIcon(true);
|
|
4711
|
+
} catch (e) {
|
|
4712
|
+
msg.innerHTML = `<span class="chip bad">✘ ${esc(e.message)}</span>`;
|
|
4713
|
+
}
|
|
4714
|
+
}
|
|
4715
|
+
$("btn-icon-pick") && $("btn-icon-pick").addEventListener("click", pickIcon);
|
|
4716
|
+
$("btn-icon-reset") && $("btn-icon-reset").addEventListener("click", resetIcon);
|
|
4717
|
+
$("btn-hotkey-save") && $("btn-hotkey-save").addEventListener("click", () => {
|
|
4718
|
+
const v = ($("hotkey-input").value || "").trim();
|
|
4719
|
+
if (!v) { $("hotkey-msg").innerHTML = `<span class="chip bad">先填一个组合,如 CTRL+ALT+L</span>`; return; }
|
|
4720
|
+
saveHotkey(v);
|
|
4721
|
+
});
|
|
4722
|
+
$("btn-hotkey-clear") && $("btn-hotkey-clear").addEventListener("click", () => {
|
|
4723
|
+
$("hotkey-input").value = "";
|
|
4724
|
+
saveHotkey("");
|
|
4725
|
+
});
|
|
4726
|
+
// 修复快捷方式:桌面图标变白 / 双击没反应时用(.lnk 被写坏会自动出现这种情况)
|
|
4727
|
+
$("btn-hotkey-repair") && $("btn-hotkey-repair").addEventListener("click", async () => {
|
|
4728
|
+
const msg = $("hotkey-msg");
|
|
4729
|
+
msg.innerHTML = `<span class="chip">正在重建快捷方式…</span>`;
|
|
4730
|
+
try {
|
|
4731
|
+
const r = await post("/api/panel-shortcut", {action: "repair"});
|
|
4732
|
+
if (r.error) throw new Error(r.error);
|
|
4733
|
+
if (!r.ok) throw new Error("重建后仍不完整,请检查启动器 .vbs 是否存在");
|
|
4734
|
+
msg.innerHTML = `<span class="chip good">✔ 快捷方式已重建(目标/参数/图标齐全)</span>`;
|
|
4735
|
+
_hotkeyCache = null;
|
|
4736
|
+
loadHotkey(true);
|
|
4737
|
+
} catch (e) {
|
|
4738
|
+
msg.innerHTML = `<span class="chip bad">✘ ${esc(e.message)}</span>`;
|
|
4739
|
+
}
|
|
4740
|
+
});
|
|
4269
4741
|
// 进诊断页由 switchTab 统一触发(以前这里观察的是 class "on",而页签用的是 "active",
|
|
4270
4742
|
// 条件永远不成立 → 数据目录卡一直停在「加载中…」)
|
|
4271
4743
|
|