Fix video infinite loop, add new background options
This commit is contained in:
@@ -5,18 +5,17 @@ sdks:
|
|||||||
- name: opencode
|
- name: opencode
|
||||||
channel: 1/stable
|
channel: 1/stable
|
||||||
plugs:
|
plugs:
|
||||||
hostsvc:
|
lmstudio:
|
||||||
interface: tunnel
|
interface: tunnel
|
||||||
endpoint: localhost:1234
|
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
|
- name: node
|
||||||
channel: 20/stable
|
channel: 20/stable
|
||||||
- name: system
|
- name: system
|
||||||
plugs:
|
|
||||||
datasets:
|
|
||||||
interface: mount
|
|
||||||
workshop-target: /home/workshop/.config/opencode.json
|
|
||||||
slots:
|
slots:
|
||||||
hostsvc:
|
lmstudio:
|
||||||
interface: tunnel
|
interface: tunnel
|
||||||
endpoint: localhost:1234 # LM Studio
|
endpoint: localhost:1234 # LM Studio
|
||||||
# project requires node 20 and yarn to build so we install them here
|
# project requires node 20 and yarn to build so we install them here
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ type Props = {
|
|||||||
error?: string,
|
error?: string,
|
||||||
disabled?: boolean,
|
disabled?: boolean,
|
||||||
autoFocus?: boolean,
|
autoFocus?: boolean,
|
||||||
filters?: Array<{ name: string, extension: string[] }>,
|
filters?: Array<{ name: string, extensions: string[] }>,
|
||||||
readFile?: boolean,
|
readFile?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ type Props = {
|
|||||||
// For example, to only accept images pass the
|
// For example, to only accept images pass the
|
||||||
// following filter:
|
// following filter:
|
||||||
// { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
|
// { name: 'Images', extensions: ['jpg', 'png', 'gif'] },
|
||||||
filters?: Array<{ name: string, extension: string[] }>,
|
filters?: Array<{ name: string, extensions: string[] }>,
|
||||||
type?: string,
|
type?: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import SettingAppearance from './view';
|
|||||||
|
|
||||||
const select = (state) => ({
|
const select = (state) => ({
|
||||||
disableBackground: makeSelectClientSetting(SETTINGS.DISABLE_BACKGROUND)(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),
|
clock24h: makeSelectClientSetting(SETTINGS.CLOCK_24H)(state),
|
||||||
searchInLanguage: makeSelectClientSetting(SETTINGS.SEARCH_IN_LANGUAGE)(state),
|
searchInLanguage: makeSelectClientSetting(SETTINGS.SEARCH_IN_LANGUAGE)(state),
|
||||||
hideBalance: makeSelectClientSetting(SETTINGS.HIDE_BALANCE)(state),
|
hideBalance: makeSelectClientSetting(SETTINGS.HIDE_BALANCE)(state),
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import React from 'react';
|
|||||||
import * as SETTINGS from 'constants/settings';
|
import * as SETTINGS from 'constants/settings';
|
||||||
import Card from 'component/common/card';
|
import Card from 'component/common/card';
|
||||||
import { FormField } from 'component/common/form';
|
import { FormField } from 'component/common/form';
|
||||||
|
import Button from 'component/button';
|
||||||
|
import FileSelector from 'component/common/file-selector';
|
||||||
import HomepageSelector from 'component/homepageSelector';
|
import HomepageSelector from 'component/homepageSelector';
|
||||||
import SettingLanguage from 'component/settingLanguage';
|
import SettingLanguage from 'component/settingLanguage';
|
||||||
import SettingsRow from 'component/settingsRow';
|
import SettingsRow from 'component/settingsRow';
|
||||||
@@ -13,6 +15,8 @@ import homepages from 'homepages';
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
disableBackground: boolean,
|
disableBackground: boolean,
|
||||||
|
backgroundMode: string,
|
||||||
|
customBackgroundImage: string,
|
||||||
clock24h: boolean,
|
clock24h: boolean,
|
||||||
searchInLanguage: boolean,
|
searchInLanguage: boolean,
|
||||||
hideBalance: boolean,
|
hideBalance: boolean,
|
||||||
@@ -21,7 +25,29 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default function SettingAppearance(props: 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 (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -64,6 +90,44 @@ export default function SettingAppearance(props: Props) {
|
|||||||
checked={clock24h}
|
checked={clock24h}
|
||||||
/>
|
/>
|
||||||
</SettingsRow>
|
</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')}>
|
<SettingsRow title={__('Disable background')}>
|
||||||
<FormField
|
<FormField
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
|||||||
|
|
||||||
const tapToUnmuteRef = useRef();
|
const tapToUnmuteRef = useRef();
|
||||||
const tapToRetryRef = useRef();
|
const tapToRetryRef = useRef();
|
||||||
|
const keydownHandler = useRef(null);
|
||||||
|
|
||||||
// initiate keyboard shortcuts
|
// initiate keyboard shortcuts
|
||||||
const { curried_function } = keyboardShorcuts({ toggleVideoTheaterMode, playNext, playPrevious });
|
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
|
// Set reference in component state
|
||||||
playerRef.current = vjsPlayer;
|
playerRef.current = vjsPlayer;
|
||||||
|
|
||||||
window.addEventListener('keydown', curried_function(playerRef, containerRef));
|
keydownHandler.current = curried_function(playerRef, containerRef);
|
||||||
|
window.addEventListener('keydown', keydownHandler.current);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('keydown', curried_function);
|
if (keydownHandler.current) {
|
||||||
|
window.removeEventListener('keydown', keydownHandler.current);
|
||||||
|
keydownHandler.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
const player = playerRef.current;
|
const player = playerRef.current;
|
||||||
if (player) {
|
if (player) {
|
||||||
@@ -245,7 +250,13 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
|||||||
window.player = undefined;
|
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
|
// Update video player and reload when source URL changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -279,7 +290,7 @@ export default React.memo<Props>(function VideoJs(props: Props) {
|
|||||||
player.bigPlayButton.hide();
|
player.bigPlayButton.hide();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, [source, reload, sourceType, videoJsOptions.sources]);
|
}, [source, reload]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// $FlowFixMe
|
// $FlowFixMe
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { makeSelectClientSetting } from 'redux/selectors/settings';
|
|||||||
|
|
||||||
const select = (state) => ({
|
const select = (state) => ({
|
||||||
disableBackground: makeSelectClientSetting(SETTINGS.DISABLE_BACKGROUND)(state),
|
disableBackground: makeSelectClientSetting(SETTINGS.DISABLE_BACKGROUND)(state),
|
||||||
|
backgroundMode: makeSelectClientSetting(SETTINGS.APP_BACKGROUND_MODE)(state),
|
||||||
|
customBackgroundImage: makeSelectClientSetting(SETTINGS.CUSTOM_BACKGROUND_IMAGE)(state),
|
||||||
});
|
});
|
||||||
|
|
||||||
const perform = {};
|
const perform = {};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { APP_BACKGROUND_MODES } from 'constants/settings';
|
||||||
// import { resetColors } from 'util/theme';
|
// import { resetColors } from 'util/theme';
|
||||||
// $FlowFixMe cannot resolve ...
|
// $FlowFixMe cannot resolve ...
|
||||||
import freeezepeach from 'static/img/freespch.png';
|
import freeezepeach from 'static/img/freespch.png';
|
||||||
@@ -9,10 +10,65 @@ type Props = {
|
|||||||
// avatar: ?string,
|
// avatar: ?string,
|
||||||
reset: ?boolean,
|
reset: ?boolean,
|
||||||
disableBackground: ?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 Wallpaper = (props: Props) => {
|
||||||
const { disableBackground } = props;
|
const { disableBackground, backgroundMode, customBackgroundImage } = props;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (avatar) {
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={'background-image'}
|
className={'background-image'}
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: disableBackground ? `none` : `url(${freeezepeach})`,
|
backgroundImage: disableBackground ? 'none' : `url("${backgroundImage}")`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
{isVideoBackground && <VideoBackground />}
|
||||||
<div className={'theme'} />
|
<div className={'theme'} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ export const THEMES = 'themes';
|
|||||||
export const AUTOMATIC_DARK_MODE_ENABLED = 'automatic_dark_mode_enabled';
|
export const AUTOMATIC_DARK_MODE_ENABLED = 'automatic_dark_mode_enabled';
|
||||||
export const CLOCK_24H = 'clock_24h';
|
export const CLOCK_24H = 'clock_24h';
|
||||||
export const DISABLE_BACKGROUND = 'disableBackground';
|
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_MEDIA = 'autoplay';
|
||||||
export const AUTOPLAY_NEXT = 'autoplay_next';
|
export const AUTOPLAY_NEXT = 'autoplay_next';
|
||||||
export const OS_NOTIFICATIONS_ENABLED = 'os_notifications_enabled';
|
export const OS_NOTIFICATIONS_ENABLED = 'os_notifications_enabled';
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ const defaultState = {
|
|||||||
[SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: false,
|
[SETTINGS.AUTOMATIC_DARK_MODE_ENABLED]: false,
|
||||||
[SETTINGS.CLOCK_24H]: false,
|
[SETTINGS.CLOCK_24H]: false,
|
||||||
[SETTINGS.DISABLE_BACKGROUND]: false,
|
[SETTINGS.DISABLE_BACKGROUND]: false,
|
||||||
|
[SETTINGS.APP_BACKGROUND_MODE]: SETTINGS.APP_BACKGROUND_MODES.DEFAULT,
|
||||||
|
[SETTINGS.CUSTOM_BACKGROUND_IMAGE]: '',
|
||||||
[SETTINGS.TILE_LAYOUT]: true,
|
[SETTINGS.TILE_LAYOUT]: true,
|
||||||
[SETTINGS.VIDEO_THEATER_MODE]: false,
|
[SETTINGS.VIDEO_THEATER_MODE]: false,
|
||||||
[SETTINGS.VIDEO_PLAYBACK_RATE]: 1,
|
[SETTINGS.VIDEO_PLAYBACK_RATE]: 1,
|
||||||
|
|||||||
@@ -577,6 +577,18 @@ img {
|
|||||||
-webkit-filter: blur(23px);
|
-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 {
|
.theme {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
|
|||||||
Reference in New Issue
Block a user