WebUI: ensure cached info are initialized properly

PR #21893.
This commit is contained in:
Chocobo1 2024-11-25 14:04:28 +08:00 committed by GitHub
commit b0fe6e6c59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 84 additions and 63 deletions

View file

@ -30,6 +30,7 @@ window.qBittorrent.Client ??= (() => {
const exports = () => {
return {
setup: setup,
initializeCaches: initializeCaches,
closeWindow: closeWindow,
closeFrameWindow: closeFrameWindow,
getSyncMainDataInterval: getSyncMainDataInterval,
@ -45,11 +46,22 @@ window.qBittorrent.Client ??= (() => {
};
};
let cacheAllSettled;
const setup = () => {
// fetch various data and store it in memory
window.qBittorrent.Cache.buildInfo.init();
window.qBittorrent.Cache.preferences.init();
window.qBittorrent.Cache.qbtVersion.init();
cacheAllSettled = Promise.allSettled([
window.qBittorrent.Cache.buildInfo.init(),
window.qBittorrent.Cache.preferences.init(),
window.qBittorrent.Cache.qbtVersion.init()
]);
};
const initializeCaches = async () => {
const results = await cacheAllSettled;
for (const [idx, result] of results.entries()) {
if (result.status === "rejected")
console.error(`Failed to initialize cache. Index: ${idx}. Reason: "${result.reason}".`);
}
};
const closeWindow = (windowID) => {
@ -1771,7 +1783,9 @@ window.addEventListener("DOMContentLoaded", () => {
});
});
window.addEventListener("load", () => {
window.addEventListener("load", async () => {
await window.qBittorrent.Client.initializeCaches();
// switch to previously used tab
const previouslyUsedTab = LocalPreferences.get("selected_window_tab", "transfers");
switch (previouslyUsedTab) {