Fix crashes when playing media on legacy OS

This commit is contained in:
Fedor Indutny 2021-12-11 00:27:42 +01:00 committed by GitHub
parent 2fe5ec6ab2
commit fed84be0b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 1 deletions

View file

@ -324,6 +324,7 @@ function prepareUrl(
appStartInitialSpellcheckSetting, appStartInitialSpellcheckSetting,
userDataPath: app.getPath('userData'), userDataPath: app.getPath('userData'),
downloadsPath: app.getPath('downloads'), downloadsPath: app.getPath('downloads'),
isLegacyOS: OS.isLegacy(),
homePath: app.getPath('home'), homePath: app.getPath('home'),
...moreKeys, ...moreKeys,
}).href; }).href;

View file

@ -70,6 +70,7 @@ try {
window.getServerPublicParams = () => config.serverPublicParams; window.getServerPublicParams = () => config.serverPublicParams;
window.getSfuUrl = () => config.sfuUrl; window.getSfuUrl = () => config.sfuUrl;
window.isBehindProxy = () => Boolean(config.proxyUrl); window.isBehindProxy = () => Boolean(config.proxyUrl);
window.isLegacyOS = () => config.isLegacyOS === 'true';
window.getAutoLaunch = () => { window.getAutoLaunch = () => {
return ipc.invoke('get-auto-launch'); return ipc.invoke('get-auto-launch');
}; };

View file

@ -16,3 +16,16 @@ export const isWindows = (minVersion?: string): boolean => {
return is.undefined(minVersion) ? true : semver.gte(osRelease, minVersion); return is.undefined(minVersion) ? true : semver.gte(osRelease, minVersion);
}; };
export const isLegacy = (): boolean => {
if (process.platform === 'darwin') {
// 17.0.0 - is macOS 10.13
return semver.lt(os.release(), '17.0.0');
}
if (process.platform === 'win32') {
return semver.lt(os.release(), '9.0.0');
}
return false;
};

View file

@ -18,8 +18,10 @@ import { IMAGE_PNG, isImage, isVideo } from '../types/MIME';
import type { LocalizerType } from '../types/Util'; import type { LocalizerType } from '../types/Util';
import type { MediaItemType, MessageAttributesType } from '../types/MediaItem'; import type { MediaItemType, MessageAttributesType } from '../types/MediaItem';
import { formatDuration } from '../util/formatDuration'; import { formatDuration } from '../util/formatDuration';
import { showToast } from '../util/showToast';
import { useRestoreFocus } from '../hooks/useRestoreFocus'; import { useRestoreFocus } from '../hooks/useRestoreFocus';
import * as log from '../logging/log'; import * as log from '../logging/log';
import { ToastUnableToLoadAttachment } from './ToastUnableToLoadAttachment';
export type PropsType = { export type PropsType = {
children?: ReactNode; children?: ReactNode;
@ -453,6 +455,25 @@ export function Lightbox({
/> />
); );
} }
} else if (isVideoTypeSupported && window.isLegacyOS()) {
const onLegacyClick = (event: React.MouseEvent<HTMLVideoElement>) => {
event.preventDefault();
event.stopPropagation();
showToast(ToastUnableToLoadAttachment);
};
content = (
<video
className="Lightbox__object"
controls={false}
key={objectURL}
loop={false}
onClick={onLegacyClick}
>
<source src={objectURL} />
</video>
);
} else if (isVideoTypeSupported) { } else if (isVideoTypeSupported) {
const shouldLoop = loop || isAttachmentGIF || isViewOnce; const shouldLoop = loop || isAttachmentGIF || isViewOnce;

View file

@ -178,7 +178,7 @@ export const GIF: React.FC<Props> = props => {
} }
let gif: JSX.Element | undefined; let gif: JSX.Element | undefined;
if (isNotDownloaded || isPending) { if (isNotDownloaded || isPending || window.isLegacyOS()) {
gif = ( gif = (
<Blurhash <Blurhash
hash={attachment.blurHash || defaultBlurHash(theme)} hash={attachment.blurHash || defaultBlurHash(theme)}

View file

@ -6,6 +6,7 @@ import classNames from 'classnames';
import { noop } from 'lodash'; import { noop } from 'lodash';
import { assert } from '../../util/assert'; import { assert } from '../../util/assert';
import { showToast } from '../../util/showToast';
import type { LocalizerType } from '../../types/Util'; import type { LocalizerType } from '../../types/Util';
import type { AttachmentType } from '../../types/Attachment'; import type { AttachmentType } from '../../types/Attachment';
import { hasNotDownloaded } from '../../types/Attachment'; import { hasNotDownloaded } from '../../types/Attachment';
@ -13,6 +14,7 @@ import type { DirectionType, MessageStatusType } from './Message';
import type { ComputePeaksResult } from '../GlobalAudioContext'; import type { ComputePeaksResult } from '../GlobalAudioContext';
import { MessageMetadata } from './MessageMetadata'; import { MessageMetadata } from './MessageMetadata';
import { ToastUnableToLoadAttachment } from '../ToastUnableToLoadAttachment';
import * as log from '../../logging/log'; import * as log from '../../logging/log';
export type Props = { export type Props = {
@ -350,6 +352,11 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
}, [id, audio, isActive, isPlaying, currentTime]); }, [id, audio, isActive, isPlaying, currentTime]);
const toggleIsPlaying = () => { const toggleIsPlaying = () => {
if (window.isLegacyOS()) {
showToast(ToastUnableToLoadAttachment);
return;
}
setIsPlaying(!isPlaying); setIsPlaying(!isPlaying);
if (!isActive && !isPlaying) { if (!isActive && !isPlaying) {

1
ts/window.d.ts vendored
View file

@ -170,6 +170,7 @@ declare global {
imageToBlurHash: typeof imageToBlurHash; imageToBlurHash: typeof imageToBlurHash;
loadImage: any; loadImage: any;
isBehindProxy: () => boolean; isBehindProxy: () => boolean;
isLegacyOS: () => boolean;
getAutoLaunch: () => Promise<boolean>; getAutoLaunch: () => Promise<boolean>;
setAutoLaunch: (value: boolean) => Promise<void>; setAutoLaunch: (value: boolean) => Promise<void>;