Allow to set custom suffix to window title

This is to allow users to differentiate qbt instances when there are multiple running.
PR #20429.
Closes #17905.
This commit is contained in:
Chocobo1
2024-02-27 12:41:12 +08:00
committed by GitHub
parent 364bcf73ee
commit 46e8ee50c8
13 changed files with 98 additions and 27 deletions

View File

@@ -361,6 +361,8 @@ void AppController::preferencesAction()
data[u"torrent_file_size_limit"_s] = pref->getTorrentFileSizeLimit();
// Recheck completed torrents
data[u"recheck_completed_torrents"_s] = pref->recheckTorrentsOnCompletion();
// Customize application instance name
data[u"app_instance_name"_s] = app()->instanceName();
// Refresh interval
data[u"refresh_interval"_s] = session->refreshInterval();
// Resolve peer countries
@@ -943,6 +945,9 @@ void AppController::setPreferencesAction()
// Recheck completed torrents
if (hasKey(u"recheck_completed_torrents"_s))
pref->recheckTorrentsOnCompletion(it.value().toBool());
// Customize application instance name
if (hasKey(u"app_instance_name"_s))
app()->setInstanceName(it.value().toString());
// Refresh interval
if (hasKey(u"refresh_interval"_s))
session->setRefreshInterval(it.value().toInt());

View File

@@ -53,7 +53,7 @@
#include "base/utils/version.h"
#include "api/isessionmanager.h"
inline const Utils::Version<3, 2> API_VERSION {2, 10, 3};
inline const Utils::Version<3, 2> API_VERSION {2, 10, 4};
class QTimer;

View File

@@ -241,7 +241,7 @@ a.propButton img {
.contextMenu li a {
color: var(--color-text-default);
display: block;
font-family: tahoma, arial, sans-serif;
font-family: Tahoma, Arial, sans-serif;
font-size: 12px;
padding: 5px 20px 5px 5px;
text-decoration: none;

View File

@@ -36,7 +36,8 @@ window.qBittorrent.Client = (() => {
genHash: genHash,
getSyncMainDataInterval: getSyncMainDataInterval,
isStopped: isStopped,
stop: stop
stop: stop,
mainTitle: mainTitle
};
};
@@ -67,6 +68,15 @@ window.qBittorrent.Client = (() => {
stopped = true;
};
const mainTitle = () => {
const emDash = '\u2014';
const qbtVersion = window.qBittorrent.Cache.qbtVersion.get();
const suffix = window.qBittorrent.Cache.preferences.get()['app_instance_name'] || '';
const title = `qBittorrent ${qbtVersion} QBT_TR(WebUI)QBT_TR[CONTEXT=OptionsDialog]`
+ ((suffix.length > 0) ? ` ${emDash} ${suffix}` : '');
return title;
};
return exports();
})();
Object.freeze(window.qBittorrent.Client);
@@ -275,7 +285,7 @@ window.addEventListener("DOMContentLoaded", function() {
initializeWindows();
// Show Top Toolbar is enabled by default
let showTopToolbar = LocalPreferences.get('show_top_toolbar', 'true') == "true";
let showTopToolbar = LocalPreferences.get('show_top_toolbar', 'true') === "true";
if (!showTopToolbar) {
$('showTopToolbarLink').firstChild.style.opacity = '0';
$('mochaToolbar').addClass('invisible');
@@ -296,7 +306,7 @@ window.addEventListener("DOMContentLoaded", function() {
$('filtersColumn_handle').addClass('invisible');
}
let speedInTitle = LocalPreferences.get('speed_in_browser_title_bar') == "true";
let speedInTitle = LocalPreferences.get('speed_in_browser_title_bar') === "true";
if (!speedInTitle)
$('speedInBrowserTitleBarLink').firstChild.style.opacity = '0';
@@ -873,14 +883,13 @@ window.addEventListener("DOMContentLoaded", function() {
transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.up_info_data, false) + ")";
$("UpInfos").set('html', transfer_info);
const qbtVersion = window.qBittorrent.Cache.qbtVersion.get();
document.title = (speedInTitle
? (`QBT_TR([D: %1, U: %2])QBT_TR[CONTEXT=MainWindow] `
.replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true))
.replace("%2", window.qBittorrent.Misc.friendlyUnit(serverState.up_info_speed, true)))
: '')
+ window.qBittorrent.Client.mainTitle();
if (speedInTitle) {
document.title = "QBT_TR([D: %1, U: %2] qBittorrent %3)QBT_TR[CONTEXT=MainWindow]".replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true)).replace("%2", window.qBittorrent.Misc.friendlyUnit(serverState.up_info_speed, true)).replace("%3", qbtVersion);
document.title += " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]";
}
else
document.title = ("qBittorrent " + qbtVersion + " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]");
$('freeSpaceOnDisk').set('html', 'QBT_TR(Free space: %1)QBT_TR[CONTEXT=HttpServer]'.replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.free_space_on_disk)));
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]'.replace("%1", serverState.dht_nodes));

