janky page position retention

This commit is contained in:
booploops 2022-09-29 22:04:56 -07:00
parent b8e3131da5
commit c5d86a9a0f
2 changed files with 67 additions and 8 deletions

View file

@ -264,17 +264,17 @@ const app = new Vue({
ipcRenderer.send("onPrivacyModeChange", newValue); ipcRenderer.send("onPrivacyModeChange", newValue);
}, },
page: () => { page: () => {
document.getElementById("app-content").scrollTo(0, 0); // document.getElementById("app-content").scrollTo(0, 0);
app.resetState(); app.resetState();
}, },
showingPlaylist: () => { showingPlaylist: () => {
if (!app.modals.showPlaylist) { if (!app.modals.showPlaylist) {
document.getElementById("app-content").scrollTo(0, 0); // document.getElementById("app-content").scrollTo(0, 0);
app.resetState(); app.resetState();
} }
}, },
artistPage: () => { artistPage: () => {
document.getElementById("app-content").scrollTo(0, 0); // document.getElementById("app-content").scrollTo(0, 0);
app.resetState(); app.resetState();
}, },
}, },
@ -290,6 +290,7 @@ const app = new Vue({
}, },
methods: { methods: {
setWindowHash(route = "") { setWindowHash(route = "") {
this.setPagePos()
window.location.hash = `#${route}`; window.location.hash = `#${route}`;
}, },
monitorMusickit() { monitorMusickit() {
@ -599,6 +600,8 @@ const app = new Vue({
} }
}, },
navigateBack() { navigateBack() {
this.setPagePos()
this.resumePagePos()
this.chrome.desiredPageTransition = "wpfade_transform_backwards"; this.chrome.desiredPageTransition = "wpfade_transform_backwards";
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
history.back(); history.back();
@ -608,6 +611,8 @@ const app = new Vue({
}); });
}, },
goToGrouping(url = "https://music.apple.com/WebObjects/MZStore.woa/wa/viewGrouping?cc=us&id=34") { goToGrouping(url = "https://music.apple.com/WebObjects/MZStore.woa/wa/viewGrouping?cc=us&id=34") {
this.setPagePos()
this.resumePagePos()
if (url.includes("viewTop")) { if (url.includes("viewTop")) {
window.location.hash = `#charts/top`; window.location.hash = `#charts/top`;
} else { } else {
@ -633,6 +638,8 @@ const app = new Vue({
} }
}, },
navigateForward() { navigateForward() {
this.setPagePos()
this.resumePagePos()
history.forward(); history.forward();
}, },
resetState() { resetState() {
@ -2079,6 +2086,15 @@ const app = new Vue({
} }
return hash; return hash;
}, },
getPagePos(href = "") {
let state = this.$store.state.pageState.scrollPos.pos.find((page) => {
return page.href === href;
})
return state ?? {
page: href,
position: 0
}
},
appRoute(route) { appRoute(route) {
if (route == "" || route == "#" || route == "/") { if (route == "" || route == "#" || route == "/") {
return; return;
@ -2091,10 +2107,12 @@ const app = new Vue({
app.cfg.general.resumeTabs.dynamicData = "home"; app.cfg.general.resumeTabs.dynamicData = "home";
} }
} }
// if the route contains does not include a / then route to the page directly // if the route contains does not include a / then route to the page directly
if (route.indexOf("/") == -1) { if (route.indexOf("/") == -1) {
this.page = route; this.page = route;
window.location.hash = this.page; window.location.hash = this.page;
this.resumePagePos()
// if (this.page == "settings") { // if (this.page == "settings") {
// this.version // this.version
// } // }
@ -2117,7 +2135,23 @@ const app = new Vue({
}, },
}); });
}, },
resumePagePos() {
setTimeout(()=>{
$("#app-content").scrollTop(app.getPagePos(window.location.hash).position)
}, 100)
},
setPagePos() {
console.debug({
href: window.location.hash,
position: $("#app-content").scrollTop()
})
this.$store.commit("setPagePos", {
href: window.location.hash,
position: $("#app-content").scrollTop()
})
},
routeView(item) { routeView(item) {
this.setPagePos()
let kind = item.attributes?.playParams ? item.attributes?.playParams?.kind ?? item.type ?? "" : item.type ?? ""; let kind = item.attributes?.playParams ? item.attributes?.playParams?.kind ?? item.type ?? "" : item.type ?? "";
let id = item.attributes?.playParams ? item.attributes?.playParams?.id ?? item.id ?? "" : item.id ?? ""; let id = item.attributes?.playParams ? item.attributes?.playParams?.id ?? item.id ?? "" : item.id ?? "";
let isLibrary = item.attributes?.playParams ? item.attributes?.playParams?.isLibrary ?? false : false; let isLibrary = item.attributes?.playParams ? item.attributes?.playParams?.isLibrary ?? false : false;
@ -2136,7 +2170,6 @@ const app = new Vue({
.then(() => { .then(() => {
kind = "appleCurator"; kind = "appleCurator";
window.location.hash = `${kind}/${id}`; window.location.hash = `${kind}/${id}`;
document.querySelector("#app-content").scrollTop = 0;
}); });
} else if (kind == "editorial-elements" || kind == "editorial-items") { } else if (kind == "editorial-elements" || kind == "editorial-items") {
console.debug(item); console.debug(item);
@ -2162,7 +2195,6 @@ const app = new Vue({
.then(() => { .then(() => {
kind = "multiroom"; kind = "multiroom";
window.location.hash = `${kind}/${id}`; window.location.hash = `${kind}/${id}`;
document.querySelector("#app-content").scrollTop = 0;
}); });
return; return;
@ -2194,12 +2226,13 @@ const app = new Vue({
.then(() => { .then(() => {
kind = "multiroom"; kind = "multiroom";
window.location.hash = `${kind}/${id}`; window.location.hash = `${kind}/${id}`;
document.querySelector("#app-content").scrollTop = 0; // document.querySelector("#app-content").scrollTop = 0;
}); });
this.resumePagePos()
} else if (kind.toString().includes("artist")) { } else if (kind.toString().includes("artist")) {
app.getArtistInfo(id, isLibrary); app.getArtistInfo(id, isLibrary);
window.location.hash = `${kind}/${id}${isLibrary ? "/" + isLibrary : ""}`; window.location.hash = `${kind}/${id}${isLibrary ? "/" + isLibrary : ""}`;
document.querySelector("#app-content").scrollTop = 0; // document.querySelector("#app-content").scrollTop = 0;
} else if (kind.toString().includes("record-label") || kind.toString().includes("curator")) { } else if (kind.toString().includes("record-label") || kind.toString().includes("curator")) {
if (kind.toString().includes("record-label")) { if (kind.toString().includes("record-label")) {
kind = "recordLabel"; kind = "recordLabel";
@ -2214,6 +2247,7 @@ const app = new Vue({
}); });
window.location.hash = `${kind}/${id}`; window.location.hash = `${kind}/${id}`;
document.querySelector("#app-content").scrollTop = 0; document.querySelector("#app-content").scrollTop = 0;
this.resumePagePos()
} else if (kind.toString().includes("social-profiles")) { } else if (kind.toString().includes("social-profiles")) {
app.page = kind + "_" + id; app.page = kind + "_" + id;
app.mk.api.v3 app.mk.api.v3
@ -2254,7 +2288,7 @@ const app = new Vue({
app.page = kind; app.page = kind;
window.location.hash = `${kind}/${id}${isLibrary ? "/" + isLibrary : ""}`; window.location.hash = `${kind}/${id}${isLibrary ? "/" + isLibrary : ""}`;
} }
this.resumePagePos()
// app.getTypeFromID((kind), (id), (isLibrary), params); // app.getTypeFromID((kind), (id), (isLibrary), params);
} else if (kind.toString().includes("song")) { } else if (kind.toString().includes("song")) {
const albumUrl = new Promise(async (resolve, reject) => { const albumUrl = new Promise(async (resolve, reject) => {

View file

@ -18,6 +18,10 @@ const store = new Vuex.Store({
currentTabIndex: 0, currentTabIndex: 0,
fullscreen: false, fullscreen: false,
}, },
scrollPos: {
limit: 10,
pos: []
}
}, },
artwork: { artwork: {
playerLCD: "", playerLCD: "",
@ -32,6 +36,27 @@ const store = new Vuex.Store({
setLCDArtwork(state, artwork) { setLCDArtwork(state, artwork) {
state.artwork.playerLCD = artwork; state.artwork.playerLCD = artwork;
}, },
setPagePos(state, pageState = {}) {
let cached = state.pageState.scrollPos.pos.find((page) => {
return page.href === pageState.href;
})
if(cached) {
state.pageState.scrollPos.pos.find((page) => {
if(page.href === pageState.href) {
page.position = pageState.position
}
})
return
}
state.pageState.scrollPos.pos.push({
"href": pageState.href,
"position": pageState.position
})
if (state.pageState.scrollPos.pos.length > state.pageState.scrollPos.limit) {
pages.value.shift()
}
return
}
}, },
}); });