change volume and menu state to localStorage

This commit is contained in:
Jonas Heinrich 2021-01-16 12:48:07 +01:00
parent 2d51b382d6
commit 9f0c480248
9 changed files with 14 additions and 348 deletions

View File

@ -1,5 +1,11 @@
## 1.0.2 - 2021-01 ## 1.0.2 - 2021-01
### Fixed
- Set user agent http header for remote API
[221](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/221) @onny
### Changed ### Changed
- Update npm modules
[235](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/235) @onny
- Update license year to 2021 - Update license year to 2021
[234](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/234) @onny [234](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/234) @onny

View File

@ -71,28 +71,6 @@ return [
'postfix' => 'search', 'postfix' => 'search',
], ],
// Settings
[
'name' => 'settings#set_menu_state',
'url' => '/settings/menuState',
'verb' => 'POST'
],
[
'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' => 'favorite_api#preflighted_cors', 'name' => 'favorite_api#preflighted_cors',

View File

@ -1,157 +0,0 @@
<?php
/**
* Radio App
*
* @author Jonas Heinrich
* @copyright 2021 Jonas Heinrich <onny@project-insanity.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Radio\Controller;
use Exception;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
use OCP\ILogger;
class SettingsController extends ApiController {
/** @var ILogger */
private $logger;
/** @var IConfig */
private $config;
/** @var string */
private $userId;
/**
* @var IL10N
*/
private $l;
/**
* @param string $appName
* @param IRequest $request
* @param string $userId
* @param ILogger $logger
* @param IConfig $config
* @param IL10N $l
*/
public function __construct(
$appName, $request, $userId, ILogger $logger, IConfig $config, IL10N $l
) {
parent::__construct($appName, $request);
$this->logger = $logger;
$this->config = $config;
$this->userId = $userId;
$this->l = $l;
}
private function getSetting(string $key, string $name, $default): JSONResponse {
try {
$userValue = $this->config->getUserValue(
$this->userId,
$this->appName,
$key,
$default
);
} catch (Exception $e) {
$this->logger->error($e->getMessage());
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new JSONResponse([$name => $userValue], Http::STATUS_OK);
}
private function setSetting($key, $value): JSONResponse {
try {
$this->config->setUserValue(
$this->userId,
$this->appName,
$key,
$value
);
} catch (Exception $e) {
return new JSONResponse(['status' => 'error'], Http::STATUS_INTERNAL_SERVER_ERROR);
}
return new JSONResponse(['status' => 'success'], Http::STATUS_OK);
}
/**
* set menu state
*
* @param string $menuState
* @return JSONResponse
*
* @NoAdminRequired
*/
public function setMenuState($menuState = ""): JSONResponse {
if ($menuState = 'SEARCH') {
return new JSONResponse(['status' => 'success'], Http::STATUS_OK);
};
$legalArguments = ['TOP', 'RECENT', 'NEW', 'FAVORITES', 'CATEGORIES'];
if (!in_array($menuState, $legalArguments)) {
return new JSONResponse(['status' => 'error'], Http::STATUS_BAD_REQUEST);
}
return $this->setSetting(
'menuState',
$menuState
);
}
/**
* get menu state
*
* @return JSONResponse
*
* @NoAdminRequired
*/
public function getMenuState(): JSONResponse {
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);
}
}

View File

