-
Notifications
You must be signed in to change notification settings - Fork 62
GPII-228 Capture Settings Backend (Snapshotter 2018) #616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 60 commits
f846454
000b33c
e36f564
179e705
eb78e33
04f4e0a
b45079c
fa8a2fb
526d545
25ac4d4
4516c89
1764ef9
2ef4b41
1c05b52
3c55217
29a2708
f30a253
cd8127b
eba8606
179c7e1
b94f137
c727f64
4aba301
db831bb
f484faf
b79d476
b26a588
38bea00
8dec2c5
eb54bb8
d594966
0131b23
f562fe8
17ce607
ec7cb2f
f32a13d
e15f44d
1b636f7
edd5160
6b0416d
511e08b
adcf338
0fd86ac
49e4a38
dd53284
3e70229
2017627
98e56d4
2b3f8e9
caa6508
4b167f8
146119b
2eb479f
e710078
382c51f
41b100d
53ae908
b71918f
97b5f82
5c985d0
3834082
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| /** | ||
| * 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": { | ||
sgithens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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": { | ||
| func: "{that}.captureSystemSettings", | ||
| args: ["{arguments}.0", "{arguments}.1"], | ||
| 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", {}, "{arguments}.0"] // options | ||
|
||
| }, | ||
| captureSystemSettings: { | ||
| funcName: "gpii.flowManager.capture.captureSystemSettings", | ||
| args: ["{lifecycleManager}.read", "{arguments}.0", "{arguments}.1"] // solutionsRegistryEntries, options | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * Invoker `{gpii.flowManager.capture}.getSystemSettingsCapture` | ||
| * | ||
| * @function | ||
| * @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 {Event} onCaptureSettingsForCurrentDevice - The transforming promise chain | ||
| * @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) { | ||
sgithens marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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) { | ||
sgithens marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| togo[key][settingId] = value; | ||
| }); | ||
| }); | ||
| }); | ||
| return togo; | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.