-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/add sessionrecording extension #148
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
Changes from all commits
08a89c4
5741d70
7f7b773
bb640f4
44ad058
20f5801
d68f3bf
847fd8d
bf4bade
0e75ea0
1e083a9
bac1a96
80454e0
0fa3673
486c4c9
15486ce
91aed53
3a7b317
7185c69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,108 @@ | ||
| import { useState } from 'react'; | ||
| import { Group, Select, Stack, Title } from '@mantine/core'; | ||
| import { useEffect, useMemo, useState } from 'react'; | ||
| import { | ||
| Alert, | ||
| CheckIcon, | ||
| Group, | ||
| Select, | ||
| SelectProps, | ||
| Stack, | ||
| Text, | ||
| Title | ||
| } from '@mantine/core'; | ||
|
|
||
| import { BoolInput } from '@/components/Input/BoolInput'; | ||
| import { NumericInput } from '@/components/Input/NumericInput/NumericInput'; | ||
| import { useSubscribeToProperty } from '@/hooks/properties'; | ||
| import { useSubscribeToSessionRecording } from '@/hooks/topicSubscriptions'; | ||
| import { useAppSelector } from '@/redux/hooks'; | ||
| import { useAppDispatch, useAppSelector } from '@/redux/hooks'; | ||
| import { updateSessionRecordingSettings } from '@/redux/sessionrecording/sessionRecordingSlice'; | ||
|
|
||
| import { KeybindButtons } from '../KeybindsPanel/KeybindButtons'; | ||
|
|
||
| import { PlaybackPauseButton } from './Playback/PlaybackPauseButton'; | ||
| import { PlaybackPlayButton } from './Playback/PlaybackPlayButton'; | ||
| import { PlaybackResumeButton } from './Playback/PlaybackResumeButton'; | ||
| import { PlaybackStopButton } from './Playback/PlaybackStopButton'; | ||
| import { RecordingState } from './types'; | ||
| import { parseFilename } from './util'; | ||
|
|
||
| export function PlaySession() { | ||
| const [loopPlayback, setLoopPlayback] = useState(false); | ||
| const [shouldOutputFrames, setShouldOutputFrames] = useState(false); | ||
| const [outputFramerate, setOutputFramerate] = useState(60); | ||
| const [filenamePlayback, setFilenamePlayback] = useState<string | null>(null); | ||
| const { latestFile, hideGuiOnPlayback, hideDashboardsOnPlayback } = useAppSelector( | ||
| (state) => state.sessionRecording.settings | ||
| ); | ||
| const [playbackFile, setPlaybackFile] = useState<string | null>(latestFile); | ||
| const keybinds = useAppSelector((state) => state.actions.keybinds); | ||
|
|
||
| const fileList = useAppSelector((state) => state.sessionRecording.files); | ||
| const recordingState = useSubscribeToSessionRecording(); | ||
| const dispatch = useAppDispatch(); | ||
|
|
||
| // Subscribe to Properties so that the middleware will be notified on updated values | ||
| // Important! These properties have to be kept in sync with the properties used in the | ||
| // middleware | ||
| useSubscribeToProperty('Modules.CefWebGui.Visible'); | ||
| useSubscribeToProperty('RenderEngine.ShowLog'); | ||
| useSubscribeToProperty('RenderEngine.ShowVersion'); | ||
| useSubscribeToProperty('Dashboard.IsEnabled'); | ||
|
|
||
| const isIdle = recordingState === RecordingState.Idle; | ||
| const isPlayingBack = | ||
| recordingState === RecordingState.Paused || recordingState === RecordingState.Playing; | ||
|
|
||
| const isSettingsCombinationDangerous = loopPlayback && hideGuiOnPlayback; | ||
| const toggleGuiKeybind = keybinds.find( | ||
| (keybind) => keybind.action === 'os.ToggleMainGui' | ||
| ); | ||
|
|
||
| // Update the playback dropdown list to the latest recorded file | ||
| useEffect(() => { | ||
| if (latestFile) { | ||
| setPlaybackFile(latestFile); | ||
| } | ||
| }, [latestFile]); | ||
|
|
||
| // Store file duplicates in map for quick lookup | ||
| const fileCounts = useMemo(() => { | ||
| const map = new Map<string, number>(); | ||
| fileList.forEach((file) => { | ||
| const name = file.substring(0, file.lastIndexOf('.')); | ||
| map.set(name, (map.get(name) || 0) + 1); | ||
| }); | ||
|
|
||
| return map; | ||
| }, [fileList]); | ||
|
|
||
| const fileListSelectData = useMemo(() => { | ||
| return fileList.map((file) => { | ||
| const { filename, isFileDuplicate } = parseFilename(file, fileCounts); | ||
| const label = isFileDuplicate ? file : filename; | ||
|
|
||
| return { value: file, label: label }; | ||
| }); | ||
| }, [fileList, fileCounts]); | ||
|
|
||
| const renderSelectOption: SelectProps['renderOption'] = ({ option, checked }) => { | ||
| const file = option.value; | ||
| const { filename, extension, isFileDuplicate } = parseFilename(file, fileCounts); | ||
|
|
||
| return ( | ||
| <Group gap={'xs'}> | ||
| {checked && <CheckIcon size={12} color={'gray'} />} | ||
| <Text size={'sm'}> | ||
| {filename} | ||
| {isFileDuplicate && ( | ||
| <Text c={'dimmed'} size={'xs'} span> | ||
| {extension} | ||
| </Text> | ||
| )} | ||
| </Text> | ||
| </Group> | ||
| ); | ||
| }; | ||
|
|
||
| function onLoopPlaybackChange(shouldLoop: boolean): void { | ||
| if (shouldLoop) { | ||
| setLoopPlayback(true); | ||
|
|
@@ -75,19 +153,62 @@ export function PlaySession() { | |
| disabled={!shouldOutputFrames || !isIdle} | ||
| /> | ||
| </Group> | ||
| <BoolInput | ||
engbergandreas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| label={'Hide GUI on playback'} | ||
| value={hideGuiOnPlayback} | ||
engbergandreas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| onChange={(value) => | ||
| dispatch(updateSessionRecordingSettings({ hideGuiOnPlayback: value })) | ||
| } | ||
| info={ | ||
| 'When checked, hides the GUI during playback. It will reappear after the recording ends.' | ||
| } | ||
| disabled={isPlayingBack} | ||
| /> | ||
| {isSettingsCombinationDangerous && ( | ||
| <Alert variant={'light'} color={'orange'} title={'Warning'}> | ||
| <Text mb={'xs'}> | ||
| Caution: Enabling both{' '} | ||
| <Text fs={'italic'} span inherit> | ||
| Loop playback | ||
| </Text>{' '} | ||
| and{' '} | ||
| <Text fs={'italic'} span inherit> | ||
| Hide GUI | ||
| </Text>{' '} | ||
| will cause the interface to remain hidden indefinitely during playback. To | ||
| reveal the GUI again, press: | ||
| </Text> | ||
|
Comment on lines
+169
to
+180
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see why this text string is needed, and like that the settings are marked in italics, but this text will be a pain to localize using i18next. Did we come up with a good way to deal with italics?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will see what the solution will be in the other PR that handles the translation |
||
| <KeybindButtons | ||
| selectedKey={toggleGuiKeybind?.key} | ||
| modifiers={toggleGuiKeybind?.modifiers} | ||
| /> | ||
| </Alert> | ||
| )} | ||
| <BoolInput | ||
| label={'Hide dashboards on playback'} | ||
| value={hideDashboardsOnPlayback} | ||
| onChange={(value) => | ||
| dispatch(updateSessionRecordingSettings({ hideDashboardsOnPlayback: value })) | ||
| } | ||
| info={ | ||
| 'When checked, hides the dashboard overlays during playback. They will reappear after the recording ends.' | ||
| } | ||
| disabled={isPlayingBack} | ||
| /> | ||
| <Group gap={'xs'} align={'flex-end'}> | ||
| <Select | ||
| value={filenamePlayback} | ||
| value={playbackFile} | ||
| label={'Playback file'} | ||
| placeholder={'Select playback file'} | ||
| data={fileList} | ||
| onChange={setFilenamePlayback} | ||
| data={fileListSelectData} | ||
| renderOption={renderSelectOption} | ||
| onChange={setPlaybackFile} | ||
| searchable | ||
| disabled={isPlayingBack} | ||
| disabled={!isIdle} | ||
| /> | ||
| <PlaybackPlayButton | ||
| disabled={isPlayingBack || filenamePlayback === null} | ||
| filename={filenamePlayback} | ||
| disabled={isPlayingBack || !playbackFile} | ||
| filename={playbackFile} | ||
| loopPlayback={loopPlayback} | ||
| shouldOutputFrames={shouldOutputFrames} | ||
| outputFramerate={outputFramerate} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.