🔥 Sync 2026-11-16 16:50:07

This commit is contained in:
github-actions[bot] committed 2026-11-16 16:50:08 +08:00
1 parent 6b8b3fec62
commit a2bf4e439b
87 files changed
+2498 -180

No files matched your search

@@ -56,6 +56,8 @@ return view.extend({
<h3 class="td-sect-t">${esc(T('首页卡片', 'Home cards'))}</h3>
<p class="td-sect-d">${esc(T('“网络连接”卡片始终显示。', 'The Connection card is always shown.'))}</p>
<div class="td-rows">${cards}</div>
<div class="td-row"><div class="lb"><b>${esc(T('速率单位', 'Speed unit'))}</b></div>
<div class="td-seg" id="td-units"><button type="button" data-m="bit">Mbps</button><button type="button" data-m="byte">MB/s</button></div></div>
</section>
<div class="td-hint">${icon('info')}<span>${esc(T('换回原主题:系统 → 通用 → 语言和界面', 'Switch back: System → General → Language and Style'))}</span></div>
@@ -65,6 +67,7 @@ return view.extend({
root.querySelectorAll('[data-pick]').forEach(b => b.addEventListener('click', () => this.update({ palette: b.dataset.pick })));
root.querySelectorAll('#td-modes button').forEach(b => b.addEventListener('click', () => this.update({ mode: b.dataset.m })));
root.querySelectorAll('#td-units button').forEach(b => b.addEventListener('click', () => this.update({ rate_unit: b.dataset.m })));
root.querySelectorAll('[data-card]').forEach(b => b.addEventListener('click', () => {
const k = b.dataset.card, field = td.OPT_IN.indexOf(k) > -1 ? 'shown_cards' : 'hidden_cards';
const list = td.words(this.conf[field]), i = list.indexOf(k);
@@ -85,9 +88,10 @@ return view.extend({
sync() {
const c = this.conf;
this.root.querySelectorAll('.td-pal').forEach(b => b.classList.toggle('on', b.dataset.pick == c.palette));
this.root.querySelectorAll('#td-modes button').forEach(b => b.classList.toggle('on', b.dataset.m == c.mode));
this.root.querySelectorAll('[data-card]').forEach(b => b.classList.toggle('on', td.cardOn(c, b.dataset.card)));
this.root.querySelectorAll('.td-pal').forEach(b => td.press(b, b.dataset.pick == c.palette));
this.root.querySelectorAll('#td-modes button').forEach(b => td.press(b, b.dataset.m == c.mode));
this.root.querySelectorAll('#td-units button').forEach(b => td.press(b, b.dataset.m == c.rate_unit));
this.root.querySelectorAll('[data-card]').forEach(b => td.press(b, td.cardOn(c, b.dataset.card)));
},
update(patch) {
@@ -81,6 +81,7 @@ return view.extend({
const software = td.software(menu);
this.s = {
inBytes: conf.rate_unit == 'byte',
down: new Array(N).fill(0), up: new Array(N).fill(0),
last: null, cpu: td.cpuStat(stat), cpuPct: null, wan: wan, wifi: wifi || { radios: {}, aps: [] }, info: info, board: board,
clients: [], ping: null, apps: apps, hasWifi: !!(wifi && Object.keys(wifi.radios).length), mode: mode
@@ -269,6 +270,8 @@ return view.extend({
if (!ok) {
this.set('td-proto', T('没有连接', 'Not connected'));
[ 'td-wanip', 'td-dns', 'td-wanup', 'td-ping' ].forEach(id => this.set(id, '—')); // not the last connection's values
this.set('td-lat', T('未连接', 'Offline'));
return;
}
@@ -402,7 +405,7 @@ return view.extend({
const rx = Math.max(0, (d.rx - this.s.last.rx) / dt), tx = Math.max(0, (d.tx - this.s.last.tx) / dt);
this.s.down.push(rx); this.s.down.shift();
this.s.up.push(tx); this.s.up.shift();
const [ dv, du ] = td.rate(rx), [ uv, uu ] = td.rate(tx);
const [ dv, du ] = td.rate(rx, this.s.inBytes), [ uv, uu ] = td.rate(tx, this.s.inBytes);
this.set('td-down', dv); this.set('td-down-u', du);
this.set('td-up', uv); this.set('td-up-u', uu);
this.drawChart();
@@ -493,13 +496,14 @@ return view.extend({
pingGateway() {
const w = this.s.wan;
if (!w || !w.gw || !/^[0-9.]+$/.test(w.gw)) {
if (!w || !w.up || !w.gw || !/^[0-9.]+$/.test(w.gw)) {
this.set('td-lat', w && w.up ? T('已连接', 'Connected') : T('未连接', 'Offline'));
return Promise.resolve();
}
/* a gateway that never answers ping (many ISP modems) is retried every few minutes, not every 30 s */
if (this.s.miss >= 3 && this.ticks % 18) return Promise.resolve();
return L.resolveDefault(fs.exec('/bin/ping', [ '-c', '1', '-W', '1', w.gw ]), {}).then(r => {
if (!this.s.wan || !this.s.wan.up || this.s.wan.gw != w.gw) return; // the connection changed while we waited
const m = String((r || {}).stdout || '').match(/time[=<]([\d.]+)/);
const v = m ? (+m[1] < 1 ? '<1' : Math.round(+m[1])) + ' ms' : null;
this.s.miss = v ? 0 : (this.s.miss || 0) + 1;
@@ -537,7 +541,7 @@ return view.extend({
/* OpenClash's proxy mode, switched through its own switch_rule_mode call */
ocSwitch(seg) {
let mode = seg.dataset.oc;
const mark = m => seg.querySelectorAll('button').forEach(b => b.classList.toggle('on', b.dataset.m == m));
const mark = m => seg.querySelectorAll('button').forEach(b => td.press(b, b.dataset.m == m));
mark(mode);
seg.addEventListener('click', ev => {
const b = ev.target.closest('button[data-m]');