From a7c9fda3077070da36bee9b8a44bb2e3d047b3d3 Mon Sep 17 00:00:00 2001 From: sylenien Date: Wed, 30 Nov 2022 11:42:36 +0100 Subject: [PATCH] change(tracker): format file --- .../src/ScreenRecordingState.ts | 180 +++++++++--------- 1 file changed, 89 insertions(+), 91 deletions(-) diff --git a/tracker/tracker-assist/src/ScreenRecordingState.ts b/tracker/tracker-assist/src/ScreenRecordingState.ts index 465b21012..4a05c0f4d 100644 --- a/tracker/tracker-assist/src/ScreenRecordingState.ts +++ b/tracker/tracker-assist/src/ScreenRecordingState.ts @@ -3,123 +3,121 @@ import { recordRequestDefault, } from './ConfirmWindow/defaults.js' import type { Options as ConfirmOptions, } from './ConfirmWindow/defaults.js' export enum RecordingState { - Off, - Requested, - Recording, + Off, + Requested, + Recording, } const borderStyles = { - height: '100vh', - width: '100vw', - border: '2px dashed red', - left: 0, - top: 0, - position: 'fixed', - 'pointer-events': 'none', + height: '100vh', + width: '100vw', + border: '2px dashed red', + left: 0, + top: 0, + position: 'fixed', + 'pointer-events': 'none', } const buttonStyles = { - cursor: 'pointer', - color: 'white', - position: 'fixed', - bottom: '0', - left: 'calc(50vw - 60px)', - 'font-weight': 500, - padding: '2px 4px', - background: '#394EFF', - 'border-top-right-radius': '3px', - 'border-top-left-radius': '3px', - 'text-align': 'center', + cursor: 'pointer', + color: 'white', + position: 'fixed', + bottom: '0', + left: 'calc(50vw - 60px)', + 'font-weight': 500, + padding: '2px 4px', + background: '#394EFF', + 'border-top-right-radius': '3px', + 'border-top-left-radius': '3px', + 'text-align': 'center', } export default class ScreenRecordingState { - private status = RecordingState.Off - private recordingAgent: string - private overlayAdded = false + private status = RecordingState.Off + private recordingAgent: string + private overlayAdded = false + private uiComponents: [HTMLDivElement, HTMLDivElement] - constructor( - private readonly confirmOptions: ConfirmOptions, - ) {} + constructor(private readonly confirmOptions: ConfirmOptions) { } - public get isActive() { - return this.status !== RecordingState.Off - } + public get isActive() { + return this.status !== RecordingState.Off + } - private confirm: ConfirmWindow | null = null + private confirm: ConfirmWindow | null = null - public requestRecording = (id: string, onAccept: () => void, onDeny: () => void) => { - if (this.isActive) return - this.status = RecordingState.Requested + public requestRecording = ( + id: string, + onAccept: () => void, + onDeny: () => void, + ) => { + if (this.isActive) return + this.status = RecordingState.Requested - this.confirm = new ConfirmWindow( - recordRequestDefault(this.confirmOptions), - ) - this.confirm - .mount() - .then((allowed) => { - if (allowed) { - this.acceptRecording() + this.confirm = new ConfirmWindow(recordRequestDefault(this.confirmOptions)) + this.confirm + .mount() + .then((allowed) => { + if (allowed) { + this.acceptRecording() onAccept() - this.recordingAgent = id - } else { + this.recordingAgent = id + } else { this.rejectRecording() onDeny() - } - }) - .then(() => { - this.confirm?.remove() - }) - .catch((e) => { - this.confirm?.remove() - console.error(e) - }) - } + } + }) + .then(() => { + this.confirm?.remove() + }) + .catch((e) => { + this.confirm?.remove() + console.error(e) + }) + } - private readonly acceptRecording = () => { - if (!this.overlayAdded) { - const stopButton = window.document.createElement('div') - stopButton.onclick = () => this.rejectRecording() - Object.assign(stopButton.style, buttonStyles) - stopButton.textContent = 'Stop Recording' - stopButton.className = 'or-recording-button' - stopButton.setAttribute('data-openreplay-obscured', '') - stopButton.setAttribute('data-openreplay-hidden', '') - stopButton.setAttribute('data-openreplay-ignore', '') - window.document.body.appendChild(stopButton) + private readonly acceptRecording = () => { + if (!this.overlayAdded) { + const stopButton = window.document.createElement('div') + stopButton.onclick = () => this.rejectRecording() + Object.assign(stopButton.style, buttonStyles) + stopButton.textContent = 'Stop Recording' + stopButton.className = 'or-recording-button' + stopButton.setAttribute('data-openreplay-obscured', '') + stopButton.setAttribute('data-openreplay-hidden', '') + stopButton.setAttribute('data-openreplay-ignore', '') + window.document.body.appendChild(stopButton) - const borderWindow = window.document.createElement('div') - Object.assign(borderWindow.style, borderStyles) - borderWindow.className = 'or-recording-border' - borderWindow.setAttribute('data-openreplay-obscured', '') - borderWindow.setAttribute('data-openreplay-hidden', '') - borderWindow.setAttribute('data-openreplay-ignore', '') - window.document.body.appendChild(borderWindow) + const borderWindow = window.document.createElement('div') + Object.assign(borderWindow.style, borderStyles) + borderWindow.className = 'or-recording-border' + borderWindow.setAttribute('data-openreplay-obscured', '') + borderWindow.setAttribute('data-openreplay-hidden', '') + borderWindow.setAttribute('data-openreplay-ignore', '') + window.document.body.appendChild(borderWindow) - this.overlayAdded = true - } - this.status = RecordingState.Recording - } + this.overlayAdded = true - public readonly stopAgentRecording = (id) => { - if (id === this.recordingAgent) { - this.rejectRecording() - } - } + this.uiComponents = [stopButton, borderWindow,] + } + this.status = RecordingState.Recording + } + + public readonly stopAgentRecording = (id) => { + if (id === this.recordingAgent) { + this.rejectRecording() + } + } public readonly stopRecording = () => { this.rejectRecording() } - private readonly rejectRecording = () => { - this.confirm?.remove() - this.status = RecordingState.Off + private readonly rejectRecording = () => { + this.confirm?.remove() + this.status = RecordingState.Off - const borders = window.document.querySelector('.or-recording-border') - const button = window.document.querySelector('.or-recording-button') - if (borders && button) { - borders.parentElement?.removeChild(borders) - button.parentElement?.removeChild(button) - } - } + this.uiComponents.forEach((el) => el.parentElement?.removeChild(el)) + } }