@ -438,12 +438,9 @@ export default {
} }
}, },
loadSettings() { loadSettings() {
axios.defaults.headers.common = { axios.defaults.headers.common = {
'User-Agent': 'Nextcloud Radio App/' + this.$version, 'User-Agent': 'Nextcloud Radio App/' + this.$version,
} }
this.$store.dispatch('getVolumeState')
}, },
async loadFavorites() { async loadFavorites() {

View File

@ -42,8 +42,7 @@
max="1" max="1"
step=".05" step=".05"
:value="player.volume" :value="player.volume"
@input="changeVolume($event)" @input="setVolume($event)">
@change="saveVolume($event)">
<div class="playerMetadata"> <div class="playerMetadata">
{{ player.title }} {{ player.title }}
</div> </div>
@ -58,11 +57,8 @@ export default {
}, },
}, },
methods: { methods: {
changeVolume() { setVolume() {
this.$store.dispatch('changeVolume', event.target.value) this.$store.dispatch('setVolume', event.target.value)
},
saveVolume() {
this.$store.dispatch('setVolumeState', event.target.value)
}, },
toggleMute() { toggleMute() {
this.$store.dispatch('toggleMute') this.$store.dispatch('toggleMute')

View File

@ -22,7 +22,7 @@
import Vue from 'vue' import Vue from 'vue'
import router from './router' import router from './router'
import store from './store' import store from './store/main'
import Dashboard from './components/Dashboard.vue' import Dashboard from './components/Dashboard.vue'
import { translate, translatePlural } from '@nextcloud/l10n' import { translate, translatePlural } from '@nextcloud/l10n'

View File

@ -22,7 +22,7 @@
import Vue from 'vue' import Vue from 'vue'
import router from './router' import router from './router'
import store from './store' import store from './store/main'
import { translate, translatePlural } from '@nextcloud/l10n' import { translate, translatePlural } from '@nextcloud/l10n'
@ -39,7 +39,7 @@ Vue.prototype.n = translatePlural
Vue.prototype.OC = window.OC Vue.prototype.OC = window.OC
Vue.prototype.OCA = window.OCA Vue.prototype.OCA = window.OCA
Vue.prototype.$apiUrl = 'https://de1.api.radio-browser.info' Vue.prototype.$apiUrl = 'https://de1.api.radio-browser.info'
Vue.prototype.$version = '1.0.1' Vue.prototype.$version = '1.0.2'
Vue.use(VueClipboard) Vue.use(VueClipboard)
Vue.use(VueBlurHash) Vue.use(VueBlurHash)

View File

@ -23,13 +23,11 @@
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'
import store from './store.js' import store from './store/main.js'
Vue.use(Router) Vue.use(Router)
const requesttoken = axios.defaults.headers.requesttoken
const router = new Router({ const router = new Router({
base: generateUrl('/apps/radio/'), base: generateUrl('/apps/radio/'),
@ -75,15 +73,7 @@ router.beforeEach((to, from, next) => {
store.dispatch('setMenuState', to.name) store.dispatch('setMenuState', to.name)
next() next()
} else { } else {
axios.defaults.headers.requesttoken = requesttoken next({ name: store.state.menu })
axios
.get(generateUrl('/apps/radio/settings/menuState'))
.then(async response => {
const {
data: { menuState: value },
} = response
next({ name: value })
})
} }
}) })

View File

@ -1,144 +0,0 @@
/*
* @copyright Copyright (c) 2021 Jonas Heinrich <onny@project-insanity.org>
*
* @author Jonas Heinrich <onny@project-insanity.org>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import Vue from 'vue'
import Vuex from 'vuex'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
Vue.use(Vuex)
const requesttoken = axios.defaults.headers.requesttoken
export default new Vuex.Store({
state: {
player: {
isPlaying: false,
isBuffering: false,
isMute: false,
isPaused: false,
volume: 0.5,
oldVolume: 0,
title: '',
},
menu: 'top',
},
mutations: {
isPlaying(state, playerState) {
state.player.isPlaying = playerState
},
isBuffering(state, bufferingState) {
state.player.isBuffering = bufferingState
},
changeVolume(state, volume) {
state.player.volume = volume
},
toggleMute(state) {
if (state.player.isMute) {
state.player.volume = state.player.oldVolume
state.player.isMute = false
} else {
state.player.oldVolume = state.player.volume
state.player.volume = 0
state.player.isMute = true
}
},
togglePlay(state) {
if (state.player.isPlaying) {
state.player.isPlaying = false
state.player.isPaused = true
} else {
state.player.isPlaying = true
state.player.isPaused = false
}
},
setTitle(state, title) {
state.player.title = title
},
setMenuState(state, menuState) {
axios.defaults.headers.requesttoken = requesttoken
axios.post(generateUrl('/apps/radio/settings/menuState'), {
menuState,
})
},
getMenuState(state) {
axios.defaults.headers.requesttoken = requesttoken
axios
.get(generateUrl('/apps/radio/settings/menuState'))
.then(async response => {
const {
data: { menuState: value },
} = response
state.menu = value
})
},
setVolumeState(state, volumeState) {
axios.defaults.headers.requesttoken = requesttoken
axios.post(generateUrl('/apps/radio/settings/volumeState'), {
volumeState,
})
},
getVolumeState(state) {
axios.defaults.headers.requesttoken = requesttoken
axios
.get(generateUrl('/apps/radio/settings/volumeState'))
.then(async response => {
const {
data: { volumeState: value },
} = response
state.player.volume = value
})
},
},
actions: {
isPlaying(context, playerState) {
context.commit('isPlaying', playerState)
},
isBuffering(context, bufferingState) {
context.commit('isBuffering', bufferingState)
},
changeVolume(context, volume) {
context.commit('changeVolume', volume)
},
toggleMute(context) {
context.commit('toggleMute')
},
togglePlay(context) {
context.commit('togglePlay')
},
setTitle(context, title) {
context.commit('setTitle', title)
},
setMenuState(context, menuState) {
context.commit('setMenuState', menuState)
},
getMenuState(context) {
context.commit('getMenuState')
},
setVolumeState(context, volumeState) {
context.commit('setVolumeState', volumeState)
},
getVolumeState(context) {
context.commit('getVolumeState')
},
},
})