manager.dart
2.89 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
import 'package:auto_track/auto_track/config/queue.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/widgets.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'config.dart';
class AutoTrackConfigManager {
static final AutoTrackConfigManager instance = AutoTrackConfigManager._();
AutoTrackConfigManager._() {
PackageInfo.fromPlatform().then((value) => _appVersion = value.version);
DeviceInfoPlugin().deviceInfo.then((value) => _deviceInfo = value.data);
}
String _appVersion = '';
String get appVersion => _appVersion;
Map<String, dynamic> _deviceInfo = {};
Map<String, dynamic> get deviceInfo => _deviceInfo;
AutoTrackConfig _config = AutoTrackConfig();
AutoTrackConfig get config => _config;
bool _autoTrackEnable = false;
bool get autoTrackEnable => _autoTrackEnable;
void updateConfig(AutoTrackConfig config) {
_config = config;
if (config.enableUpload) {
AutoTrackQueue.instance.start();
} else {
AutoTrackQueue.instance.stop();
}
}
void updateUserId(String userId) {
_config.userId = userId;
}
void updatePageConfigs(List<AutoTrackPageConfig> pageConfigs) {
_config.pageConfigs = pageConfigs;
}
void updateIgnoreElementKeys(List<Key> ignoreElementKeys) {
_config.ignoreElementKeys = ignoreElementKeys;
}
void updateIgnoreElementStringKeys(List<String> ignoreElementStringKeys) {
_config.ignoreElementStringKeys = ignoreElementStringKeys;
}
void enablePageView(bool enable) {
_config.enablePageView = enable;
}
void enablePageLeave(bool enable) {
_config.enablePageLeave = enable;
}
void enableClick(bool enable) {
_config.enableClick = enable;
}
void enableAutoTrack(bool enable) {
_autoTrackEnable = enable;
}
void enableUpload(bool enable) {
_config.enableUpload = enable;
if (enable) {
AutoTrackQueue.instance.start();
} else {
AutoTrackQueue.instance.stop();
}
}
List<AutoTrackPageConfig> get pageConfigs => _config.pageConfigs;
bool get useCustomRoute => _config.useCustomRoute;
AutoTrackPageConfig getPageConfig(Widget pageWidget) {
return _config.pageConfigs.firstWhere(
(pageConfig) => pageConfig.isPageWidget!(pageWidget),
orElse: () => AutoTrackPageConfig()
);
}
Set<Key> getIgnoreElementKeySet() => _config.getIgnoreElementKeySet();
Set<String> getIgnoreElementStringKeySet() => _config.getIgnoreElementStringKeySet();
bool isIgnoreElement(Key? key) {
if (key == null) {
return false;
}
if (getIgnoreElementKeySet().contains(key)) {
return true;
}
if (getIgnoreElementStringKeySet().contains(key.toString())) {
return true;
}
return false;
}
bool get pageViewEnabled => _config.enablePageView;
bool get pageLeaveEnable => _config.enablePageLeave;
bool get clickEnable => _config.enableClick;
}