From 9f0c480248dc218d9e235f446184bd3f8e614332 Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Sat, 16 Jan 2021 12:48:07 +0100 Subject: [PATCH] change volume and menu state to localStorage --- CHANGELOG.md | 6 + appinfo/routes.php | 22 ---- lib/Controller/SettingsController.php | 157 -------------------------- src/components/Main.vue | 3 - src/components/Player.vue | 10 +- src/dashboard.js | 2 +- src/main.js | 4 +- src/router.js | 14 +-- src/store.js | 144 ----------------------- 9 files changed, 14 insertions(+), 348 deletions(-) delete mode 100644 lib/Controller/SettingsController.php delete mode 100644 src/store.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 72cb469..29529bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## 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 +- Update npm modules + [235](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/235) @onny - Update license year to 2021 [234](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/234) @onny diff --git a/appinfo/routes.php b/appinfo/routes.php index cd19cb8..bb02165 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -71,28 +71,6 @@ return [ '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 [ 'name' => 'favorite_api#preflighted_cors', diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php deleted file mode 100644 index c7abbc2..0000000 --- a/lib/Controller/SettingsController.php +++ /dev/null @@ -1,157 +0,0 @@ - - * - * 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 . - * - */ - -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); - } - -} diff --git a/src/components/Main.vue b/src/components/Main.vue index 1c2dd0d..dd12eab 100644 --- a/src/components/Main.vue +++ b/src/components/Main.vue @@ -438,12 +438,9 @@ export default { } }, loadSettings() { - axios.defaults.headers.common = { 'User-Agent': 'Nextcloud Radio App/' + this.$version, } - this.$store.dispatch('getVolumeState') - }, async loadFavorites() { diff --git a/src/components/Player.vue b/src/components/Player.vue index eecb165..de32f35 100644 --- a/src/components/Player.vue +++ b/src/components/Player.vue @@ -42,8 +42,7 @@ max="1" step=".05" :value="player.volume" - @input="changeVolume($event)" - @change="saveVolume($event)"> + @input="setVolume($event)"> @@ -58,11 +57,8 @@ export default { }, }, methods: { - changeVolume() { - this.$store.dispatch('changeVolume', event.target.value) - }, - saveVolume() { - this.$store.dispatch('setVolumeState', event.target.value) + setVolume() { + this.$store.dispatch('setVolume', event.target.value) }, toggleMute() { this.$store.dispatch('toggleMute') diff --git a/src/dashboard.js b/src/dashboard.js index c4740bf..ed7c9ca 100644 --- a/src/dashboard.js +++ b/src/dashboard.js @@ -22,7 +22,7 @@ import Vue from 'vue' import router from './router' -import store from './store' +import store from './store/main' import Dashboard from './components/Dashboard.vue' import { translate, translatePlural } from '@nextcloud/l10n' diff --git a/src/main.js b/src/main.js index 27808c7..71b5c95 100644 --- a/src/main.js +++ b/src/main.js @@ -22,7 +22,7 @@ import Vue from 'vue' import router from './router' -import store from './store' +import store from './store/main' import { translate, translatePlural } from '@nextcloud/l10n' @@ -39,7 +39,7 @@ Vue.prototype.n = translatePlural Vue.prototype.OC = window.OC Vue.prototype.OCA = window.OCA 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(VueBlurHash) diff --git a/src/router.js b/src/router.js index a128a8d..bec9c04 100644 --- a/src/router.js +++ b/src/router.js @@ -23,13 +23,11 @@ import Vue from 'vue' import Router from 'vue-router' import { generateUrl } from '@nextcloud/router' -import axios from '@nextcloud/axios' import Main from './components/Main' -import store from './store.js' +import store from './store/main.js' Vue.use(Router) -const requesttoken = axios.defaults.headers.requesttoken const router = new Router({ base: generateUrl('/apps/radio/'), @@ -75,15 +73,7 @@ router.beforeEach((to, from, next) => { store.dispatch('setMenuState', to.name) next() } else { - axios.defaults.headers.requesttoken = requesttoken - axios - .get(generateUrl('/apps/radio/settings/menuState')) - .then(async response => { - const { - data: { menuState: value }, - } = response - next({ name: value }) - }) + next({ name: store.state.menu }) } }) diff --git a/src/store.js b/src/store.js deleted file mode 100644 index dcaf976..0000000 --- a/src/store.js +++ /dev/null @@ -1,144 +0,0 @@ -/* - * @copyright Copyright (c) 2021 Jonas Heinrich - * - * @author Jonas Heinrich - * - * @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 . - * - */ - -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') - }, - }, -})