Skip to content

Commit

Permalink
Add screen power mode command
Browse files Browse the repository at this point in the history
refs #65
  • Loading branch information
drauggres committed Feb 22, 2021
1 parent 3227bc6 commit 5b746e4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/app/controlMessage/CommandControlMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
32 changes: 30 additions & 2 deletions src/app/toolbox/DroidMoreBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
};
Expand Down Expand Up @@ -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);
});
Expand Down
5 changes: 5 additions & 0 deletions src/style/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ body.stream {
outline: none;
}

.flex-center {
display: flex;
align-items: center;
}

.wait {
cursor: wait;
}
Expand Down

0 comments on commit 5b746e4

Please sign in to comment.