Add a setting to allow permanent notification or not.

This commit is contained in:
Lucas Verney 2018-09-14 15:42:10 +02:00
parent 04ac3538a4
commit dca0f62394
4 changed files with 38 additions and 3 deletions

View File

@ -30,6 +30,14 @@
v-model="hasGeolocationPermission" v-model="hasGeolocationPermission"
> >
</v-switch> </v-switch>
<v-switch
class="switch"
:messages="[`<i aria-hidden='true' class='v-icon material-icons' style='vertical-align: middle;'>help</i> ${$t('permissions.permanentNotificationDescription')}`]"
color="success"
:label="$t('permissions.permanentNotification')"
v-model="hasPermanentNotificationPermission"
>
</v-switch>
</div> </div>
</template> </template>
@ -44,6 +52,14 @@ export default {
this.$store.dispatch('setSetting', { setting: 'hasGeolocationPermission', value }); this.$store.dispatch('setSetting', { setting: 'hasGeolocationPermission', value });
}, },
}, },
hasPermanentNotificationPermission: {
get() {
return this.$store.state.settings.hasPermanentNotificationPermission;
},
set(value) {
this.$store.dispatch('setSetting', { setting: 'hasPermanentNotificationPermission', value });
},
},
hasPlaySoundPermission: { hasPlaySoundPermission: {
get() { get() {
return this.$store.state.settings.hasPlaySoundPermission; return this.$store.state.settings.hasPlaySoundPermission;

View File

@ -62,9 +62,14 @@
"retry": "Retry", "retry": "Retry",
"spaceBeforeDoublePunctuations": "&#8203;" "spaceBeforeDoublePunctuations": "&#8203;"
}, },
"notification": {
"body": "Click to report something!"
},
"permissions": { "permissions": {
"geolocation": "Geolocation", "geolocation": "Geolocation",
"geolocationDescription": "As of current version, your precise geolocation is handled within your device and never sent from it to any external service. The map background is downloaded on demand from the tile provider and it has then access to an estimate of the displayed position. If you refuse to share your geolocation, you can still pick a location manually but you will miss some geolocation dependent features.", "geolocationDescription": "As of current version, your precise geolocation is handled within your device and never sent from it to any external service. The map background is downloaded on demand from the tile provider and it has then access to an estimate of the displayed position. If you refuse to share your geolocation, you can still pick a location manually but you will miss some geolocation dependent features.",
"permanentNotification": "Permanent notification",
"permanentNotificationDescription": "Display a permanent notification to quickly jump back to the new report window.",
"playSound": "Play sound", "playSound": "Play sound",
"preventSuspend": "Prevent device from going to sleep", "preventSuspend": "Prevent device from going to sleep",
"preventSuspendDescription": "When the map is displayed, the device will be prevented from going to sleep.", "preventSuspendDescription": "When the map is displayed, the device will be prevented from going to sleep.",

View File

@ -44,6 +44,7 @@ if (storageAvailable('localStorage')) {
// Load settings from storage // Load settings from storage
let locale = null; let locale = null;
let hasGeolocationPermission = null; let hasGeolocationPermission = null;
let hasPermanentNotificationPermission = null;
let hasPlaySoundPermission = null; let hasPlaySoundPermission = null;
let hasPreventSuspendPermission = null; let hasPreventSuspendPermission = null;
let hasVibratePermission = null; let hasVibratePermission = null;
@ -54,6 +55,7 @@ if (storageAvailable('localStorage')) {
handleMigrations(); handleMigrations();
hasGeolocationPermission = loadDataFromStorage('hasGeolocationPermission'); hasGeolocationPermission = loadDataFromStorage('hasGeolocationPermission');
hasPermanentNotificationPermission = loadDataFromStorage('hasPermanentNotificationPermission');
hasPlaySoundPermission = loadDataFromStorage('hasPlaySoundPermission'); hasPlaySoundPermission = loadDataFromStorage('hasPlaySoundPermission');
hasPreventSuspendPermission = loadDataFromStorage('hasPreventSuspendPermission'); hasPreventSuspendPermission = loadDataFromStorage('hasPreventSuspendPermission');
hasVibratePermission = loadDataFromStorage('hasVibratePermission'); hasVibratePermission = loadDataFromStorage('hasVibratePermission');
@ -107,6 +109,9 @@ export const initialState = {
hasGeolocationPermission: ( hasGeolocationPermission: (
hasGeolocationPermission !== null ? hasGeolocationPermission : true hasGeolocationPermission !== null ? hasGeolocationPermission : true
), ),
hasPermanentNotificationPermission: (
hasPermanentNotificationPermission !== null ? hasPermanentNotificationPermission : true
),
hasPlaySoundPermission: ( hasPlaySoundPermission: (
hasPlaySoundPermission !== null ? hasPlaySoundPermission : true hasPlaySoundPermission !== null ? hasPlaySoundPermission : true
), ),

View File

@ -57,6 +57,8 @@ import { distance, mockLocation } from '@/tools';
import i18n from '@/i18n'; import i18n from '@/i18n';
import store from '@/store'; import store from '@/store';
import AppLogo from '@/assets/logo.svg';
function handlePositionError(error) { function handlePositionError(error) {
store.dispatch('setLocationError', { error: error.code }); store.dispatch('setLocationError', { error: error.code });
} }
@ -173,7 +175,11 @@ export default {
}, },
methods: { methods: {
createNotification() { createNotification() {
this.notification = new Notification('Toto', { body: 'Foobar', icon: '', tag: 'CyclassistMap' }); // TODO: icon const $t = this.$t.bind(this);
this.notification = new Notification(
'Cycl\'Assist',
{ body: $t('notification.body'), icon: AppLogo, tag: 'CyclassistMap' },
);
this.notification.addEventListener('click', this.showReportDialog); this.notification.addEventListener('click', this.showReportDialog);
this.notification.addEventListener('close', this.createNotification); this.notification.addEventListener('close', this.createNotification);
}, },
@ -235,8 +241,11 @@ export default {
} }
}, },
setupNotification() { setupNotification() {
if (!window.Notification) { if (
// Ensure notification API is available !window.Notification
|| !this.$store.state.settings.hasPermanentNotificationPermission
) {
// Ensure notification API is available and notification is wanted
return; return;
} }