forked from flutter/devtools
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_logging_preferences.dart
More file actions
94 lines (80 loc) · 2.74 KB
/
_logging_preferences.dart
File metadata and controls
94 lines (80 loc) · 2.74 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
// Copyright 2024 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
part of 'preferences.dart';
class LoggingPreferencesController extends DisposableController
with AutoDisposeControllerMixin {
final retentionLimitTitle = 'Limit for the number of logs retained.';
/// The number of logs to retain on the logging table.
final retentionLimit = ValueNotifier<int>(_defaultRetentionLimit);
/// The [LoggingDetailsFormat] to use when displaying a log in the log details
/// view.
final detailsFormat = ValueNotifier<LoggingDetailsFormat>(
_defaultDetailsFormat,
);
/// The active filter tag for the logging screen.
///
/// This value caches the most recent filter settings.
final filterTag = ValueNotifier<String>('');
static const _defaultRetentionLimit = 5000;
static const _defaultDetailsFormat = LoggingDetailsFormat.text;
static const _retentionLimitStorageId = 'logging.retentionLimit';
@visibleForTesting
static const detailsFormatStorageId = 'logging.detailsFormat';
@visibleForTesting
static const filterStorageId = 'logging.filter';
@override
Future<void> init() async {
retentionLimit.value =
int.tryParse(await storage.getValue(_retentionLimitStorageId) ?? '') ??
_defaultRetentionLimit;
addAutoDisposeListener(retentionLimit, () {
safeUnawaited(
storage.setValue(
_retentionLimitStorageId,
retentionLimit.value.toString(),
),
);
ga.select(
gac.logging,
gac.LoggingEvents.changeRetentionLimit.name,
value: retentionLimit.value,
);
});
final detailsFormatValueFromStorage = await storage.getValue(
detailsFormatStorageId,
);
detailsFormat.value =
LoggingDetailsFormat.values.firstWhereOrNull(
(value) => detailsFormatValueFromStorage == value.name,
) ??
_defaultDetailsFormat;
addAutoDisposeListener(detailsFormat, () {
safeUnawaited(
storage.setValue(detailsFormatStorageId, detailsFormat.value.name),
);
ga.select(
gac.logging,
gac.LoggingEvents.changeDetailsFormat.name,
value: detailsFormat.value.index,
);
});
filterTag.value = await storage.getValue(filterStorageId) ?? '';
addAutoDisposeListener(
filterTag,
() => storage.setValue(filterStorageId, filterTag.value),
);
}
}
enum LoggingDetailsFormat {
json,
text;
LoggingDetailsFormat opposite() {
switch (this) {
case LoggingDetailsFormat.json:
return LoggingDetailsFormat.text;
case LoggingDetailsFormat.text:
return LoggingDetailsFormat.json;
}
}
}