Skip to content

Commit

Permalink
Corrected getFreeDiskStorageSync and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
robertherber authored and mikehardy committed Nov 10, 2019
1 parent 3edb258 commit 78cc5f9
Showing 1 changed file with 57 additions and 54 deletions.
111 changes: 57 additions & 54 deletions src/web/index.js
Expand Up @@ -6,6 +6,43 @@ let isBatteryCharging = false,
batteryLevel = -1,
powerState = {};

const getMaxMemorySync = () => {
if (window.performance && window.performance.memory) {
return window.performance.memory.jsHeapSizeLimit;
}
return -1;
};

const getInstallReferrerSync = () => {
return document.referrer;
};

const isAirplaneModeSync = () => {
return !!navigator.onLine;
};

const getUserAgentSync = () => {
return window.navigator.userAgent;
};

const isLocationEnabledSync = () => {
return !!navigator.geolocation;
};

const getTotalMemorySync = () => {
if (navigator.deviceMemory) {
return navigator.deviceMemory * 1000000000;
}
return -1;
};

const getUsedMemorySync = () => {
if (window.performance && window.performance.memory) {
return window.performance.memory.usedJSHeapSize;
}
return -1;
};

const getPowerState = battery => {
const { level, charging, chargingtime, dischargingtime } = battery;

Expand Down Expand Up @@ -47,7 +84,7 @@ const init = async () => {
}
};

const getBaseOs = () => {
const getBaseOsSync = () => {
const userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
Expand Down Expand Up @@ -77,17 +114,13 @@ init();
*/
module.exports = {
getInstallReferrer: async () => {
return document.referrer;
},
getInstallReferrerSync: () => {
return document.referrer;
return getInstallReferrerSync();
},
getInstallReferrerSync,
getUserAgent: async () => {
return window.navigator.userAgent;
},
getUserAgentSync: () => {
return window.navigator.userAgent;
return getUserAgentSync();
},
getUserAgentSync,
isBatteryCharging: async () => {
if (navigator.getBattery) {
const battery = await navigator.getBattery();
Expand Down Expand Up @@ -122,23 +155,17 @@ module.exports = {
return batteryLevel;
},
isLocationEnabled: async () => {
return !!navigator.geolocation;
},
isLocationEnabledSync: () => {
return !!navigator.geolocation;
return isLocationEnabledSync();
},
isLocationEnabledSync,
isAirplaneMode: async () => {
return !!navigator.onLine;
},
isAirplaneModeSync: () => {
return !!navigator.onLine;
return isAirplaneModeSync();
},
isAirplaneModeSync,
getBaseOs: async () => {
return getBaseOs();
},
getBaseOsSync: () => {
return getBaseOs();
return getBaseOsSync();
},
getBaseOsSync,
getTotalDiskCapacity: async () => {
if (navigator.storage && navigator.storage.estimate) {
const { quota } = await navigator.storage.estimate();
Expand All @@ -160,47 +187,23 @@ module.exports = {
return -1;
},
getFreeDiskStorageSync: () => {
if (window.performance && window.performance.memory) {
return window.performance.memory.usedJSHeapSize;
}
console.log(
'[react-native-device-info] getFreeDiskStorageSync not supported - please use getFreeDiskStorage'
);
return -1;
},
getMaxMemory: async () => {
if (window.performance && window.performance.memory) {
return window.performance.memory.jsHeapSizeLimit;
}
return -1;
},
getMaxMemorySync: () => {
if (window.performance && window.performance.memory) {
return window.performance.memory.jsHeapSizeLimit;
}
return -1;
return getMaxMemorySync();
},
getMaxMemorySync,
getUsedMemory: async () => {
if (window.performance && window.performance.memory) {
return window.performance.memory.usedJSHeapSize;
}
return -1;
},
getUsedMemorySync: () => {
if (window.performance && window.performance.memory) {
return window.performance.memory.usedJSHeapSize;
}
return -1;
return getUsedMemorySync();
},
getUsedMemorySync,
getTotalMemory: async () => {
if (navigator.deviceMemory) {
return navigator.deviceMemory * 1000000000;
}
return -1;
},
getTotalMemorySync: () => {
if (navigator.deviceMemory) {
return navigator.deviceMemory * 1000000000;
}
return -1;
return getTotalMemorySync();
},
getTotalMemorySync,
getPowerState: async () => {
if (navigator.getBattery) {
const battery = await navigator.getBattery();
Expand Down

0 comments on commit 78cc5f9

Please sign in to comment.