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:
parent
90859fe115
commit
8bca3f2e06
2 changed files with 15 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue