Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop name improvements #1289

Merged
merged 3 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import Keyboard from "../core/input/keyboard.js";
import RFB from "../core/rfb.js";
import * as WebUtil from "./webutil.js";

const PAGE_TITLE = "noVNC";

const UI = {

connected: false,
Expand Down Expand Up @@ -1122,6 +1124,8 @@ const UI = {
UI.showStatus(_("Disconnected"), 'normal');
}

document.title = PAGE_TITLE;

UI.openControlbar();
UI.openConnectPanel();
},
Expand Down Expand Up @@ -1615,7 +1619,7 @@ const UI = {
updateDesktopName(e) {
UI.desktopName = e.detail.name;
// Display the desktop name in the document title
document.title = e.detail.name + " - noVNC";
document.title = e.detail.name + " - " + PAGE_TITLE;
},

bell(e) {
Expand Down
1 change: 1 addition & 0 deletions core/encodings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const encodings = {
pseudoEncodingLastRect: -224,
pseudoEncodingCursor: -239,
pseudoEncodingQEMUExtendedKeyEvent: -258,
pseudoEncodingDesktopName: -307,
pseudoEncodingExtendedDesktopSize: -308,
pseudoEncodingXvp: -309,
pseudoEncodingFence: -312,
Expand Down
37 changes: 32 additions & 5 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,13 @@ export default class RFB extends EventTargetMixin {
this.focus();
}

_setDesktopName(name) {
this._fb_name = name;
this.dispatchEvent(new CustomEvent(
"desktopname",
{ detail: { name: this._fb_name } }));
}

_windowResize(event) {
// If the window resized then our screen element might have
// as well. Update the viewport dimensions.
Expand Down Expand Up @@ -1148,7 +1155,7 @@ export default class RFB extends EventTargetMixin {
/* Connection name/title */
const name_length = this._sock.rQshift32();
if (this._sock.rQwait('server init name', name_length, 24)) { return false; }
this._fb_name = decodeUTF8(this._sock.rQshiftStr(name_length));
let name = decodeUTF8(this._sock.rQshiftStr(name_length));

if (this._rfb_tightvnc) {
if (this._sock.rQwait('TightVNC extended server init header', 8, 24 + name_length)) { return false; }
Expand Down Expand Up @@ -1188,10 +1195,7 @@ export default class RFB extends EventTargetMixin {
", blue_shift: " + blue_shift);

// we're past the point where we could backtrack, so it's safe to call this
this.dispatchEvent(new CustomEvent(
"desktopname",
{ detail: { name: this._fb_name } }));

this._setDesktopName(name);
this._resize(width, height);

if (!this._viewOnly) { this._keyboard.grab(); }
Expand Down Expand Up @@ -1237,6 +1241,7 @@ export default class RFB extends EventTargetMixin {
encs.push(encodings.pseudoEncodingXvp);
encs.push(encodings.pseudoEncodingFence);
encs.push(encodings.pseudoEncodingContinuousUpdates);
encs.push(encodings.pseudoEncodingDesktopName);

if (this._fb_depth == 24) {
encs.push(encodings.pseudoEncodingCursor);
Expand Down Expand Up @@ -1503,6 +1508,9 @@ export default class RFB extends EventTargetMixin {
}
return true;

case encodings.pseudoEncodingDesktopName:
return this._handleDesktopName();

case encodings.pseudoEncodingDesktopSize:
this._resize(this._FBU.width, this._FBU.height);
return true;
Expand Down Expand Up @@ -1552,6 +1560,25 @@ export default class RFB extends EventTargetMixin {
return true;
}

_handleDesktopName() {
if (this._sock.rQwait("DesktopName", 4)) {
return false;
}

let length = this._sock.rQshift32();

if (this._sock.rQwait("DesktopName", length, 4)) {
return false;
}

let name = this._sock.rQshiftStr(length);
name = decodeUTF8(name);

this._setDesktopName(name);

return true;
}

_handleExtendedDesktopSize() {
if (this._sock.rQwait("ExtendedDesktopSize", 4)) {
return false;
Expand Down
37 changes: 30 additions & 7 deletions tests/test.rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ function push32(arr, num) {
num & 0xFF);
}

function pushString(arr, string) {
let utf8 = unescape(encodeURIComponent(string));
for (let i = 0; i < utf8.length; i++) {
arr.push(utf8.charCodeAt(i));
}
}

describe('Remote Frame Buffer Protocol Client', function () {
let clock;
let raf;
Expand Down Expand Up @@ -1446,10 +1453,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
client._sock._websocket._receive_data(new Uint8Array(data));

const name_data = [];
push32(name_data, full_opts.name.length);
for (let i = 0; i < full_opts.name.length; i++) {
name_data.push(full_opts.name.charCodeAt(i));
}
let name_len = [];
pushString(name_data, full_opts.name);
push32(name_len, name_data.length);

client._sock._websocket._receive_data(new Uint8Array(name_len));
client._sock._websocket._receive_data(new Uint8Array(name_data));
}

Expand All @@ -1464,11 +1472,11 @@ describe('Remote Frame Buffer Protocol Client', function () {
it('should set the framebuffer name and call the callback', function () {
const spy = sinon.spy();
client.addEventListener("desktopname", spy);
send_server_init({ name: 'some name' }, client);
send_server_init({ name: 'som€ nam€' }, client);

expect(client._fb_name).to.equal('some name');
expect(client._fb_name).to.equal('som€ nam€');
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.name).to.equal('some name');
expect(spy.args[0][0].detail.name).to.equal('som€ nam€');
});

it('should handle the extended init message of the tight encoding', function () {
Expand Down Expand Up @@ -2128,6 +2136,21 @@ describe('Remote Frame Buffer Protocol Client', function () {
send_fbu_msg([{ x: 0, y: 0, width: 0, height: 0, encoding: -224}], [[]], client, 100);
expect(client._FBU.rects).to.equal(0);
});

it('should handle the DesktopName pseudo-encoding', function () {
let data = [];
push32(data, 13);
pushString(data, "som€ nam€");

const spy = sinon.spy();
client.addEventListener("desktopname", spy);

send_fbu_msg([{ x: 0, y: 0, width: 0, height: 0, encoding: -307 }], [data], client);

expect(client._fb_name).to.equal('som€ nam€');
expect(spy).to.have.been.calledOnce;
expect(spy.args[0][0].detail.name).to.equal('som€ nam€');
});
});
});

Expand Down