1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-21 23:32:35 +00:00

refactor: parse cookie pref values as their default values types (#7001)

* refactor: allow floating point values in web refresh rate

Co-authored-by: Rukario <kakashiru@yahoo.com>

* refactor: parse cookie pref according to default value type

* fixup! refactor: parse cookie pref according to default value type

---------

Co-authored-by: Rukario <kakashiru@yahoo.com>
This commit is contained in:
Yat Ho 2024-12-10 22:58:28 +08:00 committed by GitHub
parent 90859fe115
commit 8bca3f2e06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View file

@ -71,14 +71,20 @@ export class Prefs extends EventTarget {
if (value === null) {
return fallback;
}
if (value === 'true') {
return true;
const type = typeof fallback;
if (type === 'boolean') {
if (value === 'true') {
return true;
}
if (value === 'false') {
return false;
}
return fallback;
}
if (value === 'false') {
return false;
}
if (/^\d+$/.test(value)) {
return Number.parseInt(value, 10);
if (type === 'number') {
const f = Number.parseFloat(value);
return Number.isNaN(f) ? fallback : f;
}
return value;
}

View file

@ -375,7 +375,8 @@ export class Transmission extends EventTarget {
case Prefs.RefreshRate: {
clearInterval(this.refreshTorrentsInterval);
const callback = this.refreshTorrents.bind(this);
const msec = Math.max(2, this.prefs.refresh_rate_sec) * 1000;
const pref = this.prefs.refresh_rate_sec;
const msec = pref > 0 ? pref * 1000 : 1000;
this.refreshTorrentsInterval = setInterval(callback, msec);
break;
}