Fix crashes when playing media on legacy OS

Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2021-12-10 16:21:48 -08:00 committed by GitHub
parent 68bc9f7f45
commit 84bd552cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 1 deletions

View File

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

View File

@ -70,6 +70,7 @@ try {
window.getServerPublicParams = () => config.serverPublicParams;
window.getSfuUrl = () => config.sfuUrl;
window.isBehindProxy = () => Boolean(config.proxyUrl);
window.isLegacyOS = () => config.isLegacyOS === 'true';
window.getAutoLaunch = () => {
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);
};
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 { MediaItemType, MessageAttributesType } from '../types/MediaItem';
import { formatDuration } from '../util/formatDuration';
import { showToast } from '../util/showToast';
import { useRestoreFocus } from '../hooks/useRestoreFocus';
import * as log from '../logging/log';
import { ToastUnableToLoadAttachment } from './ToastUnableToLoadAttachment';
export type PropsType = {
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) {
const shouldLoop = loop || isAttachmentGIF || isViewOnce;

View File

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

View File

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

1
ts/window.d.ts vendored
View File

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