-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatsModule.tsx
More file actions
194 lines (174 loc) · 6.57 KB
/
StatsModule.tsx
File metadata and controls
194 lines (174 loc) · 6.57 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
import React, { useState, useEffect } from 'react';
import { useConfig } from '../../context/ConfigContext';
import { SystemInfo } from '../../../shared/types';
const StatsModule: React.FC = () => {
const { showWeather, showBattery } = useConfig();
const [systemInfo, setSystemInfo] = useState<SystemInfo | null>(null);
const [weather, setWeather] = useState({
location: '正在获取位置...',
temperature: 22,
feelsLike: 20,
humidity: 65,
condition: 'PARTLY CLOUDY',
wind: '15 KPH NW',
radiation: 'MINIMAL'
});
const [currentTime, setCurrentTime] = useState(new Date());
// 获取系统信息
useEffect(() => {
const fetchSystemInfo = async () => {
try {
if (window.electronAPI) {
const info = await window.electronAPI.getSystemInfo();
setSystemInfo(info);
}
} catch (error) {
console.error('Failed to fetch system info:', error);
}
};
fetchSystemInfo();
// 定期更新系统信息
const interval = setInterval(fetchSystemInfo, 2000);
return () => clearInterval(interval);
}, []);
// 更新时间
useEffect(() => {
const interval = setInterval(() => {
setCurrentTime(new Date());
}, 1000);
return () => clearInterval(interval);
}, []);
// 格式化日期
const formatDate = (date: Date) => {
const day = date.getDate().toString().padStart(2, '0');
const month = date.toLocaleString('en-US', { month: 'short' }).toUpperCase();
// Fallout风格的年份(当前年份+270年)
const year = date.getFullYear() + 270;
return `${day} ${month} ${year}`;
};
return (
<div className="stats-module">
<h1 style={{ marginBottom: '20px', textTransform: 'uppercase' }}>系统状态</h1>
{/* 时间和日期显示 */}
<div style={{
marginBottom: '30px',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center'
}}>
<div>
<h2 style={{ fontSize: '24px' }}>{currentTime.toLocaleTimeString()}</h2>
<p>{formatDate(currentTime)}</p>
</div>
</div>
{/* 系统信息 */}
<div style={{ marginBottom: '30px' }}>
<h2 style={{ marginBottom: '10px', textTransform: 'uppercase' }}>系统生命体征</h2>
{systemInfo ? (
<div>
{/* CPU负载 */}
<div style={{ marginBottom: '10px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span>CPU负载:</span>
<span>{systemInfo.cpuUsage.toFixed(1)}%</span>
</div>
<div className="progress-bar">
<div
className="progress-bar-fill"
style={{ width: `${systemInfo.cpuUsage}%` }}
></div>
</div>
</div>
{/* 内存使用 */}
<div style={{ marginBottom: '10px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span>内存使用:</span>
<span>{systemInfo.memoryUsage.toFixed(1)}%</span>
</div>
<div className="progress-bar">
<div
className="progress-bar-fill"
style={{ width: `${systemInfo.memoryUsage}%` }}
></div>
</div>
</div>
{/* 存储空间 */}
<div style={{ marginBottom: '10px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span>存储空间:</span>
<span>40% 可用</span>
</div>
<div className="progress-bar">
<div
className="progress-bar-fill"
style={{ width: '60%' }}
></div>
</div>
</div>
{/* 网络活动 */}
<div style={{ marginBottom: '10px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span>网络活动:</span>
<span>上传: 1.5 MB/s | 下载: 25.3 MB/s</span>
</div>
</div>
{/* 电池状态 - 仅在配置启用且设备有电池时显示 */}
{showBattery && (
<div style={{ marginBottom: '10px' }}>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<span>电池状态:</span>
<span>[充电中] 100%</span>
</div>
<div className="progress-bar">
<div
className="progress-bar-fill"
style={{ width: '100%' }}
></div>
</div>
</div>
)}
</div>
) : (
<p>正在获取系统信息...</p>
)}
</div>
{/* 天气信息 - 仅在配置启用时显示 */}
{showWeather && (
<div>
<h2 style={{ marginBottom: '10px', textTransform: 'uppercase' }}>环境扫描器</h2>
<div style={{
border: '1px solid var(--border)',
padding: '15px',
backgroundColor: 'rgba(0, 0, 0, 0.2)'
}}>
<div style={{ marginBottom: '5px' }}>
<span style={{ display: 'inline-block', width: '120px' }}>位置:</span>
<span>{weather.location}</span>
</div>
<div style={{ marginBottom: '5px' }}>
<span style={{ display: 'inline-block', width: '120px' }}>温度:</span>
<span>{weather.temperature}°C (体感: {weather.feelsLike}°C)</span>
</div>
<div style={{ marginBottom: '5px' }}>
<span style={{ display: 'inline-block', width: '120px' }}>湿度:</span>
<span>{weather.humidity}%</span>
</div>
<div style={{ marginBottom: '5px' }}>
<span style={{ display: 'inline-block', width: '120px' }}>天气状况:</span>
<span>{weather.condition}</span>
</div>
<div style={{ marginBottom: '5px' }}>
<span style={{ display: 'inline-block', width: '120px' }}>风力:</span>
<span>{weather.wind}</span>
</div>
<div>
<span style={{ display: 'inline-block', width: '120px' }}>辐射水平:</span>
<span>{weather.radiation}</span>
</div>
</div>
</div>
)}
</div>
);
};
export default StatsModule;