Skip to content

Adjustable Refresh Rate #309

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

Merged
merged 6 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface Settings {
trackInfoBackgroundOpacity: number;
showFreemiumWarning: boolean;
cornerRadius: number;
trackInfoRefreshTimeInSeconds: number;
}

export const DEFAULT_SETTINGS: Settings = {
Expand Down Expand Up @@ -66,4 +67,5 @@ export const DEFAULT_SETTINGS: Settings = {
trackInfoBackgroundOpacity: 50,
showFreemiumWarning: true,
cornerRadius: 0,
trackInfoRefreshTimeInSeconds: 1,
};
13 changes: 7 additions & 6 deletions src/renderer/app/cover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import Menu from './menu';
import { Visualizer } from './visualizer';
import { Waiting } from './waiting';

const ONE_SECOND = 1000;
const ONE_MINUTE = ONE_SECOND * 60;
const ONE_SECOND_IN_MS = 1000;
const ONE_MINUTE = ONE_SECOND_IN_MS * 60;

const TRUNCATE_REGEX = /(.*?)\s[-(•].*/g;
const truncateText = (text: string): string => text?.replace(TRUNCATE_REGEX, '$1');
Expand Down Expand Up @@ -59,6 +59,7 @@ export const Cover: FunctionComponent<Props> = ({ settings, message, onVisualiza
visualizationId,
visualizationType,
visualizerOpacity,
trackInfoRefreshTimeInSeconds,
} = useMemo(() => settings, [settings]);

const [currentSongId, setCurrentSongId] = useState('');
Expand Down Expand Up @@ -178,23 +179,23 @@ export const Cover: FunctionComponent<Props> = ({ settings, message, onVisualiza
}, [onMouseWheel]);

useEffect(() => {
const listeningToIntervalId = setInterval(handlePlaybackChanged, ONE_SECOND);
const listeningToIntervalId = setInterval(handlePlaybackChanged, trackInfoRefreshTimeInSeconds * ONE_SECOND_IN_MS);

return () => {
if (listeningToIntervalId) {
clearInterval(listeningToIntervalId);
}
};
}, [handlePlaybackChanged]);
}, [handlePlaybackChanged, trackInfoRefreshTimeInSeconds]);

useEffect(() => {
const refreshTrackLikedIntervalId = setInterval(refreshTrackLiked, 2 * ONE_SECOND);
const refreshTrackLikedIntervalId = setInterval(refreshTrackLiked, 2 * trackInfoRefreshTimeInSeconds * ONE_SECOND_IN_MS);
return () => {
if (refreshTrackLikedIntervalId) {
clearInterval(refreshTrackLikedIntervalId);
}
};
}, [refreshTrackLiked]);
}, [refreshTrackLiked, trackInfoRefreshTimeInSeconds]);

useEffect(() => {
const keepAliveIntervalId = setInterval(keepAlive, ONE_MINUTE);
Expand Down
23 changes: 20 additions & 3 deletions src/renderer/windows/settings/advanced-settings.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React, { FunctionComponent } from 'react';
import { useFormContext } from 'react-hook-form';

import { Settings } from '../../../models/settings';
import { FieldSet, FormGroup, Legend, Row, StyledCheckbox } from '../../components';
import { DEFAULT_SETTINGS, Settings } from '../../../models/settings';
import { FieldSet, FormGroup, Label, Legend, RangeValue, Row, Slider, StyledCheckbox } from '../../components';
import { INPUT_COLOR } from '../../components/mantine.styled';

export const AdvancedSettings: FunctionComponent = () => {
const { register } = useFormContext<Settings>();
const { register, watch } = useFormContext<Settings>();

const refreshTimeWatch = watch('trackInfoRefreshTimeInSeconds');

return (
<FormGroup>
<FieldSet>
Expand All @@ -22,6 +25,20 @@ export const AdvancedSettings: FunctionComponent = () => {
<Row>
<StyledCheckbox color={INPUT_COLOR} label="Enable dev tools" size="xs" {...register('isDebug')} />
</Row>
<Row>
<Label>
Currently Listening Refresh Time (Seconds)
<Slider
type="range"
min={1}
max={10}
step={1}
defaultValue={DEFAULT_SETTINGS.trackInfoRefreshTimeInSeconds}
{...register('trackInfoRefreshTimeInSeconds', { required: true, valueAsNumber: true })}
/>
<RangeValue>{refreshTimeWatch}</RangeValue>
</Label>
</Row>
</FieldSet>
</FormGroup>
);
Expand Down