/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** * Returns an object containing the user preference of displayed devices. * * @return {Object} containing two Sets: * - added: Names of the devices that were explicitly enabled by the user * - removed: Names of the devices that were explicitly removed by the user
*/ function loadPreferredDevices() { const preferredDevices = {
added: new Set(),
removed: new Set(),
};
if (Services.prefs.prefHasUserValue(DISPLAYED_DEVICES_PREF)) { try {
let savedData = Services.prefs.getStringPref(DISPLAYED_DEVICES_PREF);
savedData = JSON.parse(savedData); if (savedData.added && savedData.removed) {
preferredDevices.added = new Set(savedData.added);
preferredDevices.removed = new Set(savedData.removed);
}
} catch (e) {
console.error(e);
}
}
return preferredDevices;
}
/** * Update the displayed device list preference with the given device list. * * @param {Object} containing two Sets: * - added: Names of the devices that were explicitly enabled by the user * - removed: Names of the devices that were explicitly removed by the user
*/ function updatePreferredDevices(devices) {
let devicesToSave = {
added: Array.from(devices.added),
removed: Array.from(devices.removed),
};
devicesToSave = JSON.stringify(devicesToSave);
Services.prefs.setStringPref(DISPLAYED_DEVICES_PREF, devicesToSave);
}
module.exports = { // This function is only exported for testing purposes
_loadPreferredDevices: loadPreferredDevices,
editCustomDevice(viewport, oldDevice, newDevice) { return async function ({ dispatch }) { // Edit custom device in storage
await editDevice(oldDevice, newDevice, "custom"); // Notify the window that the device should be updated in the device selector.
post(window, {
type: "change-device",
device: newDevice,
viewport,
});
// Update UI if the device is selected. if (viewport) {
dispatch(changeUserAgent(newDevice.userAgent));
dispatch(toggleTouchSimulation(newDevice.touch));
}
for (const [type, devices] of deviceByTypes.entries()) {
dispatch(module.exports.addDeviceType(type)); for (const device of devices) { if (device.os == "fxos") { continue;
}
// Add an empty "custom" type if it doesn't exist in device storage if (!deviceByTypes.has("custom")) {
dispatch(module.exports.addDeviceType("custom"));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.