Fix video infinite loop, add new background options
This commit is contained in:
@@ -5,18 +5,17 @@ sdks:
|
||||
- name: opencode
|
||||
channel: 1/stable
|
||||
plugs:
|
||||
hostsvc:
|
||||
lmstudio:
|
||||
interface: tunnel
|
||||
endpoint: localhost:1234
|
||||
#There used to be a plug here for binding your host directory in, but seemingly, OpenCode's sdk has it's own predefined plugin.
|
||||
#Just use dev/opencode:opencode-config instead
|
||||
- name: puppeteer-chrome
|
||||
- name: node
|
||||
channel: 20/stable
|
||||
- name: system
|
||||
plugs:
|
||||
datasets:
|
||||
interface: mount
|
||||
workshop-target: /home/workshop/.config/opencode.json
|
||||
slots:
|
||||
hostsvc:
|
||||
lmstudio:
|
||||
interface: tunnel
|
||||
endpoint: localhost:1234 # LM Studio
|
||||
# project requires node 20 and yarn to build so we install them here
|
||||
|
||||
@@ -15,7 +15,7 @@ type Props = {
|
||||
error?: string,
|
||||
disabled?: boolean,
|
||||
autoFocus?: boolean,
|
||||
filters?: Array<{ name: string, extension: string[] }>,
|
||||
filters?: Array<{ name: string, extensions: string[] }>,
|
||||
readFile?: boolean,
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ type Props = {
|
||||
// For example, to only accept images pass the
|
||||
// following filter:
|
||||
// { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
|
||||
filters?: Array<{ name: string, extension: string[] }>,
|
||||
filters?: Array<{ name: string, extensions: string[] }>,
|
||||
type?: string,
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import SettingAppearance from './view';
|
||||
|
||||
const select = (state) => ({
|
||||
disableBackground: makeSelectClientSetting(SETTINGS.DISABLE_BACKGROUND)(state),
|
||||
backgroundMode: makeSelectClientSetting(SETTINGS.APP_BACKGROUND_MODE)(state),
|
||||
customBackgroundImage: makeSelectClientSetting(SETTINGS.CUSTOM_BACKGROUND_IMAGE)(state),
|
||||
clock24h: makeSelectClientSetting(SETTINGS.CLOCK_24H)(state),
|
||||
searchInLanguage: makeSelectClientSetting(SETTINGS.SEARCH_IN_LANGUAGE)(state),
|
||||
hideBalance: makeSelectClientSetting(SETTINGS.HIDE_BALANCE)(state),
|
||||
|
||||
@@ -4,6 +4,8 @@ import React from 'react';
|
||||
import * as SETTINGS from 'constants/settings';
|
||||
import Card from 'component/common/card';
|
||||
import { FormField } from 'component/common/form';
|
||||
import Button from 'component/button';
|
||||
import FileSelector from 'component/common/file-selector';
|
||||
import HomepageSelector from 'component/homepageSelector';
|
||||
import SettingLanguage from 'component/settingLanguage';
|
||||
import SettingsRow from 'component/settingsRow';
|
||||
@@ -13,6 +15,8 @@ import homepages from 'homepages';
|
||||
|
||||
type Props = {
|
||||
disableBackground: boolean,
|
||||
backgroundMode: string,
|
||||
customBackgroundImage: string,
|
||||
clock24h: boolean,
|
||||
searchInLanguage: boolean,
|
||||
hideBalance: boolean,
|
||||
@@ -21,7 +25,29 @@ type Props = {
|
||||
};
|
||||
|
||||
export default function SettingAppearance(props: Props) {
|
||||
const { clock24h, disableBackground, searchInLanguage, hideBalance, setClientSetting, setSearchInLanguage } = props;
|
||||
const {
|
||||
clock24h,
|
||||
disableBackground,
|
||||
backgroundMode,
|
||||
customBackgroundImage,
|
||||
searchInLanguage,
|
||||
hideBalance,
|
||||
setClientSetting,
|
||||
setSearchInLanguage,
|
||||
} = props;
|
||||
|
||||
function handleBackgroundImageChosen(fileWithPath: FileWithPath) {
|
||||
const file = fileWithPath && fileWithPath.file;
|
||||
if (!file) return;
|
||||
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
if (reader.result) {
|
||||
setClientSetting(SETTINGS.CUSTOM_BACKGROUND_IMAGE, reader.result.toString());
|
||||
}
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -64,6 +90,44 @@ export default function SettingAppearance(props: Props) {
|
||||
checked={clock24h}
|
||||
/>
|
||||
</SettingsRow>
|
||||
<SettingsRow
|
||||
title={__('Background')}
|
||||
subtitle={__('Use a custom image or mirror the video that is currently playing.')}
|
||||
>
|
||||
<FormField
|
||||
type="select"
|
||||
name="app-background-mode"
|
||||
value={backgroundMode || SETTINGS.APP_BACKGROUND_MODES.DEFAULT}
|
||||
onChange={(e) => setClientSetting(SETTINGS.APP_BACKGROUND_MODE, e.target.value)}
|
||||
>
|
||||
<option value={SETTINGS.APP_BACKGROUND_MODES.DEFAULT}>{__('Default')}</option>
|
||||
<option value={SETTINGS.APP_BACKGROUND_MODES.CUSTOM}>{__('Custom image')}</option>
|
||||
<option value={SETTINGS.APP_BACKGROUND_MODES.VIDEO}>{__('Playing video')}</option>
|
||||
</FormField>
|
||||
</SettingsRow>
|
||||
{backgroundMode === SETTINGS.APP_BACKGROUND_MODES.CUSTOM && (
|
||||
<SettingsRow
|
||||
title={__('Custom background image')}
|
||||
subtitle={__('Choose an image to use as the app background.')}
|
||||
multirow
|
||||
>
|
||||
<FileSelector
|
||||
type="openFile"
|
||||
accept="image/*"
|
||||
filters={[{ name: __('Images'), extensions: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'] }]}
|
||||
currentPath={customBackgroundImage ? __('Image selected') : undefined}
|
||||
label={__('Background image')}
|
||||
onFileChosen={handleBackgroundImageChosen}
|
||||
/>
|
||||
{customBackgroundImage && (
|
||||
<Button
|
||||
button="link"
|
||||
label={__('Remove custom background')}
|
||||
onClick={() => setClientSetting(SETTINGS.CUSTOM_BACKGROUND_IMAGE, '')}
|
||||
/>
|
||||
)}
|
||||
</SettingsRow>
|
||||
)}
|
||||
<SettingsRow title={__('Disable background')}>
|
||||
<FormField
|
||||
type="checkbox"
|
||||
|
||||
@@ -128,6 +128,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
|
||||
const tapToUnmuteRef = useRef();
|
||||
const tapToRetryRef = useRef();
|
||||
const keydownHandler = useRef(null);
|
||||
|
||||
// initiate keyboard shortcuts
|
||||
const { curried_function } = keyboardShorcuts({ toggleVideoTheaterMode, playNext, playPrevious });
|
||||
@@ -232,12 +233,16 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
// Set reference in component state
|
||||
playerRef.current = vjsPlayer;
|
||||
|
||||
window.addEventListener('keydown', curried_function(playerRef, containerRef));
|
||||
keydownHandler.current = curried_function(playerRef, containerRef);
|
||||
window.addEventListener('keydown', keydownHandler.current);
|
||||
});
|
||||
|
||||
// Cleanup
|
||||
return () => {
|
||||
window.removeEventListener('keydown', curried_function);
|
||||
if (keydownHandler.current) {
|
||||
window.removeEventListener('keydown', keydownHandler.current);
|
||||
keydownHandler.current = null;
|
||||
}
|
||||
|
||||
const player = playerRef.current;
|
||||
if (player) {
|
||||
@@ -245,7 +250,13 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
window.player = undefined;
|
||||
}
|
||||
};
|
||||
}, [isAudio, source, curried_function, createVideoPlayerDOM, detectFileType, initializeVideoPlayer]);
|
||||
// These dep-array entries are intentionally only [isAudio, source]: the DOM/player is
|
||||
// recreated from scratch only when the medium or the source changes. initializeVideoPlayer,
|
||||
// createVideoPlayerDOM, detectFileType and curried_function are recreated on each render
|
||||
// (unstable identity), so adding them here would destroy/recreate the player on every
|
||||
// render, stacking one <video> element + one player per pass.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [isAudio, source]);
|
||||
|
||||
// Update video player and reload when source URL changes
|
||||
useEffect(() => {
|
||||
@@ -279,7 +290,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
||||
player.bigPlayButton.hide();
|
||||
}
|
||||
});
|
||||
}, [source, reload, sourceType, videoJsOptions.sources]);
|
||||
}, [source, reload]);
|
||||
|
||||
return (
|
||||
// $FlowFixMe
|
||||
|
||||
@@ -5,6 +5,8 @@ import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||
|
||||
const select = (state) => ({
|
||||
disableBackground: makeSelectClientSetting(SETTINGS.DISABLE_BACKGROUND)(state),
|
||||
backgroundMode: makeSelectClientSetting(SETTINGS.APP_BACKGROUND_MODE)(state),
|
||||
customBackgroundImage: makeSelectClientSetting(SETTINGS.CUSTOM_BACKGROUND_IMAGE)(state),
|
||||
});
|
||||
|
||||
const perform = {};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// @flow
|
||||
import React from 'react';
|
||||
import { APP_BACKGROUND_MODES } from 'constants/settings';
|
||||
// import { resetColors } from 'util/theme';
|
||||
// $FlowFixMe cannot resolve ...
|
||||
import freeezepeach from 'static/img/freespch.png';
|
||||
@@ -9,10 +10,65 @@ type Props = {
|
||||
// avatar: ?string,
|
||||
reset: ?boolean,
|
||||
disableBackground: ?boolean,
|
||||
backgroundMode: ?string,
|
||||
customBackgroundImage: ?string,
|
||||
};
|
||||
|
||||
const VideoBackground = () => {
|
||||
const canvasRef = React.useRef<any>();
|
||||
|
||||
React.useEffect(() => {
|
||||
const canvas = canvasRef.current;
|
||||
if (!canvas) return;
|
||||
|
||||
const context = canvas.getContext('2d');
|
||||
if (!context) return;
|
||||
|
||||
let animationFrame;
|
||||
let lastDrawTime = 0;
|
||||
|
||||
function draw(timestamp) {
|
||||
animationFrame = window.requestAnimationFrame(draw);
|
||||
|
||||
if (timestamp - lastDrawTime < 33) return;
|
||||
lastDrawTime = timestamp;
|
||||
|
||||
const video: ?HTMLVideoElement =
|
||||
(document.querySelector('video.vjs-tech'): any) || (document.querySelector('video.video-js'): any);
|
||||
|
||||
if (video && video.videoWidth && video.videoHeight) {
|
||||
const width = window.innerWidth;
|
||||
const height = window.innerHeight;
|
||||
|
||||
if (canvas.width !== width || canvas.height !== height) {
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
}
|
||||
|
||||
const scale = Math.max(width / video.videoWidth, height / video.videoHeight);
|
||||
const drawWidth = video.videoWidth * scale;
|
||||
const drawHeight = video.videoHeight * scale;
|
||||
const x = (width - drawWidth) / 2;
|
||||
const y = (height - drawHeight) / 2;
|
||||
|
||||
try {
|
||||
context.drawImage(video, x, y, drawWidth, drawHeight);
|
||||
} catch (e) {}
|
||||
} else if (canvas.width && canvas.height) {
|
||||
context.clearRect(0, 0, canvas.width, canvas.height);
|
||||
}
|
||||
}
|
||||
|
||||
animationFrame = window.requestAnimationFrame(draw);
|
||||
|
||||
return () => window.cancelAnimationFrame(animationFrame);
|
||||
}, []);
|
||||
|
||||
return <canvas ref={canvasRef} className="background-video" />;
|
||||
};
|
||||
|
||||
const Wallpaper = (props: Props) => {
|
||||
const { disableBackground } = props;
|
||||
const { disableBackground, backgroundMode, customBackgroundImage } = props;
|
||||
|
||||
/*
|
||||
if (avatar) {
|
||||
@@ -229,14 +285,19 @@ const Wallpaper = (props: Props) => {
|
||||
/>
|
||||
*/
|
||||
|
||||
const isVideoBackground = !disableBackground && backgroundMode === APP_BACKGROUND_MODES.VIDEO;
|
||||
const backgroundImage =
|
||||
backgroundMode === APP_BACKGROUND_MODES.CUSTOM && customBackgroundImage ? customBackgroundImage : freeezepeach;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={'background-image'}
|
||||
style={{
|
||||
backgroundImage: disableBackground ? `none` : `url(${freeezepeach})`,
|
||||
backgroundImage: disableBackground ? 'none' : `url("${backgroundImage}")`,
|
||||
}}
|
||||
/>
|
||||
{isVideoBackground && <VideoBackground />}
|
||||
<div className={'theme'} />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -15,6 +15,14 @@ export const THEMES = 'themes';
|
||||
export const AUTOMATIC_DARK_MODE_ENABLED = 'automatic_dark_mode_enabled';
|
||||
export const CLOCK_24H = 'clock_24h';
|
||||
export const DISABLE_BACKGROUND = 'disableBackground';
|
||||
export const APP_BACKGROUND_MODE = 'app_background_mode';
|
||||
export const CUSTOM_BACKGROUND_IMAGE = 'custom_background_image';
|
||||
|
||||
export const APP_BACKGROUND_MODES = {
|
||||
DEFAULT: 'default',
|
||||
CUSTOM: 'custom',
|
||||
VIDEO: 'video',
|
||||
};
|
||||
export const AUTOPLAY_MEDIA = 'autoplay';
|
||||
export const AUTOPLAY_NEXT = 'autoplay_next';
|
||||
export const OS_NOTIFICATIONS_ENABLED = 'os_notifications_enabled';
|
||||
|
||||
@@ -41,6 +41,8 @@ const defaultState = {
|
||||
[SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: false,
|
||||
[SETTINGS.CLOCK_24H]: false,
|
||||
[SETTINGS.DISABLE_BACKGROUND]: false,
|
||||
[SETTINGS.APP_BACKGROUND_MODE]: SETTINGS.APP_BACKGROUND_MODES.DEFAULT,
|
||||
[SETTINGS.CUSTOM_BACKGROUND_IMAGE]: '',
|
||||
[SETTINGS.TILE_LAYOUT]: true,
|
||||
[SETTINGS.VIDEO_THEATER_MODE]: false,
|
||||
[SETTINGS.VIDEO_PLAYBACK_RATE]: 1,
|
||||
|
||||
@@ -577,6 +577,18 @@ img {
|
||||
-webkit-filter: blur(23px);
|
||||
}
|
||||
|
||||
.background-video {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
width: 100vw;
|
||||
height: 100vh;
|
||||
filter: blur(23px);
|
||||
-webkit-filter: blur(23px);
|
||||
}
|
||||
|
||||
.theme {
|
||||
position: fixed;
|
||||
left: 0px;
|
||||
|
||||
Reference in New Issue
Block a user