mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-14 02:27:09 -07:00
WebUI: add versioning to local preferences
And provide migration path for changing preferences. Fixes #22639. PR #22677.
This commit is contained in:
parent
7049f80a01
commit
778aa64c54
2 changed files with 44 additions and 2 deletions
|
@ -174,7 +174,9 @@ let selectedStatus = LocalPreferences.get("selected_filter", "all");
|
|||
let setStatusFilter = () => {};
|
||||
let toggleFilterDisplay = () => {};
|
||||
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
window.addEventListener("DOMContentLoaded", (event) => {
|
||||
window.qBittorrent.LocalPreferences.upgrade();
|
||||
|
||||
let isSearchPanelLoaded = false;
|
||||
let isLogPanelLoaded = false;
|
||||
let isRssPanelLoaded = false;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2025 Mike Tzou (Chocobo1)
|
||||
* Copyright (C) 2019 Thomas Piccirello <thomas.piccirello@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -32,7 +33,8 @@ window.qBittorrent ??= {};
|
|||
window.qBittorrent.LocalPreferences ??= (() => {
|
||||
const exports = () => {
|
||||
return {
|
||||
LocalPreferences: LocalPreferences
|
||||
LocalPreferences: LocalPreferences,
|
||||
upgrade: upgrade
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -53,6 +55,10 @@ window.qBittorrent.LocalPreferences ??= (() => {
|
|||
}
|
||||
}
|
||||
|
||||
size() {
|
||||
return localStorage.length;
|
||||
}
|
||||
|
||||
remove(key) {
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
|
@ -63,6 +69,40 @@ window.qBittorrent.LocalPreferences ??= (() => {
|
|||
}
|
||||
};
|
||||
|
||||
const localPreferences = new LocalPreferences();
|
||||
|
||||
const upgrade = () => {
|
||||
const MIGRATION_VERSION = 1;
|
||||
const MIGRATION_VERSION_KEY = "MigrationVersion";
|
||||
|
||||
// clean start
|
||||
if (localPreferences.size() === 0) {
|
||||
localPreferences.set(MIGRATION_VERSION_KEY, MIGRATION_VERSION);
|
||||
return;
|
||||
}
|
||||
|
||||
// already in use
|
||||
const version = Number(localPreferences.get(MIGRATION_VERSION_KEY)); // `0` on first initialization
|
||||
if (version !== MIGRATION_VERSION) {
|
||||
if (version < 1)
|
||||
resetSideFilters();
|
||||
|
||||
localPreferences.set(MIGRATION_VERSION_KEY, MIGRATION_VERSION);
|
||||
}
|
||||
};
|
||||
|
||||
const resetSideFilters = () => {
|
||||
// conditionally reset the filter to default to avoid none selected
|
||||
const clear = (key) => {
|
||||
const value = Number(localPreferences.get(key));
|
||||
if ((value === 1) || (value === 2)) // affected values
|
||||
localPreferences.remove(key);
|
||||
};
|
||||
clear("selected_category");
|
||||
clear("selected_tag");
|
||||
clear("selected_tracker");
|
||||
};
|
||||
|
||||
return exports();
|
||||
})();
|
||||
Object.freeze(window.qBittorrent.LocalPreferences);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue