Path: blob/main/replay/backend/models/PlaybarView.ts
1030 views
import Window from '~backend/models/Window';1import Application from '~backend/Application';2import IRectangle from '~shared/interfaces/IRectangle';3import ReplayTabState from '~backend/api/ReplayTabState';4import ViewBackend from '~backend/models/ViewBackend';56export default class PlaybarView extends ViewBackend {7private readonly isReady: Promise<void>;8private tabState: ReplayTabState;9private isLoaded = false;10private playOnLoaded = false;1112constructor(window: Window) {13super(window, {14sandbox: false,15nodeIntegration: true,16enableRemoteModule: true,17});1819this.browserView.setAutoResize({20width: true,21height: false,22horizontal: false,23vertical: true,24});2526const url = Application.instance.getPageUrl('playbar');27this.isReady = this.browserView.webContents.loadURL(url);28this.updateFrontendTicks = this.updateFrontendTicks.bind(this);29}3031public async load(tabState: ReplayTabState) {32this.isLoaded = false;33this.attach();3435// remove existing listeners36if (this.tabState) this.tabState.off('tick:changes', this.updateFrontendTicks);3738this.tabState = tabState;39this.tabState.on('tick:changes', this.updateFrontendTicks);4041await this.isReady;4243this.browserView.webContents.send('ticks:load', this.tabState.getTickState());44this.isLoaded = true;45if (this.playOnLoaded) this.play();46}4748public play() {49if (!this.isLoaded) {50this.playOnLoaded = true;51} else {52this.playOnLoaded = false;53this.browserView.webContents.send('start');54}55}5657public pause() {58this.playOnLoaded = false;59this.browserView.webContents.send('pause');60}6162public changeTickOffset(offset: number) {63this.browserView.webContents.send('ticks:change-offset', offset);64}6566public onTickHover(rect: IRectangle, tickValue: number) {67if (!this.isAttached) return;68const tick = this.tabState.ticks.find(x => x.playbarOffsetPercent === tickValue);69if (!tick) return;7071const bounds = this.browserView.getBounds();72// set rect y to the top of the playbar73rect.y = bounds.y;74const commandLabel = tick.label;75const commandResult =76tick.eventType === 'command'77? this.tabState.commandsById.get(tick.commandId)78: {79duration: 0,80};81Application.instance.overlayManager.show(82'command-overlay',83this.window.browserWindow,84rect,85commandLabel,86commandResult,87);88}8990private updateFrontendTicks() {91this.browserView.webContents.send('ticks:updated', this.tabState.getTickState());92}93}949596