forked from xvrh/chrome_extension.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_memory.dart
65 lines (48 loc) · 1.63 KB
/
system_memory.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
// ignore_for_file: unnecessary_parenthesis
library;
import 'dart:js_util';
import 'src/internal_helpers.dart';
import 'src/js/system_memory.dart' as $js;
import 'system.dart';
export 'src/chrome.dart' show chrome, EventStream;
export 'system.dart' show ChromeSystem, ChromeSystemExtension;
final _systemMemory = ChromeSystemMemory._();
extension ChromeSystemMemoryExtension on ChromeSystem {
/// The `chrome.system.memory` API.
ChromeSystemMemory get memory => _systemMemory;
}
class ChromeSystemMemory {
ChromeSystemMemory._();
bool get isAvailable =>
$js.chrome.systemNullable?.memoryNullable != null && alwaysTrue;
/// Get physical memory information.
Future<MemoryInfo> getInfo() async {
var $res = await promiseToFuture<$js.MemoryInfo>(
$js.chrome.system.memory.getInfo());
return MemoryInfo.fromJS($res);
}
}
class MemoryInfo {
MemoryInfo.fromJS(this._wrapped);
MemoryInfo({
/// The total amount of physical memory capacity, in bytes.
required double capacity,
/// The amount of available capacity, in bytes.
required double availableCapacity,
}) : _wrapped = $js.MemoryInfo(
capacity: capacity,
availableCapacity: availableCapacity,
);
final $js.MemoryInfo _wrapped;
$js.MemoryInfo get toJS => _wrapped;
/// The total amount of physical memory capacity, in bytes.
double get capacity => _wrapped.capacity;
set capacity(double v) {
_wrapped.capacity = v;
}
/// The amount of available capacity, in bytes.
double get availableCapacity => _wrapped.availableCapacity;
set availableCapacity(double v) {
_wrapped.availableCapacity = v;
}
}