From 5b746e4a4d8a5534aca4d9e38ff36d1d19d4af7e Mon Sep 17 00:00:00 2001 From: Sergey Volkov Date: Mon, 22 Feb 2021 19:43:22 +0300 Subject: [PATCH] Add screen power mode command refs #65 --- .../controlMessage/CommandControlMessage.ts | 10 ++++++ src/app/toolbox/DroidMoreBox.ts | 32 +++++++++++++++++-- src/style/app.css | 5 +++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/app/controlMessage/CommandControlMessage.ts b/src/app/controlMessage/CommandControlMessage.ts index 29ae2c4e..11774d0a 100644 --- a/src/app/controlMessage/CommandControlMessage.ts +++ b/src/app/controlMessage/CommandControlMessage.ts @@ -70,6 +70,16 @@ export class CommandControlMessage extends ControlMessage { return event; } + public static createSetScreenPowerModeCommand(mode: boolean): CommandControlMessage { + const event = new CommandControlMessage(ControlMessage.TYPE_SET_SCREEN_POWER_MODE); + let offset = 0; + const buffer = Buffer.alloc(1 + 1); + offset = buffer.writeInt8(event.type, offset); + buffer.writeUInt8(mode ? 1 : 0, offset); + event.buffer = buffer; + return event; + } + public static createPushFileCommand(params: FilePushParams): CommandControlMessage { const { id, fileName, fileSize, chunk, state } = params; diff --git a/src/app/toolbox/DroidMoreBox.ts b/src/app/toolbox/DroidMoreBox.ts index edab9168..e63349f3 100644 --- a/src/app/toolbox/DroidMoreBox.ts +++ b/src/app/toolbox/DroidMoreBox.ts @@ -169,6 +169,31 @@ export class DroidMoreBox { } DroidMoreBox.wrap('p', commands, moreBox); + const screenPowerModeId = `screen_power_mode_${udid}_${playerName}_${displayId}`; + const screenPowerModeLabel = document.createElement('label'); + screenPowerModeLabel.style.display = 'none'; + const labelTextPrefix = 'Mode'; + const buttonTextPrefix = 'Set screen power mode'; + const screenPowerModeCheck = document.createElement('input'); + screenPowerModeCheck.type = 'checkbox'; + let mode = (screenPowerModeCheck.checked = false) ? 'ON' : 'OFF'; + screenPowerModeCheck.id = screenPowerModeLabel.htmlFor = screenPowerModeId; + screenPowerModeLabel.innerText = `${labelTextPrefix} ${mode}`; + screenPowerModeCheck.onchange = () => { + mode = screenPowerModeCheck.checked ? 'ON' : 'OFF'; + screenPowerModeLabel.innerText = `${labelTextPrefix} ${mode}`; + sendScreenPowerModeButton.innerText = `${buttonTextPrefix} ${mode}`; + }; + const sendScreenPowerModeButton = document.createElement('button'); + sendScreenPowerModeButton.innerText = `${buttonTextPrefix} ${mode}`; + sendScreenPowerModeButton.onclick = () => { + const message = CommandControlMessage.createSetScreenPowerModeCommand(screenPowerModeCheck.checked); + client.sendMessage(message); + }; + DroidMoreBox.wrap('p', [screenPowerModeCheck, screenPowerModeLabel, sendScreenPowerModeButton], moreBox, [ + 'flex-center', + ]); + const qualityId = `show_video_quality_${udid}_${playerName}_${displayId}`; const qualityLabel = document.createElement('label'); const qualityCheck = document.createElement('input'); @@ -177,7 +202,7 @@ export class DroidMoreBox { qualityCheck.id = qualityId; qualityLabel.htmlFor = qualityId; qualityLabel.innerText = 'Show quality stats'; - DroidMoreBox.wrap('p', [qualityCheck, qualityLabel], moreBox); + DroidMoreBox.wrap('p', [qualityCheck, qualityLabel], moreBox, ['flex-center']); qualityCheck.onchange = () => { player.setShowQualityStats(qualityCheck.checked); }; @@ -257,8 +282,11 @@ export class DroidMoreBox { document.execCommand('copy'); } - private static wrap(tagName: string, elements: HTMLElement[], parent: HTMLElement): void { + private static wrap(tagName: string, elements: HTMLElement[], parent: HTMLElement, opt_classes?: string[]): void { const wrap = document.createElement(tagName); + if (opt_classes) { + wrap.classList.add(...opt_classes); + } elements.forEach((e) => { wrap.appendChild(e); }); diff --git a/src/style/app.css b/src/style/app.css index 4490f370..017bfff3 100644 --- a/src/style/app.css +++ b/src/style/app.css @@ -91,6 +91,11 @@ body.stream { outline: none; } +.flex-center { + display: flex; + align-items: center; +} + .wait { cursor: wait; }