/
info_model.dart
76 lines (61 loc) · 2.14 KB
/
info_model.dart
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
import 'dart:ffi';
import 'dart:io';
import 'package:linux_system_info/linux_system_info.dart';
import 'package:safe_change_notifier/safe_change_notifier.dart';
import 'package:udisks/udisks.dart';
import 'hostname_service.dart';
class InfoModel extends SafeChangeNotifier {
InfoModel(
[HostnameService? hostnameService,
UDisksClient? uDisksClient,
List<Cpu>? cpus,
SystemInfo? systemInfo,
MemInfo? memInfo,
GnomeInfo? gnomeInfo])
: _hostnameService = hostnameService ?? HostnameService(),
_uDisksClient = uDisksClient ?? UDisksClient(),
_cpus = cpus ?? CpuInfo.getProcessors(),
_systemInfo = systemInfo ?? SystemInfo(),
_memInfo = memInfo ?? MemInfo(),
_gnomeInfo = gnomeInfo ?? GnomeInfo();
final HostnameService _hostnameService;
final UDisksClient _uDisksClient;
final List<Cpu> _cpus;
final SystemInfo _systemInfo;
final MemInfo _memInfo;
final GnomeInfo _gnomeInfo;
String _gpuName = '';
int? _diskCapacity;
Future<void> init() async {
await _hostnameService.init();
await GpuInfo.load().then((gpus) {
_gpuName = gpus.first.model;
});
await _uDisksClient.connect().then((value) {
_diskCapacity =
_uDisksClient.drives.fold<int>(0, (sum, drive) => sum + drive.size);
});
notifyListeners();
}
String get hostname => _hostnameService.hostname;
String get staticHostname => _hostnameService.staticHostname;
void setHostname(String hostname) {
_hostnameService.setHostname(hostname).then((_) => notifyListeners());
}
String get osName => _systemInfo.os_name;
String get osVersion => _systemInfo.os_version;
int get osType => sizeOf<IntPtr>() * 8;
String get processorName => _cpus[0].model_name;
int get processorCount => _cpus.length + 1;
int get memory => _memInfo.mem_total_gb;
String get graphics => _gpuName;
int? get diskCapacity => _diskCapacity;
String get gnomeVersion => _gnomeInfo.version;
String get windowServer => Platform.environment['XDG_SESSION_TYPE'] ?? '';
@override
void dispose() {
_hostnameService.dispose();
_uDisksClient.close();
super.dispose();
}
}