Adding changes from pull request 118 (#138)

This commit is contained in:
rspruel 2025-06-13 05:54:15 -04:00 committed by GitHub
parent bed156c565
commit 31cf849134
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 5 deletions

View File

@ -32,7 +32,7 @@ import "core-js/stable";
import "regenerator-runtime/runtime"; import "regenerator-runtime/runtime";
import * as Log from '../core/util/logging.js'; import * as Log from '../core/util/logging.js';
import _, { l10n } from './localization.js'; import _, { l10n } from './localization.js';
import { isTouchDevice, isSafari, hasScrollbarGutter, dragThreshold, supportsBinaryClipboard, isFirefox, isWindows, isIOS, supportsPointerLock } import { isTouchDevice, isSafari, hasScrollbarGutter, dragThreshold, supportsBinaryClipboard, isFirefox, isWindows, isIOS, supportsPointerLock, supportsKeyboardLock }
from '../core/util/browser.js'; from '../core/util/browser.js';
import { setCapture, getPointerEvent } from '../core/util/events.js'; import { setCapture, getPointerEvent } from '../core/util/events.js';
import KeyTable from "../core/input/keysym.js"; import KeyTable from "../core/input/keysym.js";
@ -1551,7 +1551,7 @@ const UI = {
//keep alive for websocket connection to stay open, since we may not control reverse proxies //keep alive for websocket connection to stay open, since we may not control reverse proxies
//send a keep alive within a window that we control //send a keep alive within a window that we control
UI._sessionTimeoutInterval = setInterval(function() { UI._sessionTimeoutInterval = setInterval(function() {
if (UI.rfb) { if (UI.rfb) {
const timeSinceLastActivityInS = (Date.now() - UI.rfb.lastActiveAt) / 1000; const timeSinceLastActivityInS = (Date.now() - UI.rfb.lastActiveAt) / 1000;
let idleDisconnectInS = 1200; //20 minute default let idleDisconnectInS = 1200; //20 minute default
if (Number.isFinite(parseFloat(UI.rfb.idleDisconnect))) { if (Number.isFinite(parseFloat(UI.rfb.idleDisconnect))) {
@ -1869,6 +1869,9 @@ const UI = {
document.mozFullScreenElement || // currently working methods document.mozFullScreenElement || // currently working methods
document.webkitFullscreenElement || document.webkitFullscreenElement ||
document.msFullscreenElement) { document.msFullscreenElement) {
if (supportsKeyboardLock) {
navigator.keyboard.unlock();
}
if (document.exitFullscreen) { if (document.exitFullscreen) {
document.exitFullscreen(); document.exitFullscreen();
} else if (document.mozCancelFullScreen) { } else if (document.mozCancelFullScreen) {
@ -1888,8 +1891,11 @@ const UI = {
} else if (document.body.msRequestFullscreen) { } else if (document.body.msRequestFullscreen) {
document.body.msRequestFullscreen(); document.body.msRequestFullscreen();
} }
if(navigator.keyboard && navigator.keyboard.lock){ // No need to explicitly ask for permission,
navigator.keyboard.lock(['Escape']); // but it's expected that user grant it since Chromium 131.
// See https://developer.chrome.com/blog/keyboard-lock-pointer-lock-permission
if (supportsKeyboardLock) {
navigator.keyboard.lock();
} }
} }
UI.updateFullscreenButton(); UI.updateFullscreenButton();
@ -3028,4 +3034,4 @@ if (l10n.language === "en" || l10n.dictionary !== undefined) {
.then(UI.prime); .then(UI.prime);
} }
export default UI; export default UI;

View File

@ -27,6 +27,8 @@ window.addEventListener('touchstart', function onFirstTouch() {
// brings us a bit closer but is not optimal. // brings us a bit closer but is not optimal.
export let dragThreshold = 10 * (window.devicePixelRatio || 1); export let dragThreshold = 10 * (window.devicePixelRatio || 1);
export const supportsKeyboardLock = ('keyboard' in navigator && 'lock' in navigator.keyboard && typeof(navigator.keyboard.lock) === 'function');
let _supportsCursorURIs = false; let _supportsCursorURIs = false;
try { try {