mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
@@ -62,30 +62,6 @@ export class SettingsItemComponent {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for user permission to use location,
|
||||
* if no permission is granted, setting is set to false and an alert is presented to the user
|
||||
*/
|
||||
private async checkGeoLocationPermission() {
|
||||
const permissionGranted = await this.settingsProvider.checkGeoLocationPermission();
|
||||
if (!permissionGranted) {
|
||||
// revert setting value
|
||||
this.setting.value = false;
|
||||
await this.presentGeoLocationAlert();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows alert with error message on denied user permission or disabled location services
|
||||
*/
|
||||
private async presentGeoLocationAlert() {
|
||||
const title = await this.translateService.get('settings.geoLocation.permission_denied_title')
|
||||
.toPromise();
|
||||
const message = await this.translateService.get('settings.geoLocation.permission_denied_message')
|
||||
.toPromise();
|
||||
await this.presentAlert(title, message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows alert with given title and message and a 'ok' button
|
||||
*
|
||||
@@ -112,11 +88,6 @@ export class SettingsItemComponent {
|
||||
case 'language':
|
||||
this.translateService.use(this.setting.value as SCLanguageCode);
|
||||
break;
|
||||
case 'geoLocation':
|
||||
if (!!this.setting.value) {
|
||||
await this.checkGeoLocationPermission();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
await this.settingsProvider
|
||||
|
||||
@@ -16,7 +16,6 @@ import {CommonModule} from '@angular/common';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {FormsModule} from '@angular/forms';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {IonicModule} from '@ionic/angular';
|
||||
import {TranslateModule} from '@ngx-translate/core';
|
||||
|
||||
@@ -51,7 +50,6 @@ const settingsRoutes: Routes = [
|
||||
],
|
||||
providers: [
|
||||
ConfigProvider,
|
||||
Geolocation,
|
||||
SettingsProvider,
|
||||
],
|
||||
})
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {SCSetting, SCThingOriginType, SCThingType, SCSettingInputType} from '@openstapps/core';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {ConfigProvider} from '../config/config.provider';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
import {SettingsProvider, SettingValuesContainer, STORAGE_KEY_SETTING_VALUES} from './settings.provider';
|
||||
@@ -38,7 +37,6 @@ describe('SettingsProvider', () => {
|
||||
{
|
||||
provide: ConfigProvider, useValue: configProviderMethodSpy,
|
||||
},
|
||||
Geolocation,
|
||||
],
|
||||
});
|
||||
configProviderSpy = TestBed.get(ConfigProvider);
|
||||
@@ -317,7 +315,7 @@ describe('SettingsProvider', () => {
|
||||
description: '',
|
||||
defaultValue: false,
|
||||
inputType: SCSettingInputType.SingleChoice,
|
||||
name: 'geoLocation',
|
||||
name: 'foo',
|
||||
order: 0,
|
||||
origin: {
|
||||
indexed: '2018-09-11T12:30:00Z',
|
||||
@@ -326,14 +324,12 @@ describe('SettingsProvider', () => {
|
||||
},
|
||||
translations: {
|
||||
de: {
|
||||
description: 'Berechtigung für die Verwendung des Ortungsdienstes, für die Anzeige der aktuellen ' +
|
||||
'Position \'\n auf der Karte und zur Berechnung der Entfernung zu Gebäuden und Orten des Campus',
|
||||
name: 'Position',
|
||||
description: 'Foo Beschreibung',
|
||||
name: 'Foo',
|
||||
},
|
||||
en: {
|
||||
description: 'Allow the App to use the device location to provide additional informationsbased ' +
|
||||
'on your actual location',
|
||||
name: 'Position',
|
||||
description: 'Foo Description',
|
||||
name: 'Foo',
|
||||
},
|
||||
},
|
||||
type: SCThingType.Setting,
|
||||
@@ -374,7 +370,7 @@ const SETTING_VALUES_MOCK: SettingValuesContainer = {
|
||||
bar: 'foo-bar',
|
||||
},
|
||||
privacy: {
|
||||
geoLocation: 'true',
|
||||
foo: true,
|
||||
},
|
||||
profile: {
|
||||
group: 'employee',
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Geolocation} from '@ionic-native/geolocation/ngx';
|
||||
import {
|
||||
SCSetting,
|
||||
SCSettingValue,
|
||||
@@ -196,11 +195,9 @@ export class SettingsProvider {
|
||||
*
|
||||
* @param storage TODO
|
||||
* @param configProvider TODO
|
||||
* @param geoLocation TODO
|
||||
*/
|
||||
constructor(private readonly storage: StorageProvider,
|
||||
private readonly configProvider: ConfigProvider,
|
||||
private readonly geoLocation: Geolocation) {
|
||||
private readonly configProvider: ConfigProvider) {
|
||||
this.categoriesOrder = [];
|
||||
this.settingsCache = {};
|
||||
}
|
||||
@@ -265,32 +262,6 @@ export class SettingsProvider {
|
||||
return this.settingsCache[category] !== undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for user permission to use location
|
||||
*/
|
||||
public async checkGeoLocationPermission(): Promise<boolean> {
|
||||
// request geoLocation to test the user permission
|
||||
try {
|
||||
// set enableHighAccuracy, otherwise android platform does not respond
|
||||
const options = {
|
||||
enableHighAccuracy: true,
|
||||
};
|
||||
await this.geoLocation.getCurrentPosition(options);
|
||||
} catch (error) {
|
||||
// if error code is 1 the user denied permission,
|
||||
// other errors like 'timeout' or 'no location' will be ignored here
|
||||
if (error.code === 1) {
|
||||
// ios has special error message for disabled location services, for the setting we ignore it
|
||||
if (error.message.toLowerCase() !== 'location services are disabled.') {
|
||||
// revert setting value
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns copy of cached settings
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user