forked from HuakunShen/tauri-plugin-system-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.ts
205 lines (184 loc) · 5.24 KB
/
type.ts
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
import { z } from "zod";
// TODO: verify actual value returned from rust for "Unknown" enum
// export const DiskKind = z.enum(["HDD", "SSD", "Unknown"]);
export const DiskKind = z.union([
z.literal("HDD"),
z.literal("SSD"),
z.object({
Unknown: z.number(),
}),
]);
export type DiskKind = z.infer<typeof DiskKind>;
export const MacAddress = z.number().array().length(6);
export type MacAddress = z.infer<typeof MacAddress>;
export const ProcessStatus = z.union([
z.literal("Idle"),
z.literal("Run"),
z.literal("Sleep"),
z.literal("Stop"),
z.literal("Zombie"),
z.literal("Tracing"),
z.literal("Dead"),
z.literal("Wakekill"),
z.literal("Waking"),
z.literal("Parked"),
z.literal("LockBlocked"),
z.literal("UninterruptibleDiskSleep"),
z.object({
Unknown: z.number(),
}),
]);
export type ProcessStatus = z.infer<typeof ProcessStatus>;
export const DiskUsage = z.object({
total_written_bytes: z.number(),
written_bytes: z.number(),
total_read_bytes: z.number(),
read_bytes: z.number(),
});
export type DiskUsage = z.infer<typeof DiskUsage>;
export const Cpu = z.object({
name: z.string(),
frequency: z.number(),
cpu_usage: z.number(),
vendor_id: z.string(),
brand: z.string(),
});
export type Cpu = z.infer<typeof Cpu>;
export const Disk = z.object({
kind: DiskKind,
name: z.string(),
file_system: z.string(),
mount_point: z.string(),
total_space: z.number(),
available_space: z.number(),
is_removable: z.boolean(),
});
export type Disk = z.infer<typeof Disk>;
export const Network = z.object({
interface_name: z.string(),
received: z.number(),
total_received: z.number(),
transmitted: z.number(),
total_transmitted: z.number(),
packets_received: z.number(),
total_packets_received: z.number(),
packets_transmitted: z.number(),
total_packets_transmitted: z.number(),
errors_on_received: z.number(),
total_errors_on_received: z.number(),
errors_on_transmitted: z.number(),
total_errors_on_transmitted: z.number(),
mac_address: z.number().array(),
mac_address_str: z.string(),
});
export type Network = z.infer<typeof Network>;
export const Component = z.object({
temperature: z.number(),
max: z.number(),
critical: z.number().nullable(),
label: z.string(),
});
export type Component = z.infer<typeof Component>;
export const Process = z.object({
name: z.string(),
cmd: z.string().array(),
exe: z.string().nullable(),
pid: z.number(),
environ: z.string().array(),
cwd: z.string().nullable(),
root: z.string().nullable(),
memory: z.number(),
virtual_memory: z.number(),
parent: z.number().nullable(),
status: ProcessStatus,
start_time: z.number(),
run_time: z.number(),
cpu_usage: z.number(),
disk_usage: DiskUsage,
user_id: z.string().nullable(),
effective_user_id: z.string().nullable(),
group_id: z.string().nullable(),
effective_group_id: z.string().nullable(),
session_id: z.number().nullable(),
});
export type Process = z.infer<typeof Process>;
// aggregate info
export const StaticInfo = z.object({
hostname: z.string().nullable(),
kernel_version: z.string().nullable(),
os_version: z.string().nullable(),
name: z.string().nullable(),
});
export type StaticInfo = z.infer<typeof StaticInfo>;
export const MemoryInfo = z.object({
total_memory: z.number(),
used_memory: z.number(),
total_swap: z.number(),
used_swap: z.number(),
});
export type MemoryInfo = z.infer<typeof MemoryInfo>;
export const CpuInfo = z.object({
cpus: Cpu.array(),
cpu_count: z.number(),
});
export type CpuInfo = z.infer<typeof CpuInfo>;
export const AllSystemInfo = z.object({
hostname: z.string().nullable(),
kernel_version: z.string().nullable(),
os_version: z.string().nullable(),
name: z.string().nullable(),
total_memory: z.number(),
used_memory: z.number(),
total_swap: z.number(),
used_swap: z.number(),
cpus: Cpu.array(),
cpu_count: z.number(),
disks: Disk.array(),
networks: Network.array(),
components: Component.array(),
processes: Process.array(),
});
export type AllSystemInfo = z.infer<typeof AllSystemInfo>;
export const BatteryState = z.enum([
"Unknown",
"Charging",
"Discharging",
"Empty",
"Full",
]);
export type BatteryState = z.infer<typeof BatteryState>;
export const BatteryTechnology = z.enum([
"Unknown",
"LithiumIon",
"LeadAcid",
"LithiumPolymer",
"NickelMetalHydride",
"NickelCadmium",
"NickelZinc",
"LithiumIronPhosphate",
"RechargeableAlkalineManganese",
]);
export type BatteryTechnology = z.infer<typeof BatteryTechnology>;
export const Battery = z.object({
state_of_charge: z.number(),
energy: z.number(),
energy_full: z.number(),
energy_full_design: z.number(),
energy_rate: z.number(),
voltage: z.number(),
state_of_health: z.number(),
state: BatteryState,
technology: BatteryTechnology,
temperature_kelin: z.number().nullable(),
temperature_celsius: z.number().nullable(),
temperature_fahrenheit: z.number().nullable(),
cycle_count: z.number().nullable(),
vendor: z.string().nullable(),
model: z.string().nullable(),
serial_number: z.string().nullable(),
time_to_full: z.number().nullable(),
time_to_empty: z.number().nullable(),
});
export type Battery = z.infer<typeof Battery>;
export const Batteries = Battery.array();
export type Batteries = z.infer<typeof Batteries>;