Skip to content

Commit

Permalink
Fix linting errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbound committed Feb 4, 2024
1 parent 2c11e27 commit 183a7bc
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 90 deletions.
77 changes: 37 additions & 40 deletions app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,10 @@ const UI = {
},

/**
* @param {string} text
* @param { "normal" | "info" | "warn" | "warning" | "error" } statusType
* @param {number} time
* @returns
* @param {string} text
* @param { "normal" | "info" | "warn" | "warning" | "error" } statusType
* @param {number} time
* @returns
*/
showStatus(text, statusType, time) {
const statusElem = document.getElementById('noVNC_status');
Expand Down Expand Up @@ -1614,44 +1614,41 @@ const UI = {
* TOUCHPAD
* ------v------*/

toggleTouchpadMode() {
if (!UI.rfb) return;

UI.rfb.touchpadMode = !UI.rfb.touchpadMode;
WebUtil.writeSetting('touchpad_mode', UI.rfb.touchpadMode);
UI.updateTouchpadMode();
UI.updateViewDrag();
},

updateTouchpadMode() {
if (UI.rfb.touchpadMode) {
UI.rfb.dragViewport = false;

UI.forceSetting('resize', 'off');
UI.forceSetting('view_clip', true);
UI.forceSetting('show_dot', true);

UI.rfb.clipViewport = true;
UI.rfb.scaleViewport = false;
UI.rfb.resizeSession = false;
UI.rfb.showDotCursor = true;
}
else {
UI.enableSetting('resize');
UI.enableSetting('view_clip');
UI.enableSetting('show_dot');
}
toggleTouchpadMode() {
if (!UI.rfb) return;

UI.rfb.touchpadMode = !UI.rfb.touchpadMode;
WebUtil.writeSetting('touchpad_mode', UI.rfb.touchpadMode);
UI.updateTouchpadMode();
UI.updateViewDrag();
},

UI.updateViewDrag
updateTouchpadMode() {
if (UI.rfb.touchpadMode) {
UI.rfb.dragViewport = false;

UI.forceSetting('resize', 'off');
UI.forceSetting('view_clip', true);
UI.forceSetting('show_dot', true);

UI.rfb.clipViewport = true;
UI.rfb.scaleViewport = false;
UI.rfb.resizeSession = false;
UI.rfb.showDotCursor = true;
} else {
UI.enableSetting('resize');
UI.enableSetting('view_clip');
UI.enableSetting('show_dot');
}

const touchpadButton = document.getElementById('noVNC_touchpad_button');
if (UI.rfb.touchpadMode) {
touchpadButton.classList.add("noVNC_selected");
} else {
touchpadButton.classList.remove("noVNC_selected");
}
},

const touchpadButton = document.getElementById('noVNC_touchpad_button');
if (UI.rfb.touchpadMode) {
touchpadButton.classList.add("noVNC_selected");
} else {
touchpadButton.classList.remove("noVNC_selected");
}
},

/* ------^-------
* /TOUCHPAD
* ==============
Expand Down
8 changes: 4 additions & 4 deletions core/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,16 @@ export default class Display {
/**
* Attempt to move the viewport by the specified amounts
* and returns the amount of actual position change.
* @param {number} moveByX
* @param {number} moveByY
* @param {number} moveByX
* @param {number} moveByY
* @return {{ x: number, y: number }}
*/
viewportTryMoveBy(moveByX, moveByY) {
if (moveByX === 0 && moveByY === 0) {
return {
x: 0,
y: 0
}
};
}

const vpX = this._viewportLoc.x;
Expand All @@ -116,7 +116,7 @@ export default class Display {
return {
x: this._viewportLoc.x - vpX,
y: this._viewportLoc.y - vpY
}
};
}

viewportChangePos(deltaX, deltaY) {
Expand Down
12 changes: 6 additions & 6 deletions core/input/gesturehandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class GestureHandler {
}

/**
* @param {boolean} enabled
* @param {boolean} enabled
*/
set touchpadMode(enabled) {
this._touchpadMode = enabled;
Expand Down Expand Up @@ -115,8 +115,8 @@ export default class GestureHandler {
}

/**
*
* @param {TouchEvent} e
*
* @param {TouchEvent} e
*/
_eventHandler(e) {
let fn;
Expand Down Expand Up @@ -179,7 +179,7 @@ export default class GestureHandler {
movementY: 0,
angle: 0,
});

switch (this._tracked.length) {
case 1:
this._startLongpressTimeout();
Expand All @@ -199,7 +199,7 @@ export default class GestureHandler {
}
}

_touchMove(id, x, y) {
_touchMove(id, x, y) {
let touch = this._tracked.find(t => t.id === id);

// If this is an update for a touch we're not tracking, ignore it
Expand Down Expand Up @@ -495,7 +495,7 @@ export default class GestureHandler {
detail['clientX'] = pos.x;
detail['clientY'] = pos.y;

if (this._touchpadMode &&
if (this._touchpadMode &&
this._tracked.length === 1) {

const touch = this._tracked[0];
Expand Down
66 changes: 30 additions & 36 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default class RFB extends EventTargetMixin {
this._viewportHasMoved = false;
this._accumulatedWheelDeltaX = 0;
this._accumulatedWheelDeltaY = 0;

// Gesture state
this._gestureLastTapTime = null;
this._gestureFirstDoubleTapEv = null;
Expand Down Expand Up @@ -413,7 +413,7 @@ export default class RFB extends EventTargetMixin {
this._sendEncodings();
}
}

/**
* @returns {boolean}
*/
Expand All @@ -422,7 +422,7 @@ export default class RFB extends EventTargetMixin {
}

/**
* @param {boolean} enabled
* @param {boolean} enabled
*/
set touchpadMode(enabled) {
if (!this._gestures) {
Expand Down Expand Up @@ -556,7 +556,7 @@ export default class RFB extends EventTargetMixin {
const container = document.getElementById('noVNC_container');
const containerBounds = container.getBoundingClientRect();
const x = containerBounds.left + (containerBounds.width * .5);
const y = containerBounds.top + (containerBounds.height * .5)
const y = containerBounds.top + (containerBounds.height * .5);
this._cursor.move(x, y);

const elementPos = clientToElement(x, y, this._canvas);
Expand Down Expand Up @@ -1299,8 +1299,7 @@ export default class RFB extends EventTargetMixin {
case 'onetap':
if (this._touchpadMode) {
this._handleTouchpadOneTapEvent();
}
else {
} else {
this._handleTapEvent(ev, 0x1);
}
break;
Expand All @@ -1326,12 +1325,12 @@ export default class RFB extends EventTargetMixin {
// sequence.
if (this._touchpadMode) {
if (this._touchpadTapTimeoutId > 0) {
this._clearTouchpadTapTimeoutId();
this._isTouchpadDragging = true;
this._mouseButtonMask = 0x1;
const cursorPos = this._getCursorPositionToCanvas();
this._sendMouse(cursorPos.x, cursorPos.y, 0x1);
}
this._clearTouchpadTapTimeoutId();
this._isTouchpadDragging = true;
this._mouseButtonMask = 0x1;
const cursorPos = this._getCursorPositionToCanvas();
this._sendMouse(cursorPos.x, cursorPos.y, 0x1);
}
break;
}
this._fakeMouseMove(ev, pos.x, pos.y);
Expand All @@ -1343,8 +1342,7 @@ export default class RFB extends EventTargetMixin {
if (this._touchpadMode) {
const cursorPos = this._getCursorPositionToCanvas();
this._handleMouseButton(cursorPos.x, cursorPos.y, true, 0x4);
}
else {
} else {
this._fakeMouseMove(ev, pos.x, pos.y);
this._handleMouseButton(pos.x, pos.y, true, 0x4);
}
Expand Down Expand Up @@ -1382,8 +1380,7 @@ export default class RFB extends EventTargetMixin {
// current position, not to where the touch currently is.
if (this._touchpadMode) {
this._handleTouchpadMove(ev.detail.movementX, ev.detail.movementY);
}
else {
} else {
this._fakeMouseMove(ev, pos.x, pos.y);
}
break;
Expand Down Expand Up @@ -1427,7 +1424,7 @@ export default class RFB extends EventTargetMixin {
// We don't know if the mouse was moved so we need to move it
// every update.
this._fakeMouseMove(ev, pos.x, pos.y);

if (Math.abs(magnitude - this._gestureLastMagnitudeX) > GESTURE_ZOOMSENS) {
this._handleKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
while ((magnitude - this._gestureLastMagnitudeX) > GESTURE_ZOOMSENS) {
Expand Down Expand Up @@ -1472,8 +1469,7 @@ export default class RFB extends EventTargetMixin {
if (this._touchpadMode) {
const cursorPos = this._getCursorPositionToCanvas();
this._handleMouseButton(cursorPos.x, cursorPos.y, false, 0x4);
}
else {
} else {
this._fakeMouseMove(ev, pos.x, pos.y);
this._handleMouseButton(pos.x, pos.y, false, 0x4);
}
Expand All @@ -1484,10 +1480,10 @@ export default class RFB extends EventTargetMixin {
}

// TouchpadMode Private Methods

/**
* @param {number} movementX
* @param {number} movementY
* @param {number} movementX
* @param {number} movementY
*/
_handleTouchpadMove(movementX, movementY) {

Expand All @@ -1511,12 +1507,10 @@ export default class RFB extends EventTargetMixin {

// See if the cursor has moved outside the center deadzone.
const deadzone = this._getTouchpadCursorDeadZone();
const moveViewportX =
Math.min(safeX - deadzone.left, 0) +
const moveViewportX = Math.min(safeX - deadzone.left, 0) +
Math.max(safeX - deadzone.right, 0);

const moveViewportY =
Math.min(safeY - deadzone.top, 0) +
const moveViewportY = Math.min(safeY - deadzone.top, 0) +
Math.max(safeY - deadzone.bottom, 0);

// Try moving the viewport, getting the actual amount it moved.
Expand All @@ -1534,8 +1528,8 @@ export default class RFB extends EventTargetMixin {
const posFromCanvas = clientToElement(safeX, safeY, this._canvas);
const hotspot = this._cursor.hotspot;
this._sendMouse(
posFromCanvas.x + hotspot.x,
posFromCanvas.y + hotspot.y,
posFromCanvas.x + hotspot.x,
posFromCanvas.y + hotspot.y,
this._mouseButtonMask);
}

Expand All @@ -1547,7 +1541,7 @@ export default class RFB extends EventTargetMixin {
this._sendTouchpadTap();
return;
}

this._touchpadTapTimeoutId = window.setTimeout(() => {
this._clearTouchpadTapTimeoutId();
this._sendTouchpadTap();
Expand All @@ -1556,8 +1550,8 @@ export default class RFB extends EventTargetMixin {
}

/**
*
* @param {number} magnitude
*
* @param {number} magnitude
*/
_handleTouchpadPinchZoom(magnitude) {
if (this._lastTouchpadPinchMagnitude > 0) {
Expand All @@ -1570,16 +1564,16 @@ export default class RFB extends EventTargetMixin {
// Capture the current viewport size.
const originalVpW = this._display.viewportLocation.w;
const originalVpH = this._display.viewportLocation.h;

// Change viewport size based on new scale.
const newWidth = container.clientWidth * this._currentPinchScale;
const newHeight = container.clientHeight * this._currentPinchScale;
this._display.viewportChangeSize(newWidth, newHeight);

// Apply scaling to CSS.
const visualScale = container.clientWidth / newWidth;
this._display.rescale(visualScale);

// Adjust viewport location to keep it centered.
const moveX = (originalVpW - this._display.viewportLocation.w) / 2;
const moveY = (originalVpH - this._display.viewportLocation.h) / 2;
Expand Down Expand Up @@ -1644,7 +1638,7 @@ export default class RFB extends EventTargetMixin {
const canvasCenter = {
x: canvasBounds.width * .5,
y: canvasBounds.height * .5
}
};
const xFromCenter = canvasBounds.width * .1;
const yFromCenter = canvasBounds.height * .1;
const innerWidth = xFromCenter * 2;
Expand All @@ -1657,7 +1651,7 @@ export default class RFB extends EventTargetMixin {
left: canvasCenter.x - xFromCenter,
right: canvasCenter.x + xFromCenter,
width: innerWidth
}
};
}

// Message Handlers
Expand Down
2 changes: 1 addition & 1 deletion core/util/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function isTouchDevice() {
// required for MS Surface
(navigator.maxTouchPoints > 0) ||
(navigator.msMaxTouchPoints > 0);
};
}

// The goal is to find a certain physical width, the devicePixelRatio
// brings us a bit closer but is not optimal.
Expand Down
6 changes: 3 additions & 3 deletions core/util/cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ export default class Cursor {
return this._position;
}

/**
/**
* @returns {{ x: number, y: number }}
*/
get hotspot() {
get hotspot() {
return this._hotSpot;
}

attach(target) {
if (this._target) {
this.detach();
Expand Down

0 comments on commit 183a7bc

Please sign in to comment.