forked from GPII/universal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCapture.js
More file actions
executable file
·200 lines (193 loc) · 7.35 KB
/
Capture.js
File metadata and controls
executable file
·200 lines (193 loc) · 7.35 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* GPII Capture Component
*
* Copyright 2020 Raising the Floor - International
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/gpii/universal/LICENSE.txt
*/
"use strict";
var fluid = require("infusion"),
gpii = fluid.registerNamespace("gpii");
fluid.defaults("gpii.flowManager.capture", {
gradeNames: ["fluid.component"],
events: {
// Pseudoevents for transforming promise chains to fetch the solutions on the current device
// and capture the settings for the device.
onSolutionsForCurrentDevice: null,
onCaptureSettingsForCurrentDevice: null
},
listeners: {
// Begin declaration of Promise Chain for onSolutionsForCurrentDevice
"onSolutionsForCurrentDevice.getDeviceContextPromise": {
funcName: "gpii.lifecycleManager.getDeviceContextPromise",
args: ["{flowManager}.deviceReporter"],
priority: "first"
},
"onSolutionsForCurrentDevice.getSolutions": {
funcName: "gpii.flowManager.getSolutions",
args: [ "{flowManager}.solutionsRegistryDataSource", "{arguments}.0"],
priority: "after:getDeviceContextPromise"
},
"onSolutionsForCurrentDevice.solutionsRegistryEntriesToPromise": {
funcName: "fluid.toPromise",
args: ["{arguments}.0.solutionsRegistryEntries"],
priority: "after:getSolutions"
},
// Begin declaration of Promise Chain for onCaptureSettingsForCurrentDevice
"onCaptureSettingsForCurrentDevice.getInstalledSolutionsForCurrentDevice": {
func: "{that}.getInstalledSolutionsForCurrentDevice",
priority: "first"
},
"onCaptureSettingsForCurrentDevice.captureSystemSettings": {
funcName: "gpii.flowManager.capture.captureSystemSettings",
args: ["{lifecycleManager}.read", "{arguments}.0", "{arguments}.1"], // solutionsRegistryEntries, options
priority: "after:getInstalledSolutionsForCurrentDevice"
},
"onCaptureSettingsForCurrentDevice.formatRawCapturedSettings": {
func: "gpii.flowManager.capture.formatRawCapturedSettings",
args: ["{arguments}.0"],
priority: "after:captureSystemSettings"
}
},
invokers: {
getInstalledSolutionsForCurrentDevice: {
funcName: "fluid.promise.fireTransformEvent",
args: ["{that}.events.onSolutionsForCurrentDevice"]
},
getSystemSettingsCapture: {
funcName: "fluid.promise.fireTransformEvent",
args: ["{that}.events.onCaptureSettingsForCurrentDevice", null, "{arguments}.0"] // options
}
}
});
/**
* Invoker `{gpii.flowManager.capture}.getInstalledSolutionsForCurrentDevice`
*
* @method
* @name {gpii.flowManager.capture}.getInstalledSolutionsForCurrentDevice
*
* This invoker method will return the solution registry entries, in their usual json format,
* that are available on the current device.
*
* @return {Promise} A promise resolved with an object of solutions registry entries available on the
* current device. As with the solutions registry itself, these are keyed by the solution ID.
*/
/**
* Invoker `{gpii.flowManager.capture}.getSystemSettingsCapture`
*
* @method
* @name {gpii.flowManager.capture}.getSystemSettingsCapture
*
* This main API entry point for capturing settings from a system or computer. This captures
* the actual settings on the device, so it assumed to be running in a local untrusted flow
* manager.
*
* @param {Object} options - Options for this chain.
* @param {Array} options.solutionsList - An array of solution IDs to filter by when
* retreiving settings. If this option is not included, all available settings will be
* returned. ex: `["com.microsoft.windows.mouseSettings", "com.freedomscientific.jaws"]`.
* @return {Promise} A promise resolved with the payload of captured system settings.
*/
/**
* Runs through all the solutions currently available on the system, pulls the current
* setting for each supportedSetting and returns them in an object. Primary use case
* is for backing Capture tools that would allow a user to set up their GPII profile
* starting with the current settings for their applications on the local machine.
*
* @param {Function|gpii.lifecycleManager.read} readSettingsFunc - lifecycleManager.read (or suitable implementation),
* that takes solution registry entries, reads their current values on the device, and returns a promise resolved to
* them.
* @param {Object} solutions - Solutions registry entries for solutions available on the current machine.
* @param {Object} options - Extra options for processing.
* @param {Array} options.solutionsList - If provided, only solutions in this list of `solutionsID`s will
* be captured. Example:
*
* '''json
* ["com.microsoft.windows.cursors", "com.freedomscientific.jaws"]
* '''
* @return {fluid.promise} Returns a promise resolving with the entire system settings capture.
*/
gpii.flowManager.capture.captureSystemSettings = function (readSettingsFunc, solutions, options) {
var solutionsToFetch = fluid.copy(solutions);
if (options.solutionsList) {
fluid.remove_if(solutionsToFetch, function (solution, solutionID) {
return !options.solutionsList.includes(solutionID);
});
}
return readSettingsFunc(solutionsToFetch);
};
/**
* The raw return payload from the capture promise sequence looks like:
* '''json
* [
* {
* "fakemag1": [
* {
* "settings": {
* "magnification": 2
* }
* }
* ]
* },
* {
* "fakemag1": [
* {
* "settings": {
* "invert": true
* }
* }
* ]
* },
* {
* "fakemag2": [
* {
* "settings": {
* "magnification": 2,
* "invert": true
* }
* }
* ]
* }
* ]
* '''
*
* and we want:
* '''json
* {
* "fakemag1": {
* "magnification": 2,
* "invert": true
* },
* "fakemag2": {
* "magnification": 2,
* "invert": true
* }
* }
* '''
*
* @param {Object} data - The raw captured data.
* @return {Object} Returns a new payload with collapsed data, and multiple settings handler
* results for the same solution merged together.
*/
gpii.flowManager.capture.formatRawCapturedSettings = function (data) {
var togo = {};
fluid.each(data, function (sequenceItem) {
if (sequenceItem.isError) {
fluid.log("Error capturing settings for: ", sequenceItem);
return;
}
fluid.each(sequenceItem, function (item, key) {
if (!togo[key]) {
togo[key] = {};
}
fluid.each(fluid.get(item, [0, "settings"]), function (value, settingId) {
togo[key][settingId] = value;
});
});
});
return togo;
};