From 1e13484c26cff13523971a59c48ef5f1efa1cb9c Mon Sep 17 00:00:00 2001 From: rustdesk Date: Mon, 31 Jan 2022 00:48:04 +0800 Subject: [PATCH] fix on getByname --- src/connection.ts | 8 ++++---- src/globals.js | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index a25bcee68..3337d3505 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -424,8 +424,8 @@ export default class Connection { } } - getRemember(): any { - return this._options["remember"]; + getRemember(): Boolean { + return this._options["remember"] || false; } setRemember(v: Boolean) { @@ -566,9 +566,9 @@ export default class Connection { const misc = message.Misc.fromPartial({ option }); this._ws?.sendMessage({ misc }); } - + getImageQuality() { - return this.getOption("image-quality"); + return this.getOption('image-quality'); } getImageQualityEnum( diff --git a/src/globals.js b/src/globals.js index d7154043e..ca3001d19 100644 --- a/src/globals.js +++ b/src/globals.js @@ -229,14 +229,18 @@ window.setByName = (name, value) => { } window.getByName = (name, arg) => { - try { - arg = JSON.parse(arg); - } catch (e) { } + let v = _getByName(name, arg); + if (typeof v == 'string' || v instanceof String) return v; + if (v == undefined || v == null) return ''; + return JSON.stringify(v); +} + +function _getByName(name, arg) { switch (name) { case 'peers': return localStorage.getItem('peers') || '[]'; case 'remote_id': - return localStorage.getItem('remote-id') || ''; + return localStorage.getItem('remote-id'); case 'remember': return curConn.getRemember(); case 'event': @@ -247,7 +251,7 @@ window.getByName = (name, arg) => { } break; case 'toggle_option': - return curConn.getOption(arg); + return curConn.getOption(arg) || false; case 'option': return localStorage.getItem(arg); case 'image_quality':