Skip to content

Commit

Permalink
Merge pull request #1041 from JGreenlee/fix-appstatus-checks
Browse files Browse the repository at this point in the history
Fixes for End of Sept RC
  • Loading branch information
shankari authored Sep 28, 2023
2 parents c190794 + e5b2834 commit 0f7caef
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
51 changes: 25 additions & 26 deletions www/js/control/AppStatusModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//component to view and manage permission settings
import React, { useState, useEffect, useMemo } from "react";
import React, { useState, useEffect, useMemo, useRef } from "react";
import { Modal, useWindowDimensions, ScrollView } from "react-native";
import { Dialog, Button, Text, useTheme } from 'react-native-paper';
import { useTranslation } from "react-i18next";
Expand All @@ -16,8 +16,8 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
const { appConfig, loading } = useAppConfig();

const { height: windowHeight } = useWindowDimensions();
const [osver, setOsver] = useState(0);
const [platform, setPlatform] = useState<string>("");
const osver = useRef(0);
const platform = useRef<string>("");

const [error, setError] = useState<string>("");
const [errorVis, setErrorVis] = useState<boolean>(false);
Expand All @@ -31,10 +31,12 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
let iconMap = (statusState) => statusState ? "check-circle-outline" : "alpha-x-circle-outline";
let colorMap = (statusState) => statusState ? colors.success : colors.danger;

const overallStatus = useMemo(() => {
const overallStatus = useMemo<boolean|undefined>(() => {
let status = true;
if (!checkList?.length) return undefined; // if checks not loaded yet, status is undetermined
checkList.forEach((lc) => {
if(!lc.statusState){
console.debug('check in permission status for ' + lc.name + ':', lc.statusState);
if (lc.statusState === false) {
status = false;
}
})
Expand Down Expand Up @@ -96,32 +98,30 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
return checkOrFix(locPermissionsCheck, window['cordova'].plugins.BEMDataCollection.isValidLocationPermissions, false);
};
var androidSettingsDescTag = "intro.appstatus.locsettings.description.android-gte-9";
if (osver < 9) {
if (osver.current < 9) {
androidSettingsDescTag = "intro.appstatus.locsettings.description.android-lt-9";
}
var androidPermDescTag = "intro.appstatus.locperms.description.android-gte-12";
if(osver < 6) {
if(osver.current < 6) {
androidPermDescTag = 'intro.appstatus.locperms.description.android-lt-6';
} else if (osver < 10) {
} else if (osver.current < 10) {
androidPermDescTag = "intro.appstatus.locperms.description.android-6-9";
} else if (osver < 11) {
} else if (osver.current < 11) {
androidPermDescTag= "intro.appstatus.locperms.description.android-10";
} else if (osver < 12) {
} else if (osver.current < 12) {
androidPermDescTag= "intro.appstatus.locperms.description.android-11";
}
console.log("description tags are "+androidSettingsDescTag+" "+androidPermDescTag);
// location settings
let locSettingsCheck = {
name: t("intro.appstatus.locsettings.name"),
desc: t(androidSettingsDescTag),
statusState: false,
fix: fixSettings,
refresh: checkSettings
}
let locPermissionsCheck = {
name: t("intro.appstatus.locperms.name"),
desc: t(androidPermDescTag),
statusState: false,
fix: fixPerms,
refresh: checkPerms
}
Expand Down Expand Up @@ -153,22 +153,20 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
};
var iOSSettingsDescTag = "intro.appstatus.locsettings.description.ios";
var iOSPermDescTag = "intro.appstatus.locperms.description.ios-gte-13";
if(osver < 13) {
if(osver.current < 13) {
iOSPermDescTag = 'intro.appstatus.locperms.description.ios-lt-13';
}
console.log("description tags are "+iOSSettingsDescTag+" "+iOSPermDescTag);

const locSettingsCheck = {
name: t("intro.appstatus.locsettings.name"),
desc: t(iOSSettingsDescTag),
statusState: false,
fix: fixSettings,
refresh: checkSettings
};
const locPermissionsCheck = {
name: t("intro.appstatus.locperms.name"),
desc: t(iOSPermDescTag),
statusState: false,
fix: fixPerms,
refresh: checkPerms
};
Expand All @@ -178,7 +176,7 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
}

function setupAndroidFitnessChecks() {
if(osver >= 10){
if(osver.current >= 10){
let fixPerms = function() {
console.log("fix and refresh fitness permissions");
return checkOrFix(fitnessPermissionsCheck, window['cordova'].plugins.BEMDataCollection.fixFitnessPermissions,
Expand Down Expand Up @@ -269,10 +267,10 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
false);
};
var androidUnusedDescTag = "intro.appstatus.unusedapprestrict.description.android-disable-gte-13";
if (osver == 12) {
if (osver.current == 12) {
androidUnusedDescTag= "intro.appstatus.unusedapprestrict.description.android-disable-12";
}
else if (osver < 12) {
else if (osver.current < 12) {
androidUnusedDescTag= "intro.appstatus.unusedapprestrict.description.android-disable-lt-12";
}
let unusedAppsUnrestrictedCheck = {
Expand All @@ -297,9 +295,9 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {

let overallFitnessName = t('intro.appstatus.overall-fitness-name-android');
let locExplanation = t('intro.appstatus.overall-loc-description');
if(platform == "ios") {
if(platform.current == "ios") {
overallFitnessName = t('intro.appstatus.overall-fitness-name-ios');
if(osver < 13) {
if(osver.current < 13) {
locExplanation = (t("intro.permissions.locationPermExplanation-ios-lt-13"));
} else {
locExplanation = (t("intro.permissions.locationPermExplanation-ios-gte-13"));
Expand All @@ -318,12 +316,13 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
}

function createChecklist(){
if(platform == "android") {
console.debug("setting up checks, platform is " + platform.current + "and osver is " + osver.current);
if(platform.current == "android") {
setupAndroidLocChecks();
setupAndroidFitnessChecks();
setupAndroidNotificationChecks();
setupAndroidBackgroundRestrictionChecks();
} else if (platform == "ios") {
} else if (platform.current == "ios") {
setupIOSLocChecks();
setupIOSFitnessChecks();
setupAndroidNotificationChecks();
Expand Down Expand Up @@ -371,16 +370,16 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
//load when ready
useEffect(() => {
if (appConfig && window['device']?.platform) {
setPlatform(window['device'].platform.toLowerCase());
setOsver(window['device'].version.split(".")[0]);
platform.current = window['device'].platform.toLowerCase();
osver.current = window['device'].version.split(".")[0];

if(!haveSetText)
{
//window.appStatusModalOpened = false;
setupPermissionText();
setHaveSetText(true);
}
else{
if(!checkList || checkList.length == 0) {
console.log("setting up permissions");
createChecklist();
}
Expand Down Expand Up @@ -443,4 +442,4 @@ const AppStatusModal = ({permitVis, setPermitVis}) => {
)
}

export default AppStatusModal;
export default AppStatusModal;
31 changes: 16 additions & 15 deletions www/js/control/ControlCollectionHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ export async function isMediumAccuracy() {
return undefined; // config not loaded when loading ui, set default as false
} else {
var v = await accuracy2String(config);
if (window.cordova.platformId == 'ios') {
console.log("window platform is", window['cordova'].platformId);
if (window['cordova'].platformId == 'ios') {
return v != "kCLLocationAccuracyBestForNavigation" && v != "kCLLocationAccuracyBest" && v != "kCLLocationAccuracyTenMeters";
} else if (window.cordova.platformId == 'android') {
} else if (window['cordova'].platformId == 'android') {
return v != "PRIORITY_HIGH_ACCURACY";
} else {
window.alert("Emission does not support this platform");
Expand All @@ -62,15 +63,15 @@ export async function helperToggleLowAccuracy() {
let accuracyOptions = await getAccuracyOptions();
let medium = await isMediumAccuracy();
if (medium) {
if (window.cordova.platformId == 'ios') {
if (window['cordova'].platformId == 'ios') {
tempConfig.accuracy = accuracyOptions["kCLLocationAccuracyBest"];
} else if (window.cordova.platformId == 'android') {
tempConfig.accuracy = cch.accuracyOptions["PRIORITY_HIGH_ACCURACY"];
} else if (window['cordova'].platformId == 'android') {
tempConfig.accuracy = accuracyOptions["PRIORITY_HIGH_ACCURACY"];
}
} else {
if (window.cordova.platformId == 'ios') {
if (window['cordova'].platformId == 'ios') {
tempConfig.accuracy = accuracyOptions["kCLLocationAccuracyHundredMeters"];
} else if (window.cordova.platformId == 'android') {
} else if (window['cordova'].platformId == 'android') {
tempConfig.accuracy = accuracyOptions["PRIORITY_BALANCED_POWER_ACCURACY"];
}
}
Expand All @@ -87,7 +88,7 @@ export async function helperToggleLowAccuracy() {
*/

export const getState = function() {
return window.cordova.plugins.BEMDataCollection.getState();
return window['cordova'].plugins.BEMDataCollection.getState();
};

export async function getHelperCollectionSettings() {
Expand All @@ -101,18 +102,18 @@ export async function getHelperCollectionSettings() {
}

const setConfig = function(config) {
return window.cordova.plugins.BEMDataCollection.setConfig(config);
return window['cordova'].plugins.BEMDataCollection.setConfig(config);
};

const getConfig = function() {
return window.cordova.plugins.BEMDataCollection.getConfig();
return window['cordova'].plugins.BEMDataCollection.getConfig();
};
const getAccuracyOptions = function() {
return window.cordova.plugins.BEMDataCollection.getAccuracyOptions();
return window['cordova'].plugins.BEMDataCollection.getAccuracyOptions();
};

export const forceTransitionWrapper = function(transition) {
return window.cordova.plugins.BEMDataCollection.forceTransition(transition);
return window['cordova'].plugins.BEMDataCollection.forceTransition(transition);
};

const formatConfigForDisplay = function(config, accuracyOptions) {
Expand Down Expand Up @@ -197,7 +198,7 @@ const ControlSyncHelper = ({ editVis, setEditVis }) => {

/*ios vs android*/
let filterComponent;
if(window.cordova.platformId == 'ios') {
if(window['cordova'].platformId == 'ios') {
filterComponent = <View style={{ paddingHorizontal: 15, flexDirection: 'row', justifyContent: 'space-between' }}>
<Text variant="labelMedium">Filter Distance</Text>
<TextInput label="Filter Distance" value={localConfig?.filter_distance?.toString()} onChangeText={text => onChangeText(text, "filter_distance")}/>
Expand All @@ -209,7 +210,7 @@ const ControlSyncHelper = ({ editVis, setEditVis }) => {
</View>
}
let iosToggles;
if(window.cordova.platformId == 'ios') {
if(window['cordova'].platformId == 'ios') {
iosToggles = <>
{/* use visit notifications toggle NO ANDROID */}
<View style={{ paddingHorizontal: 15, flexDirection: 'row', justifyContent: 'space-between' }}>
Expand All @@ -224,7 +225,7 @@ const ControlSyncHelper = ({ editVis, setEditVis }) => {
</>
}
let geofenceComponent;
if(window.cordova.platformId == 'android') {
if(window['cordova'].platformId == 'android') {
geofenceComponent = <View style={{ paddingHorizontal: 15, flexDirection: 'row', justifyContent: 'space-between' }}>
<Text variant="labelMedium">Geofence Responsiveness</Text>
<TextInput label="Geofence Responsiveness" value={localConfig?.android_geofence_responsiveness?.toString()} onChangeText={text => onChangeText(text, "android_geofence_responsiveness")}/>
Expand Down
2 changes: 1 addition & 1 deletion www/js/diary/diaryHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import moment from "moment";
import { DateTime } from "luxon";
import { LabelOptions, readableLabelToKey } from "../survey/multilabel/confirmHelper";

const modeColors = {
export const modeColors = {
pink: '#c32e85', // oklch(56% 0.2 350) // e-car
red: '#c21725', // oklch(52% 0.2 25) // car
orange: '#bf5900', // oklch(58% 0.16 50) // air, hsr
Expand Down

0 comments on commit 0f7caef

Please sign in to comment.