forked from ck9393/fanctrlplus
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFanctrlPlus.Dashboard.page
More file actions
328 lines (284 loc) · 9.92 KB
/
Copy pathFanctrlPlus.Dashboard.page
File metadata and controls
328 lines (284 loc) · 9.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
Menu="Dashboard:0"
Cond="version_compare(parse_ini_file('/etc/unraid-version')['version'],'6.11.9','>')"
---
<?php
$pluginname = "fanctrlplus";
$cfg_path = "/boot/config/plugins/$pluginname";
$cfg_files = glob("$cfg_path/{$pluginname}_*.cfg");
$order_file = "$cfg_path/order.cfg";
$order = [];
$all_cfg = [];
// 获取状态
$status_text = file_exists("/var/run/{$pluginname}.pid") ? "Running" : "Inactive";
$status_color = $status_text === "Running" ? "green-text" : "red-text";
// 先读取 order.cfg 顺序
if (file_exists($order_file)) {
$ini = parse_ini_file($order_file);
$order = array_values($ini);
}
// 1. 先按 order.cfg 顺序添加(只要实际存在)
foreach ($order as $file) {
$path = "$cfg_path/$file";
if (is_file($path)) {
$cfg = parse_ini_file($path);
$cfg['file'] = $file;
$all_cfg[] = $cfg;
}
}
// 2. 把未出现在 order.cfg 的 cfg 文件(包含 _temp_)加进去
$seen = array_flip($order);
foreach ($cfg_files as $path) {
$basename = basename($path);
if (!isset($seen[$basename])) {
$cfg = parse_ini_file($path);
$cfg['file'] = $basename;
$all_cfg[] = $cfg;
}
}
// 3. 构建 HTML row
$fan_rows = "";
foreach ($all_cfg as $cfg) {
$file = $cfg['file'];
$label = $cfg['custom'] ?? $file;
// 跳过未命名的风扇(custom 名为空)
if (empty($cfg['custom'])) continue;
$fan_rows .= <<<ROW
<tr>
<td>
<span class="w26">$label</span>
<span class="w18 fcp-col-temp" data-label="$label">
<span class="fp-tval">--</span>
<span class="fp-origin"></span>
</span>
<span class="w18 fcp-col-rpm" data-label="$label">
<span class="fp-rval">--</span>
/
<span class="fp-pct">--</span>
</span>
<span class="w18 fanctrlplus-fanstatus" data-label="$label">--</span>
<span class="w18">
<span class="fa fa-refresh fanctrlplus-refresh"
data-label="$label"
style="cursor:pointer;font-size:13px;color:var(--blue-800);vertical-align:middle;"
title="Manual Run: Read current temperature and set fan speed immediately"></span>
</span>
</td>
</tr>
ROW;
}
// 样式输出
echo '<link rel="stylesheet" href="/plugins/fanctrlplus/fonts/style.css">' . PHP_EOL;
echo <<<STYLE
<style>
/* ====== 顶部状态(保留原样) ====== */
.fanctrlplus-status{
font-weight: normal;
font-size: 12px;
display: inline-block;
margin-bottom: 6px;
}
.fp-rval, .fp-pct{
min-width: 30px;
display: inline-block;
text-align: center;
}
/* ====== 表头:桌面全称,≤1080px 用短写 ====== */
#fanctrlplus-dashboard .fcp-col-head .mobile{ display:none; }
@media (max-width:1080px){
#fanctrlplus-dashboard .fcp-col-head .full { display:none; }
#fanctrlplus-dashboard .fcp-col-head .mobile{ display:inline; }
}
/* ====== 温度列(新结构)====== */
/* 外层容器:桌面一行排列 */
#fanctrlplus-dashboard .fcp-col-temp{
display:inline-flex; gap:6px; align-items:baseline;
}
/* 数值部分 */
#fanctrlplus-dashboard .fcp-col-temp .fp-tval{
display: inline-block;
min-width: 16px;
text-align: center;
}
/* 单位(兼容旧 */
#fanctrlplus-dashboard .fcp-col-temp{
display:grid;
grid-template-columns: 30px 55px;
}
/* 来源 */
#fanctrlplus-dashboard .fcp-col-temp .fp-origin{
display:inline-block;
min-width:55px;
text-align:center;
font-size:90%;
opacity:.65;
letter-spacing: 1px;
}
/* 无来源时的占位(与来源宽度匹配,避免跳动) */
#fanctrlplus-dashboard .fcp-col-temp .fp-origin-placeholder{
text-align:center;
color:inherit;
}
/* ====== ≤1080px:两行布局,避免 w18 溢出 ====== */
@media (max-width:1080px){
#fanctrlplus-dashboard .fcp-col-temp{
display:block; line-height:1.1;
}
#fanctrlplus-dashboard .fcp-col-temp .fp-tval{
display:inline-block; /* 上行:温度 */
}
#fanctrlplus-dashboard .fcp-col-temp .fp-origin {
display:block; /* 下行:来源 */
font-size:80%;
opacity:.65;
margin-top:2px;
min-width:0;
text-align:left;
}
#fanctrlplus-dashboard .fcp-col-temp .fp-origin-placeholder{
display:block;
min-width:0;
text-align:left;
}
}
</style>
STYLE;
// 输出 tile
$isResponsiveWebgui = version_compare((parse_ini_file('/etc/unraid-version')['version'] ?? '0.0.0'), '7.2.0-beta', '>=');
$tbodyClass = $isResponsiveWebgui ? 'mixed' : 'sortable';
$headerSection = $isResponsiveWebgui
? "<h3 class='tile-header-main'>FanCtrl Plus</h3>\n<span class='fanctrlplus-status $status_color'>Status: $status_text</span>"
: "FanCtrl Plus<br>\n<span class='fanctrlplus-status $status_color'>Status: $status_text</span><br>";
$mytiles[$pluginname]['column2'] = <<<EOT
<tbody id="fanctrlplus-dashboard" class="$tbodyClass" title="FanCtrl Plus">
<tr>
<td>
<span class="tile-header">
<span class="tile-header-left">
<i class="icon-fanctrlplus f32"></i>
<div class="section">
$headerSection
</div>
</span>
<span class="tile-header-right">
<span class="tile-header-right-controls">
<a href="/Settings/fanctrlplus" title="Go to FanCtrl Plus settings">
<i class="fa fa-fw fa-cog control"></i>
</a>
</span>
</span>
</td>
</tr>
<tr class="header">
<td>
<span class="w26">NAME</span>
<span class="w18 fcp-col-head">
<span class="full">TEMP (SOURCE)</span>
<span class="mobile">TEMP</span>
</span>
<span class="w18" style="text-indent:0.3rem;">RPM / PWM%</span>
<span class="w18">STATUS</span>
<span class="w18">RUN</span>
</td>
</tr>
$fan_rows
</tbody>
EOT;
?>
<script>
// 设置温度与来源。支持 *, --,以及无来源时用占位“-”
function setTempCell(label, val, origin) {
const tile = document.getElementById('fanctrlplus-dashboard');
if (!tile) return;
// 保险:label 里若有特殊字符,避免 querySelector 失效
const key = (window.CSS && CSS.escape) ? CSS.escape(label) : String(label).replace(/"/g, '\\"');
const wrap = tile.querySelector(`.fcp-col-temp[data-label="${key}"]`);
if (!wrap) return;
const t = wrap.querySelector('.fp-tval');
const o = wrap.querySelector('.fp-origin');
// —— 温度文本 ——
let show;
if (val === '*') show = '*';
else if (val == null || val === '-' || val === '--') show = '--';
else show = `${val} °C`;
if (t) t.textContent = show;
// —— 来源文本 ——
if (!o) return;
// 规范化 origin:去掉包裹的括号、trim
const oriRaw = (origin ?? '').toString().trim();
const ori = oriRaw.replace(/^$begin:math:text$(.*)$end:math:text$$/, '$1'); // "(Idle)" -> "Idle"
const isEmptyOrigin = ori.length === 0;
const isIdle = /^idle$/i.test(ori);
const isNoTemp = (val === '*' || val === '-' || val === '--' || val == null);
if (isEmptyOrigin) {
o.innerHTML = `<span class="fp-origin-placeholder">-</span>`;
} else if (isIdle && isNoTemp) {
o.innerHTML = `<span class="fp-origin-placeholder">(Idle)</span>`;
} else {
const normalized = /^$begin:math:text$.*$end:math:text$$/.test(oriRaw) ? oriRaw : `(${ori})`;
o.textContent = normalized;
}
}
function updateFanctrlplusTile() {
const tile = document.getElementById("fanctrlplus-dashboard");
if (!tile) return;
fetch("/plugins/fanctrlplus/FanctrlDashboard.php")
.then(res => res.json())
.then(data => {
// 顶部状态
const statusSpan = tile.querySelector(".fanctrlplus-status");
if (statusSpan) {
statusSpan.textContent = `Status: ${data.status}`;
statusSpan.className = "fanctrlplus-status " + (data.status === "Running" ? "green-text" : "red-text");
}
// 行数据(仅新结构)
(data.fans || []).forEach(f => {
setTempCell(f.label, f.temp_raw, f.temp_origin);
const rpmWrap = tile.querySelector(`.fcp-col-rpm[data-label="${f.label}"]`);
const statEl = tile.querySelector(`.fanctrlplus-fanstatus[data-label="${f.label}"]`);
if (rpmWrap) {
const rpmValEl = rpmWrap.querySelector('.fp-rval');
const pctEl = rpmWrap.querySelector('.fp-pct');
if (rpmValEl) rpmValEl.textContent = (f.rpm_val ?? "--");
if (pctEl) pctEl.textContent = (f.percent !== "-" ? f.percent : "--");
}
if (statEl) statEl.innerHTML = (f.status ?? "-");
});
})
.catch(() => {
const statusSpan = tile?.querySelector(".fanctrlplus-status");
if (statusSpan) statusSpan.textContent = "Status: Loading...";
// 仅复位新结构
tile?.querySelectorAll('.fcp-col-temp .fp-tval').forEach(n => n.textContent = '--');
tile?.querySelectorAll('.fcp-col-temp .fp-origin').forEach(n => n.textContent = '');
tile?.querySelectorAll('.fcp-col-rpm .fp-rval').forEach(n => n.textContent = '--');
tile?.querySelectorAll('.fcp-col-rpm .fp-pct').forEach(n => n.textContent = '--%');
tile?.querySelectorAll('.fanctrlplus-fanstatus').forEach(n => n.textContent = '--');
});
}
// 单风扇立即执行 (Run Now)
function refreshSingleFan(custom) {
fetch(`/plugins/fanctrlplus/include/FanctrlLogic.php?op=refresh_single&custom=${encodeURIComponent(custom)}`)
.then(() => setTimeout(updateFanctrlplusTile, 2000)); // 2秒后刷新界面
}
document.addEventListener("DOMContentLoaded", function () {
setTimeout(updateFanctrlplusTile, 200);
setInterval(updateFanctrlplusTile, 5000);
const dashboard = document.getElementById("fanctrlplus-dashboard");
if (dashboard) {
dashboard.addEventListener("click", function(e) {
const btn = e.target.closest('.fanctrlplus-refresh');
if (!btn) return;
const label = btn.getAttribute('data-label');
btn.style.color = '#aaa';
btn.classList.add('fa-spin');
refreshSingleFan(label);
setTimeout(() => {
btn.style.color = 'var(--blue-800)';
btn.classList.remove('fa-spin');
}, 1800);
e.preventDefault();
e.stopPropagation();
});
}
});
</script>