mirror of
https://codeberg.org/Hyperpipe/Hyperpipe
synced 2025-06-28 05:08:00 +02:00
feat: option to restore settings via url
This commit is contained in:
parent
d1ff3d681b
commit
1b678b032c
4 changed files with 101 additions and 5 deletions
10
src/App.vue
10
src/App.vue
|
@ -24,7 +24,10 @@ import Artist from '@/components/Artist.vue';
|
||||||
const Genres = defineAsyncComponent(() => import('@/components/Genres.vue')),
|
const Genres = defineAsyncComponent(() => import('@/components/Genres.vue')),
|
||||||
Charts = defineAsyncComponent(() => import('@/components/Charts.vue')),
|
Charts = defineAsyncComponent(() => import('@/components/Charts.vue')),
|
||||||
Library = defineAsyncComponent(() => import('@/components/Library.vue')),
|
Library = defineAsyncComponent(() => import('@/components/Library.vue')),
|
||||||
Prefs = defineAsyncComponent(() => import('@/components/Prefs.vue'));
|
Prefs = defineAsyncComponent(() => import('@/components/Prefs.vue')),
|
||||||
|
RestorePrefs = defineAsyncComponent(() =>
|
||||||
|
import('@/components/RestorePrefs.vue'),
|
||||||
|
);
|
||||||
|
|
||||||
/* Composables */
|
/* Composables */
|
||||||
import { useStore, useUnwrap } from '@/scripts/util.js';
|
import { useStore, useUnwrap } from '@/scripts/util.js';
|
||||||
|
@ -87,6 +90,9 @@ function parseUrl() {
|
||||||
case 'prefs':
|
case 'prefs':
|
||||||
nav.state.page = 'prefs';
|
nav.state.page = 'prefs';
|
||||||
break;
|
break;
|
||||||
|
case 'restore':
|
||||||
|
nav.state.page = 'restore';
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log(loc);
|
console.log(loc);
|
||||||
break;
|
break;
|
||||||
|
@ -201,6 +207,8 @@ onMounted(() => {
|
||||||
@open-playlist="results.getAlbum" />
|
@open-playlist="results.getAlbum" />
|
||||||
|
|
||||||
<Prefs v-if="nav.state.page == 'prefs'" />
|
<Prefs v-if="nav.state.page == 'prefs'" />
|
||||||
|
|
||||||
|
<RestorePrefs v-if="nav.state.page == 'restore'" />
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<Transition name="fade">
|
<Transition name="fade">
|
||||||
|
|
|
@ -24,7 +24,8 @@ const { t, setupLocale } = useI18n(),
|
||||||
next = ref(false),
|
next = ref(false),
|
||||||
compact = ref(false),
|
compact = ref(false),
|
||||||
prm = ref(false),
|
prm = ref(false),
|
||||||
cc = ref(false);
|
cc = ref(false),
|
||||||
|
restoreUrl = ref('');
|
||||||
|
|
||||||
getJson('https://piped-instances.kavin.rocks')
|
getJson('https://piped-instances.kavin.rocks')
|
||||||
.then(i => i || getJson('https://instances.tokhmi.xyz'))
|
.then(i => i || getJson('https://instances.tokhmi.xyz'))
|
||||||
|
@ -40,6 +41,16 @@ getJson('https://raw.codeberg.page/Hyperpipe/pages/api/backend.json').then(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const getRestoreUrl = () => {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
Object.keys(window.localStorage).forEach(key => {
|
||||||
|
params.set(key, window.localStorage.getItem(key));
|
||||||
|
});
|
||||||
|
restoreUrl.value = window.location.origin + '/restore/?' + params;
|
||||||
|
};
|
||||||
|
|
||||||
|
getRestoreUrl();
|
||||||
|
|
||||||
function getBool(val) {
|
function getBool(val) {
|
||||||
return 'bi ' + (val ? 'bi-check2' : 'bi-x-lg');
|
return 'bi ' + (val ? 'bi-check2' : 'bi-x-lg');
|
||||||
}
|
}
|
||||||
|
@ -362,6 +373,9 @@ onMounted(() => {
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<h2>{{ t('title.restore_prefs') }}</h2>
|
||||||
|
<a :href="restoreUrl">{{ restoreUrl }}</a>
|
||||||
|
|
||||||
<footer>
|
<footer>
|
||||||
{{ date }}
|
{{ date }}
|
||||||
<a
|
<a
|
||||||
|
|
73
src/components/RestorePrefs.vue
Normal file
73
src/components/RestorePrefs.vue
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<script setup>
|
||||||
|
import { useI18n } from '@/stores/misc.js';
|
||||||
|
import { ref, onMounted } from 'vue';
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
|
const urlParamKeys = ref([]),
|
||||||
|
urlParamValues = ref([]),
|
||||||
|
restorePrefs = () => {
|
||||||
|
for (let i = 0; i < urlParamKeys.value.length; i++) {
|
||||||
|
window.localStorage.setItem(
|
||||||
|
urlParamKeys.value[i],
|
||||||
|
urlParamValues.value[i],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.location.href = '/';
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const urlParams = new URLSearchParams(window.location.search);
|
||||||
|
urlParams.forEach((val, key) => {
|
||||||
|
urlParamKeys.value.push(key);
|
||||||
|
urlParamValues.value.push(val);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<h2>{{ t('title.restore_prefs') }}</h2>
|
||||||
|
|
||||||
|
<div class="table">
|
||||||
|
<span v-for="(key, index) in urlParamKeys">
|
||||||
|
<div class="table-row">
|
||||||
|
<span>{{ key }}</span>
|
||||||
|
<hr />
|
||||||
|
<span>{{ urlParamValues[index] }}</span>
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button @click="restorePrefs" class="input">
|
||||||
|
{{ t('title.restore_prefs') }}
|
||||||
|
</button>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
h2 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 100%;
|
||||||
|
margin: 2rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-row {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.table-row > span {
|
||||||
|
width: 50%;
|
||||||
|
padding-left: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -17,7 +17,8 @@
|
||||||
"remote": "Remote",
|
"remote": "Remote",
|
||||||
"search": "Search",
|
"search": "Search",
|
||||||
"feeds": "Feeds",
|
"feeds": "Feeds",
|
||||||
"offline": "Offline"
|
"offline": "Offline",
|
||||||
|
"restore_prefs": "Restore preferences"
|
||||||
},
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"back": "Back",
|
"back": "Back",
|
||||||
|
@ -93,8 +94,8 @@
|
||||||
"lyrics": "Lyrics"
|
"lyrics": "Lyrics"
|
||||||
},
|
},
|
||||||
"statusBar": {
|
"statusBar": {
|
||||||
"currentPlaylist": "Current Playlist",
|
"currentPlaylist": "Current Playlist",
|
||||||
"loop": "Loop",
|
"loop": "Loop",
|
||||||
"add_current_to_playlist": "Add Current Song to a Playlist"
|
"add_current_to_playlist": "Add Current Song to a Playlist"
|
||||||
},
|
},
|
||||||
"general": {
|
"general": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue