Skip to content

WebUI: Change ServerPathSeparator to be a getter function#24694

Open
vafada wants to merge 2 commits into
qbittorrent:masterfrom
vafada:serverpathseparator_getter
Open

WebUI: Change ServerPathSeparator to be a getter function#24694
vafada wants to merge 2 commits into
qbittorrent:masterfrom
vafada:serverpathseparator_getter

Conversation

@vafada

@vafada vafada commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

This PR #24678 is implemented wrong

1. the ServerPathSeparator for windows will never be \

When filesystem.js is included the IIFE (Immediately Invoked Function Expression) is immediately called but the call to the buildInfo api might not resolve yet:

class BuildInfoCache {
#m_store = {};
init() {
return fetch("api/v2/app/buildInfo", {
method: "GET",
cache: "no-store"
})
.then(async (response) => {
if (!response.ok)
return;
const responseJSON = await response.json();
deepFreeze(responseJSON);
this.#m_store = responseJSON;
});
}
get() {
return this.#m_store;
}
}

so window.qBittorrent?.Cache.buildInfo.get().platform will be undefined and ServerPathSeparator will be stuck at /

To fix this, I replaced the constant to be a getter function

2. filesystem.js now depends on window.qBittorrent.Cache. But there are several html files that includes filesystem.js but never includes cache.js. This broke a couple of features in the WebUI with a javascript error.

Screenshot from 2026-07-14 22-39-42
  • Add Torrent Dialog is broken
    • Add a new torrent via Add Torrent File... and Add Torrent Link...
    • in the RSS tab, when double-clicking to download
  • In the Content tab, Rename file link

Again, the IIFE (Immediately Invoked Function Expression) in filesystem.js is invoked but window.qBittorrent?.Cache is undefined.

The optional chaining operator must be window.qBittorrent.Cache?.buildInfo (after the Cache object), though changing it to a getter function resolves this.

I still added <script defer src="scripts/cache.js?v=${CACHEID}"></script> to all files that includes filesystem.js since filesystem.js now depends on window.qBittorrent.Cache

@vafada

vafada commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Easy to test this on non-windows machine, just hardcode platformName to windows:

const QString platformName =
#ifdef Q_OS_LINUX
u"linux"_s;
#elif defined(Q_OS_MACOS)
u"macos"_s;
#elif defined(Q_OS_WIN)
u"windows"_s;
#else
u"unknown"_s;
#endif

Try the new Copy path feature in WebUI and check what the path separator is.

@vafada
vafada marked this pull request as ready for review July 15, 2026 03:34
@glassez glassez changed the title BUGFIX: Change ServerPathSeparator to be a getter function WebUI: Change ServerPathSeparator to be a getter function Jul 15, 2026
@glassez
glassez requested a review from a team July 15, 2026 04:08
@glassez glassez added WebUI WebUI-related issues/changes Bugfix labels Jul 15, 2026
@glassez glassez added this to the 5.2.4 milestone Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix WebUI WebUI-related issues/changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants