VulpesOS/assets/webapps/system.gaiamobile.org/js/feature_detector.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

65 lines
1.5 KiB
JavaScript

/* global BaseModule */
'use strict';
(function(exports) {
/**
* This is the feature detector module of the system app.
* It is responsible to retrieve device specific information.
*/
var FeatureDetector = function() {
};
FeatureDetector.SERVICES = [
'getDeviceMemory'
];
FeatureDetector.STATES = [
'getDeviceType'
];
BaseModule.create(FeatureDetector, {
name: 'FeatureDetector',
deviceType: 'phone',
_deviceMemoryPromise: null,
_start: function() {
this._getDeviceType();
this._getDeviceMemory();
},
_stop: function() {
this.deviceType = null;
this._deviceMemoryPromise = null;
},
_getDeviceType: function() {
// `_GAIA_DEVICE_TYPE_` is a placeholder and will be replaced by real
// device type in build time, `system/build/build.js` does the trick.
this.deviceType = 'phone';
},
getDeviceType: function() {
return this.deviceType;
},
_getDeviceMemory: function() {
if ('getFeature' in navigator) {
this._deviceMemoryPromise =
navigator.getFeature('hardware.memory').catch(() => {
this.error('Failed to retrieve total memory of the device.');
// Return the failsafe value.
return 0;
});
} else {
this.error('navigator.getFeature is not available.');
this._deviceMemoryPromise = Promise.resolve(0);
}
},
getDeviceMemory: function() {
return this._deviceMemoryPromise;
}
});
}(window));