WebUI: avoid redundant re-initialization

PR #21012.
This commit is contained in:
Chocobo1 2024-07-12 15:00:36 +08:00 committed by GitHub
commit 9feefc8144
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 174 additions and 240 deletions

View file

@ -28,10 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Cache ??= (() => {
window.qBittorrent.Cache = (() => {
const exports = () => { const exports = () => {
return { return {
buildInfo: new BuildInfoCache(), buildInfo: new BuildInfoCache(),
@ -170,5 +168,4 @@ window.qBittorrent.Cache = (() => {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Cache); Object.freeze(window.qBittorrent.Cache);

View file

@ -25,10 +25,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Client ??= (() => {
window.qBittorrent.Client = (() => {
const exports = () => { const exports = () => {
return { return {
closeWindows: closeWindows, closeWindows: closeWindows,

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.ContextMenu ??= (() => {
const exports = () => {
window.qBittorrent.ContextMenu = (function() {
const exports = function() {
return { return {
ContextMenu: ContextMenu, ContextMenu: ContextMenu,
TorrentsTableContextMenu: TorrentsTableContextMenu, TorrentsTableContextMenu: TorrentsTableContextMenu,
@ -680,5 +678,4 @@ window.qBittorrent.ContextMenu = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.ContextMenu); Object.freeze(window.qBittorrent.ContextMenu);

View file

@ -23,11 +23,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Download ??= (() => {
const exports = () => {
window.qBittorrent.Download = (function() {
const exports = function() {
return { return {
changeCategorySelect: changeCategorySelect, changeCategorySelect: changeCategorySelect,
changeTMM: changeTMM changeTMM: changeTMM
@ -138,5 +136,4 @@ window.qBittorrent.Download = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Download); Object.freeze(window.qBittorrent.Download);

View file

@ -33,11 +33,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.DynamicTable ??= (() => {
const exports = () => {
window.qBittorrent.DynamicTable = (function() {
const exports = function() {
return { return {
TorrentsTable: TorrentsTable, TorrentsTable: TorrentsTable,
TorrentPeersTable: TorrentPeersTable, TorrentPeersTable: TorrentPeersTable,
@ -3279,7 +3277,6 @@ window.qBittorrent.DynamicTable = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.DynamicTable); Object.freeze(window.qBittorrent.DynamicTable);
/*************************************************************/ /*************************************************************/

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.FileTree ??= (() => {
const exports = () => {
window.qBittorrent.FileTree = (function() {
const exports = function() {
return { return {
FilePriority: FilePriority, FilePriority: FilePriority,
TriState: TriState, TriState: TriState,
@ -196,5 +194,4 @@ window.qBittorrent.FileTree = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.FileTree); Object.freeze(window.qBittorrent.FileTree);

View file

@ -30,11 +30,9 @@
// This file is the JavaScript implementation of base/utils/fs.cpp // This file is the JavaScript implementation of base/utils/fs.cpp
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Filesystem ??= (() => {
const exports = () => {
window.qBittorrent.Filesystem = (function() {
const exports = function() {
return { return {
PathSeparator: PathSeparator, PathSeparator: PathSeparator,
fileExtension: fileExtension, fileExtension: fileExtension,
@ -71,5 +69,4 @@ window.qBittorrent.Filesystem = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Filesystem); Object.freeze(window.qBittorrent.Filesystem);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.LocalPreferences ??= (() => {
const exports = () => {
window.qBittorrent.LocalPreferences = (function() {
const exports = function() {
return { return {
LocalPreferencesClass: LocalPreferencesClass LocalPreferencesClass: LocalPreferencesClass
}; };
@ -67,5 +65,4 @@ window.qBittorrent.LocalPreferences = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.LocalPreferences); Object.freeze(window.qBittorrent.LocalPreferences);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Misc ??= (() => {
const exports = () => {
window.qBittorrent.Misc = (function() {
const exports = function() {
return { return {
friendlyUnit: friendlyUnit, friendlyUnit: friendlyUnit,
friendlyDuration: friendlyDuration, friendlyDuration: friendlyDuration,
@ -230,5 +228,4 @@ window.qBittorrent.Misc = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Misc); Object.freeze(window.qBittorrent.Misc);

View file

@ -31,11 +31,9 @@
/* /*
File implementing auto-fill for the path input field in the path dialogs. File implementing auto-fill for the path input field in the path dialogs.
*/ */
if (window.qBittorrent === undefined)
window.qBittorrent = {};
if (window.qBittorrent.pathAutofill === undefined) { window.qBittorrent ??= {};
window.qBittorrent.pathAutofill = (() => { window.qBittorrent.pathAutofill ??= (() => {
const exports = () => { const exports = () => {
return { return {
attachPathAutofill: attachPathAutofill attachPathAutofill: attachPathAutofill
@ -87,7 +85,5 @@ if (window.qBittorrent.pathAutofill === undefined) {
}; };
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.pathAutofill);
Object.freeze(window.qBittorrent.pathAutofill);
};

View file

@ -28,10 +28,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.PiecesBar ??= (() => {
window.qBittorrent.PiecesBar = (() => {
const exports = () => { const exports = () => {
return { return {
PiecesBar: PiecesBar PiecesBar: PiecesBar
@ -267,5 +265,4 @@ window.qBittorrent.PiecesBar = (() => {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PiecesBar); Object.freeze(window.qBittorrent.PiecesBar);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.ProgressBar ??= (() => {
const exports = () => {
window.qBittorrent.ProgressBar = (function() {
const exports = function() {
return { return {
ProgressBar: ProgressBar ProgressBar: ProgressBar
}; };
@ -157,5 +155,4 @@ window.qBittorrent.ProgressBar = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.ProgressBar); Object.freeze(window.qBittorrent.ProgressBar);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.PropFiles ??= (() => {
const exports = () => {
window.qBittorrent.PropFiles = (function() {
const exports = function() {
return { return {
normalizePriority: normalizePriority, normalizePriority: normalizePriority,
isDownloadCheckboxExists: isDownloadCheckboxExists, isDownloadCheckboxExists: isDownloadCheckboxExists,
@ -769,5 +767,4 @@ window.qBittorrent.PropFiles = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PropFiles); Object.freeze(window.qBittorrent.PropFiles);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.PropGeneral ??= (() => {
const exports = () => {
window.qBittorrent.PropGeneral = (function() {
const exports = function() {
return { return {
updateData: updateData updateData: updateData
}; };
@ -257,5 +255,4 @@ window.qBittorrent.PropGeneral = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PropGeneral); Object.freeze(window.qBittorrent.PropGeneral);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.PropPeers ??= (() => {
const exports = () => {
window.qBittorrent.PropPeers = (function() {
const exports = function() {
return { return {
updateData: updateData updateData: updateData
}; };
@ -182,5 +180,4 @@ window.qBittorrent.PropPeers = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PropPeers); Object.freeze(window.qBittorrent.PropPeers);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.PropTrackers ??= (() => {
const exports = () => {
window.qBittorrent.PropTrackers = (function() {
const exports = function() {
return { return {
updateData: updateData updateData: updateData
}; };
@ -237,5 +235,4 @@ window.qBittorrent.PropTrackers = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PropTrackers); Object.freeze(window.qBittorrent.PropTrackers);

View file

@ -28,11 +28,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.PropWebseeds ??= (() => {
const exports = () => {
window.qBittorrent.PropWebseeds = (function() {
const exports = function() {
return { return {
updateData: updateData updateData: updateData
}; };
@ -148,5 +146,4 @@ window.qBittorrent.PropWebseeds = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.PropWebseeds); Object.freeze(window.qBittorrent.PropWebseeds);

View file

@ -1,10 +1,8 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.MultiRename ??= (() => {
const exports = () => {
window.qBittorrent.MultiRename = (function() {
const exports = function() {
return { return {
AppliesTo: AppliesTo, AppliesTo: AppliesTo,
RenameFiles: RenameFiles RenameFiles: RenameFiles
@ -282,5 +280,4 @@ window.qBittorrent.MultiRename = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.MultiRename); Object.freeze(window.qBittorrent.MultiRename);

View file

@ -23,11 +23,9 @@
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Search ??= (() => {
const exports = () => {
window.qBittorrent.Search = (function() {
const exports = function() {
return { return {
startStopSearch: startStopSearch, startStopSearch: startStopSearch,
manageSearchPlugins: manageSearchPlugins, manageSearchPlugins: manageSearchPlugins,
@ -866,5 +864,4 @@ window.qBittorrent.Search = (function() {
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Search); Object.freeze(window.qBittorrent.Search);

View file

@ -44,11 +44,9 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Filters ??= (() => {
const exports = () => {
window.qBittorrent.Filters = (function() {
const exports = function() {
return { return {
categoriesFilterContextMenu: categoriesFilterContextMenu, categoriesFilterContextMenu: categoriesFilterContextMenu,
tagsFilterContextMenu: tagsFilterContextMenu, tagsFilterContextMenu: tagsFilterContextMenu,
@ -163,6 +161,5 @@
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Filters); Object.freeze(window.qBittorrent.Filters);
</script> </script>

View file

@ -29,17 +29,16 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.InstallSearchPlugin ??= (() => {
const exports = () => {
window.qBittorrent.InstallSearchPlugin = (function() {
const exports = function() {
return { return {
setup: setup,
newPluginOk: newPluginOk newPluginOk: newPluginOk
}; };
}; };
const init = function() { const setup = function() {
new Keyboard({ new Keyboard({
defaultEventType: "keydown", defaultEventType: "keydown",
events: { events: {
@ -75,10 +74,9 @@
} }
}; };
init();
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.InstallSearchPlugin); Object.freeze(window.qBittorrent.InstallSearchPlugin);
window.qBittorrent.InstallSearchPlugin.setup();
</script> </script>

View file

@ -148,10 +148,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Log ??= (() => {
window.qBittorrent.Log = (() => {
const exports = () => { const exports = () => {
return { return {
init: init, init: init,
@ -430,6 +428,5 @@
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Log); Object.freeze(window.qBittorrent.Log);
</script> </script>

View file

@ -1572,12 +1572,11 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Preferences ??= (() => {
const exports = () => {
window.qBittorrent.Preferences = (function() {
const exports = function() {
return { return {
setup: setup,
numberInputLimiter: numberInputLimiter, numberInputLimiter: numberInputLimiter,
updateFileLogEnabled: updateFileLogEnabled, updateFileLogEnabled: updateFileLogEnabled,
updateFileLogBackupEnabled: updateFileLogBackupEnabled, updateFileLogBackupEnabled: updateFileLogBackupEnabled,
@ -1654,7 +1653,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
}; };
// Downloads tab // Downloads tab
const watchedFoldersTable = new HtmlTable($("watched_folders_tab")); let watchedFoldersTable;
const updateTempDirEnabled = function() { const updateTempDirEnabled = function() {
const isTempDirEnabled = $("temppath_checkbox").checked; const isTempDirEnabled = $("temppath_checkbox").checked;
@ -2886,9 +2885,12 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
}); });
}; };
// hide entries const setup = () => {
watchedFoldersTable = new HtmlTable($("watched_folders_tab"));
const buildInfo = window.qBittorrent.Cache.buildInfo.get(); const buildInfo = window.qBittorrent.Cache.buildInfo.get();
// hide entries
const libtorrentVersion = window.qBittorrent.Misc.parseVersion(buildInfo.libtorrent); const libtorrentVersion = window.qBittorrent.Misc.parseVersion(buildInfo.libtorrent);
if (libtorrentVersion.valid) { if (libtorrentVersion.valid) {
if (libtorrentVersion.major >= 2) { if (libtorrentVersion.major >= 2) {
@ -2920,10 +2922,12 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
loadPreferences(); loadPreferences();
window.qBittorrent.pathAutofill.attachPathAutofill();
};
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Preferences); Object.freeze(window.qBittorrent.Preferences);
window.qBittorrent.pathAutofill.attachPathAutofill(); window.qBittorrent.Preferences.setup();
</script> </script>

View file

@ -158,12 +158,8 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.Rss ??= (() => {
const serverSyncRssDataInterval = 1500;
window.qBittorrent.Rss = (() => {
const exports = () => { const exports = () => {
return { return {
init: init, init: init,
@ -181,6 +177,7 @@
}; };
}; };
const serverSyncRssDataInterval = 1500;
let feedData = {}; let feedData = {};
let pathByFeedId = new Map(); let pathByFeedId = new Map();
let feedRefreshTimer; let feedRefreshTimer;
@ -828,6 +825,5 @@
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.Rss); Object.freeze(window.qBittorrent.Rss);
</script> </script>

View file

@ -330,12 +330,11 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.RssDownloader ??= (() => {
window.qBittorrent.RssDownloader = (() => {
const exports = () => { const exports = () => {
return { return {
setup: setup,
updateRulesList: updateRulesList, updateRulesList: updateRulesList,
showRule: showRule, showRule: showRule,
renameRule: renameRule, renameRule: renameRule,
@ -356,7 +355,7 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also
let rulesList = {}; let rulesList = {};
let feedList = []; let feedList = [];
const initRssDownloader = () => { const setup = () => {
const pref = window.parent.qBittorrent.Cache.preferences.get(); const pref = window.parent.qBittorrent.Cache.preferences.get();
if (!pref.rss_auto_downloading_enabled) if (!pref.rss_auto_downloading_enabled)
@ -808,9 +807,9 @@ Supports the formats: S01E01, 1x1, 2017.12.31 and 31.12.2017 (Date formats also
$("episodeFilterText").title = episodeFilterTitle; $("episodeFilterText").title = episodeFilterTitle;
}; };
initRssDownloader();
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.RssDownloader); Object.freeze(window.qBittorrent.RssDownloader);
window.qBittorrent.RssDownloader.setup();
</script> </script>

View file

@ -79,13 +79,12 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.SearchPlugins ??= (() => {
const exports = () => {
window.qBittorrent.SearchPlugins = (function() {
const exports = function() {
return { return {
closeSearchWindow: closeSearchWindow, closeSearchWindow: closeSearchWindow,
setup: setup,
installPlugin: installPlugin, installPlugin: installPlugin,
checkForUpdates: checkForUpdates, checkForUpdates: checkForUpdates,
updateTable: updateTable updateTable: updateTable
@ -97,7 +96,7 @@
let prevOffsetLeft; let prevOffsetLeft;
let prevOffsetTop; let prevOffsetTop;
const initSearchPlugins = function() { const setup = function() {
searchPluginsTable = new window.qBittorrent.DynamicTable.SearchPluginsTable(); searchPluginsTable = new window.qBittorrent.DynamicTable.SearchPluginsTable();
searchPluginsTableContextMenu = new window.qBittorrent.ContextMenu.SearchPluginsTableContextMenu({ searchPluginsTableContextMenu = new window.qBittorrent.ContextMenu.SearchPluginsTableContextMenu({
targets: ".searchPluginsTableRow", targets: ".searchPluginsTableRow",
@ -230,10 +229,9 @@
setupSearchPluginTableEvents(true); setupSearchPluginTableEvents(true);
}; };
initSearchPlugins();
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.SearchPlugins); Object.freeze(window.qBittorrent.SearchPlugins);
window.qBittorrent.SearchPlugins.setup();
</script> </script>

View file

@ -18,12 +18,11 @@
<script> <script>
"use strict"; "use strict";
if (window.qBittorrent === undefined) window.qBittorrent ??= {};
window.qBittorrent = {}; window.qBittorrent.TransferList ??= (() => {
const exports = () => {
window.qBittorrent.TransferList = (function() {
const exports = function() {
return { return {
setup: setup,
contextMenu: contextMenu, contextMenu: contextMenu,
}; };
}; };
@ -111,10 +110,13 @@
}, },
}); });
const setup = () => {
torrentsTable.setup("torrentsTableDiv", "torrentsTableFixedHeaderDiv", contextMenu); torrentsTable.setup("torrentsTableDiv", "torrentsTableFixedHeaderDiv", contextMenu);
};
return exports(); return exports();
})(); })();
Object.freeze(window.qBittorrent.TransferList); Object.freeze(window.qBittorrent.TransferList);
window.qBittorrent.TransferList.setup();
</script> </script>