remember menu and volume state

This commit is contained in:
Jonas Heinrich 2020-10-28 21:21:59 +01:00
parent 6fc4744b56
commit 05698fa938
7 changed files with 84 additions and 10 deletions

View File

@ -37,6 +37,8 @@ return [
// Settings // Settings
['name' => 'settings#set_menu_state', 'url' => '/settings/menuState', 'verb' => 'POST'], ['name' => 'settings#set_menu_state', 'url' => '/settings/menuState', 'verb' => 'POST'],
['name' => 'settings#get_menu_state', 'url' => '/settings/menuState', 'verb' => 'GET'], ['name' => 'settings#get_menu_state', 'url' => '/settings/menuState', 'verb' => 'GET'],
['name' => 'settings#set_volume_state', 'url' => '/settings/volumeState', 'verb' => 'POST'],
['name' => 'settings#get_volume_state', 'url' => '/settings/volumeState', 'verb' => 'GET'],
// Api // Api
['name' => 'radio_api#preflighted_cors', 'url' => '/api/0.1/{path}', ['name' => 'radio_api#preflighted_cors', 'url' => '/api/0.1/{path}',
'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']] 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']]

View File

@ -99,4 +99,30 @@ class SettingsController extends ApiController {
return $this->getSetting('menuState', 'menuState', 'TOP'); return $this->getSetting('menuState', 'menuState', 'TOP');
} }
/**
* set player volume
*
* @param string $playerVolume
* @return JSONResponse
*
* @NoAdminRequired
*/
public function setVolumeState($volumeState = "0.5"): JSONResponse {
return $this->setSetting(
'volumeState',
$volumeState
);
}
/**
* get player volume
*
* @return JSONResponse
*
* @NoAdminRequired
*/
public function getVolumeState(): JSONResponse {
return $this->getSetting('volumeState', 'volumeState', 0.5);
}
} }

File diff suppressed because one or more lines are too long

View File

@ -73,10 +73,12 @@ export default {
} }
}, },
}, },
created() {
this.loadSettings()
},
mounted() { mounted() {
this.loadStations() this.loadStations()
this.scroll() this.scroll()
this.$store.dispatch('getMenuState')
}, },
methods: { methods: {
async onRoute() { async onRoute() {
@ -204,6 +206,9 @@ export default {
} }
} }
}, },
loadSettings() {
this.$store.dispatch('getVolumeState')
},
}, },
} }
</script> </script>

View File

@ -20,7 +20,8 @@
max="1" max="1"
step=".05" step=".05"
:value="player.volume" :value="player.volume"
@input="changeVolume($event)"> @input="changeVolume($event)"
@change="saveVolume($event)">
<span class="playerMetadata"> <span class="playerMetadata">
{{ player.title }} {{ player.title }}
</span> </span>
@ -38,6 +39,9 @@ export default {
changeVolume() { changeVolume() {
this.$store.dispatch('changeVolume', event.target.value) this.$store.dispatch('changeVolume', event.target.value)
}, },
saveVolume() {
this.$store.dispatch('setVolumeState', event.target.value)
},
toggleMute() { toggleMute() {
this.$store.dispatch('toggleMute') this.$store.dispatch('toggleMute')
}, },

View File

@ -1,20 +1,17 @@
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import { generateUrl } from '@nextcloud/router' import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import Main from './components/Main' import Main from './components/Main'
Vue.use(Router) Vue.use(Router)
export default new Router({ const router = new Router({
mode: 'history', mode: 'history',
base: generateUrl('/apps/radio'), base: generateUrl('/apps/radio'),
linkActiveClass: 'active', linkActiveClass: 'active',
routes: [ routes: [
{
path: '/',
redirect: '/top',
},
{ {
path: '/top', path: '/top',
component: Main, component: Main,
@ -42,3 +39,20 @@ export default new Router({
}, },
], ],
}) })
router.beforeEach((to, from, next) => {
if (to.name) {
next()
} else {
axios
.get(generateUrl('/apps/radio/settings/menuState'))
.then(async response => {
const {
data: { menuState: value },
} = response
next({ name: value })
})
}
})
export default router

View File

@ -13,10 +13,11 @@ export default new Vuex.Store({
isBuffering: false, isBuffering: false,
isMute: false, isMute: false,
isPaused: false, isPaused: false,
volume: 0, volume: 0.5,
oldVolume: 0, oldVolume: 0,
title: 'test', title: 'test',
}, },
menu: 'top',
}, },
mutations: { mutations: {
isPlaying(state, playerState) { isPlaying(state, playerState) {
@ -55,14 +56,29 @@ export default new Vuex.Store({
menuState, menuState,
}) })
}, },
getMenuState(state, menuState) { getMenuState(state) {
axios axios
.get(generateUrl('/apps/radio/settings/menuState')) .get(generateUrl('/apps/radio/settings/menuState'))
.then(async response => { .then(async response => {
const { const {
data: { menuState: value }, data: { menuState: value },
} = response } = response
console.log(value) state.menu = value
})
},
setVolumeState(state, volumeState) {
axios.post(generateUrl('/apps/radio/settings/volumeState'), {
volumeState,
})
},
getVolumeState(state) {
axios
.get(generateUrl('/apps/radio/settings/volumeState'))
.then(async response => {
const {
data: { volumeState: value },
} = response
state.player.volume = value
}) })
}, },
}, },
@ -91,5 +107,11 @@ export default new Vuex.Store({
getMenuState(context) { getMenuState(context) {
context.commit('getMenuState') context.commit('getMenuState')
}, },
setVolumeState(context, volumeState) {
context.commit('setVolumeState', volumeState)
},
getVolumeState(context) {
context.commit('getVolumeState')
},
}, },
}) })