View File

@@ -1157,7 +1157,8 @@ const initializeWindows = function() {
url: 'api/v2/app/shutdown',
method: 'post',
onSuccess: function() {
document.write('<!doctype html><html lang="${LANG}"><head> <meta charset="UTF-8"> <meta name="color-scheme" content="light dark" /> <title>QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]</title></head><body> <h1 style="text-align: center;">QBT_TR(qBittorrent has been shutdown)QBT_TR[CONTEXT=HttpServer]</h1></body></html>');
const shutdownMessage = 'QBT_TR(%1 has been shutdown)QBT_TR[CONTEXT=HttpServer]'.replace("%1", window.qBittorrent.Client.mainTitle());
document.write(`<!doctype html><html lang="${LANG}"><head> <meta charset="UTF-8"> <meta name="color-scheme" content="light dark"> <title>${shutdownMessage}</title> <style>* {font-family: Arial, Helvetica, sans-serif;}</style></head><body> <h1 style="text-align: center;">${shutdownMessage}</h1></body></html>`);
document.close();
window.stop();
window.qBittorrent.Client.stop();

View File

@@ -1043,6 +1043,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="checkbox" id="recheckTorrentsOnCompletion">
</td>
</tr>
<tr>
<td>
<label for="appInstanceName">QBT_TR(Customize application instance name:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="text" id="appInstanceName" style="width: 15em;" title="QBT_TR(It appends the text to the window title to help distinguish qBittorent instances)QBT_TR[CONTEXT=OptionsDialog]" />
</td>
</tr>
<tr>
<td>
<label for="refreshInterval">QBT_TR(Refresh interval:)QBT_TR[CONTEXT=OptionsDialog]</label>
@@ -2301,6 +2309,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
$('saveResumeDataInterval').setProperty('value', pref.save_resume_data_interval);
$('torrentFileSizeLimit').setProperty('value', (pref.torrent_file_size_limit / 1024 / 1024));
$('recheckTorrentsOnCompletion').setProperty('checked', pref.recheck_completed_torrents);
$('appInstanceName').setProperty('value', pref.app_instance_name);
$('refreshInterval').setProperty('value', pref.refresh_interval);
$('resolvePeerCountries').setProperty('checked', pref.resolve_peer_countries);
$('reannounceWhenAddressChanged').setProperty('checked', pref.reannounce_when_address_changed);
@@ -2746,6 +2755,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
settings['save_resume_data_interval'] = Number($('saveResumeDataInterval').getProperty('value'));
settings['torrent_file_size_limit'] = ($('torrentFileSizeLimit').getProperty('value') * 1024 * 1024);
settings['recheck_completed_torrents'] = $('recheckTorrentsOnCompletion').getProperty('checked');
settings['app_instance_name'] = $('appInstanceName').getProperty('value');
settings['refresh_interval'] = Number($('refreshInterval').getProperty('value'));
settings['resolve_peer_countries'] = $('resolvePeerCountries').getProperty('checked');
settings['reannounce_when_address_changed'] = $('reannounceWhenAddressChanged').getProperty('checked');