manager.dart
2.45 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
import 'package:auto_track/auto_track/config/queue.dart';
import 'package:flutter/widgets.dart';
import 'config.dart';
class AutoTrackConfigManager {
static final AutoTrackConfigManager instance = AutoTrackConfigManager._();
AutoTrackConfigManager._();
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;
}