Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ import { perfLogger } from '../core/util/performance-logger.js';
// perfLogger.enable(5000);

const PAGE_TITLE = "KasmVNC";
const SETTING_RANGES = {
video_area: { min: 1, max: 100 },
video_time: { min: 0, max: 60 },
video_out_time: { min: 1, max: 100 },
};

var currentEventCount = -1;
var idleCounter = 0;
Expand Down Expand Up @@ -302,7 +307,7 @@ const UI = {
UI.initSetting('video_quality', 2);
UI.initSetting('anti_aliasing', 0);
UI.initSetting('video_rendering_mode', 'canvas2d');
UI.initSetting('video_area', 65);
UI.initSetting('video_area', 45);
UI.initSetting('video_time', 5);
UI.initSetting('video_out_time', 3);
UI.initSetting('video_scaling', 2);
Expand Down Expand Up @@ -1405,13 +1410,15 @@ const UI = {
if (val === null) {
val = WebUtil.readSetting(name, defVal);
}
val = UI.clampSetting(name, val);
WebUtil.setSetting(name, val);
UI.updateSetting(name);
return val;
},

// Set the new value, update and disable form control setting
forceSetting(name, val, disable=true) {
val = UI.clampSetting(name, val);
WebUtil.setSetting(name, val);
UI.updateSetting(name);
if (disable) {
Expand All @@ -1426,7 +1433,8 @@ const UI = {
// updates from control to current cookie setting.
updateSetting(name) {
// Update the settings control
let value = UI.getSetting(name);
let value = UI.clampSetting(name, UI.getSetting(name));
WebUtil.setSetting(name, value);

const ctrl = document.getElementById('noVNC_setting_' + name);
if (!ctrl) return;
Expand Down Expand Up @@ -1463,6 +1471,7 @@ const UI = {
} else {
val = ctrl.value;
}
val = UI.clampSetting(name, val);
WebUtil.writeSetting(name, val);
Log.Debug("Setting saved '" + name + "=" + val + "'");
return val;
Expand All @@ -1486,6 +1495,20 @@ const UI = {
return val;
},

clampSetting(name, value) {
const range = SETTING_RANGES[name];
if (range === undefined || value === null || typeof value === 'undefined') {
return value;
}

let numberValue = parseInt(value);
if (!Number.isInteger(numberValue)) {
numberValue = range.min;
}

return Math.min(Math.max(numberValue, range.min), range.max);
},

getSettingElement(name) {
return document.getElementById('noVNC_setting_' + name);
},
Expand Down Expand Up @@ -1548,7 +1571,7 @@ const UI = {
UI.updateSetting('jpeg_video_quality', 5);
UI.updateSetting('webp_video_quality', 5);
UI.updateSetting('video_quality', 2);
UI.updateSetting('video_area', 65);
UI.updateSetting('video_area', 45);
UI.updateSetting('video_time', 5);
UI.updateSetting('video_out_time', 3);
UI.updateSetting('video_scaling', 2);
Expand Down Expand Up @@ -3031,7 +3054,7 @@ const UI = {
forceFramerate(fps);
UI.forceSetting('treat_lossless', 8);
UI.forceSetting('video_time', 5);
UI.forceSetting('video_area', 65);
UI.forceSetting('video_area', 45);
UI.forceSetting('video_scaling', 0);
UI.forceSetting('video_out_time', 3);
break;
Expand All @@ -3046,7 +3069,7 @@ const UI = {
forceFramerate(fps);
UI.forceSetting('treat_lossless', 7);
UI.forceSetting('video_time', 5);
UI.forceSetting('video_area', 65);
UI.forceSetting('video_area', 45);
UI.forceSetting('video_scaling', 0);
UI.forceSetting('video_out_time', 3);
break;
Expand All @@ -3063,7 +3086,7 @@ const UI = {
UI.forceSetting('max_video_resolution_y', 540);
UI.forceSetting('treat_lossless', 7);
UI.forceSetting('video_time', 5);
UI.forceSetting('video_area', 65);
UI.forceSetting('video_area', 45);
UI.forceSetting('video_scaling', 0);
UI.forceSetting('video_out_time', 3);
break;
Expand Down
22 changes: 22 additions & 0 deletions app/ui_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { MouseButtonMapper, XVNC_BUTTONS } from "../core/mousebuttonmapper.js";
import * as Log from '../core/util/logging.js';
import {showNotification} from "../core/util/notifications";

const SETTING_RANGES = {
video_area: { min: 1, max: 100 },
video_time: { min: 0, max: 60 },
video_out_time: { min: 1, max: 100 },
};

const UI = {
connected: false,
screenID: null,
Expand Down Expand Up @@ -130,6 +136,7 @@ const UI = {
if ((val === 'undefined' || val === null) && default_value !== 'undefined' && default_value !== null) {
val = default_value;
}
val = UI.clampSetting(name, val);
if (typeof val !== 'undefined' && val !== null && isBool) {
if (val.toString().toLowerCase() in {'0': 1, 'no': 1, 'false': 1}) {
val = false;
Expand All @@ -140,6 +147,20 @@ const UI = {
return val;
},

clampSetting(name, value) {
const range = SETTING_RANGES[name];
if (range === undefined || value === null || typeof value === 'undefined') {
return value;
}

let numberValue = parseInt(value);
if (!Number.isInteger(numberValue)) {
numberValue = range.min;
}

return Math.min(Math.max(numberValue, range.min), range.max);
},

connect() {
let details = null
const initialAutoPlacementValue = window.localStorage.getItem('autoPlacement')
Expand Down Expand Up @@ -418,6 +439,7 @@ const UI = {
if (val === null) {
val = WebUtil.readSetting(name, defVal);
}
val = UI.clampSetting(name, val);
WebUtil.setSetting(name, val);
return val;
},
Expand Down
14 changes: 7 additions & 7 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export default class RFB extends EventTargetMixin {
this._preferBandwidth = true;
this._dynamicQualityMin = 3;
this._dynamicQualityMax = 9;
this._videoArea = 65;
this._videoArea = 45;
this._pendingVideoQualityRefresh = false;
this._videoTime = 5;
this._videoOutTime = 3;
Expand Down Expand Up @@ -564,8 +564,8 @@ export default class RFB extends EventTargetMixin {
return this._videoArea;
}
set videoArea(area) {
if (!Number.isInteger(area) || area < 0 || area > 100) {
Log.Error("video area must be an integer between 0 and 100");
if (!Number.isInteger(area) || area < 1 || area > 100) {
Log.Error("video area must be an integer between 1 and 100");
return;
}

Expand All @@ -581,8 +581,8 @@ export default class RFB extends EventTargetMixin {
return this._videoTime;
}
set videoTime(value) {
if (!Number.isInteger(value) || value < 0 || value > 100) {
Log.Error("video time must be an integer between 0 and 100");
if (!Number.isInteger(value) || value < 0 || value > 60) {
Log.Error("video time must be an integer between 0 and 60");
return;
}

Expand All @@ -598,8 +598,8 @@ export default class RFB extends EventTargetMixin {
return this._videoOutTime;
}
set videoOutTime(value) {
if (!Number.isInteger(value) || value < 0 || value > 100) {
Log.Error("video out time must be an integer between 0 and 100");
if (!Number.isInteger(value) || value < 1 || value > 100) {
Log.Error("video out time must be an integer between 1 and 100");
return;
}

Expand Down
6 changes: 3 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ <h1 class="noVNC_logo">
</li>
<li>
<label for="noVNC_setting_video_area">Video Area:</label>
<input id="noVNC_setting_video_area" type="range" min="0" max="100" value="65" onchange="noVNC_setting_video_area_output.value=value">
<output id="noVNC_setting_video_area_output">65</output>
<input id="noVNC_setting_video_area" type="range" min="1" max="100" value="45" onchange="noVNC_setting_video_area_output.value=value">
<output id="noVNC_setting_video_area_output">45</output>
</li>
<li>
<label for="noVNC_setting_video_time">Video Time:</label>
Expand All @@ -428,7 +428,7 @@ <h1 class="noVNC_logo">
</li>
<li>
<label for="noVNC_setting_video_out_time">Video Out Time:</label>
<input id="noVNC_setting_video_out_time" type="range" min="0" max="60" value="3" onchange="noVNC_setting_video_out_time_output.value=value">
<input id="noVNC_setting_video_out_time" type="range" min="1" max="100" value="3" onchange="noVNC_setting_video_out_time_output.value=value">
<output id="noVNC_setting_video_out_time_output">3</output>
</li>
<li>
Expand Down