1
0
mirror of https://github.com/TeamPiped/Piped.git synced 2024-12-14 06:10:28 +05:30

Make the indexeddb call syncronous to fix race condition

This commit is contained in:
Kavin 2023-11-23 21:48:23 +00:00
parent 6578f0f82b
commit dd83474126
No known key found for this signature in database
GPG Key ID: 6E4598CA5C92C41F

View File

@ -401,7 +401,7 @@ export default {
videoEl.currentTime = segment.segment[1]; videoEl.currentTime = segment.segment[1];
segment.skipped = true; segment.skipped = true;
}, },
setPlayerAttrs(localPlayer, videoEl, uri, mime, shaka) { async setPlayerAttrs(localPlayer, videoEl, uri, mime, shaka) {
const url = "/watch?v=" + this.video.id; const url = "/watch?v=" + this.video.id;
if (!this.$ui) { if (!this.$ui) {
@ -502,22 +502,25 @@ export default {
startTime = parseTimeParam(time); startTime = parseTimeParam(time);
this.initialSeekComplete = true; this.initialSeekComplete = true;
} else if (window.db && this.getPreferenceBoolean("watchHistory", false)) { } else if (window.db && this.getPreferenceBoolean("watchHistory", false)) {
var tx = window.db.transaction("watch_history", "readonly"); await new Promise(resolve => {
var store = tx.objectStore("watch_history"); var tx = window.db.transaction("watch_history", "readonly");
var request = store.get(this.video.id); var store = tx.objectStore("watch_history");
request.onsuccess = function (event) { var request = store.get(this.video.id);
var video = event.target.result; request.onsuccess = function (event) {
const currentTime = video?.currentTime; var video = event.target.result;
if (currentTime) { const currentTime = video?.currentTime;
if (currentTime < video.duration * 0.9) { if (currentTime) {
startTime = currentTime; if (currentTime < video.duration * 0.9) {
startTime = currentTime;
}
} }
} resolve();
}; };
tx.oncomplete = () => { tx.oncomplete = () => {
this.initialSeekComplete = true; this.initialSeekComplete = true;
}; };
});
} else { } else {
this.initialSeekComplete = true; this.initialSeekComplete = true;
} }