2019-05-12 16:51:22 +02:00
|
|
|
// @flow
|
2021-02-17 15:44:37 +01:00
|
|
|
import React from 'react';
|
2019-05-12 16:51:22 +02:00
|
|
|
import { Modal } from 'modal/modal';
|
2019-12-02 18:30:08 +01:00
|
|
|
import { formatFileSystemPath } from 'util/url';
|
2019-05-12 16:51:22 +02:00
|
|
|
// @if TARGET='app'
|
|
|
|
import { shell } from 'electron';
|
|
|
|
// @endif
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
2019-07-04 13:15:40 +02:00
|
|
|
isTrusted: boolean,
|
2019-05-12 16:51:22 +02:00
|
|
|
path: string,
|
2019-07-04 13:15:40 +02:00
|
|
|
isMine: boolean,
|
2019-05-12 16:51:22 +02:00
|
|
|
closeModal: () => void,
|
|
|
|
};
|
|
|
|
|
2019-07-04 13:15:40 +02:00
|
|
|
function ModalOpenExternalResource(props: Props) {
|
|
|
|
const { uri, isTrusted, path, isMine, closeModal } = props;
|
|
|
|
|
2021-02-17 15:44:37 +01:00
|
|
|
if ((uri && isTrusted) || (path && isMine)) {
|
|
|
|
openResource();
|
|
|
|
}
|
|
|
|
|
|
|
|
function openResource() {
|
2019-05-12 16:51:22 +02:00
|
|
|
// @if TARGET='app'
|
2020-10-16 16:49:01 +02:00
|
|
|
const { openExternal, openPath, showItemInFolder } = shell;
|
2019-05-12 16:51:22 +02:00
|
|
|
if (uri) {
|
|
|
|
openExternal(uri);
|
2019-05-12 19:59:57 +02:00
|
|
|
} else if (path) {
|
2020-10-16 16:49:01 +02:00
|
|
|
const success = openPath(path);
|
2019-05-12 16:51:22 +02:00
|
|
|
if (!success) {
|
|
|
|
showItemInFolder(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// @endif
|
|
|
|
// @if TARGET='web'
|
|
|
|
if (uri) {
|
|
|
|
window.open(uri);
|
|
|
|
} else if (path) {
|
2019-12-02 18:30:08 +01:00
|
|
|
window.open(formatFileSystemPath(path));
|
2019-05-12 16:51:22 +02:00
|
|
|
}
|
|
|
|
// @endif
|
|
|
|
|
|
|
|
closeModal();
|
2021-02-17 15:44:37 +01:00
|
|
|
}
|
2019-05-12 16:51:22 +02:00
|
|
|
|
2019-07-04 13:15:40 +02:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
isOpen
|
|
|
|
title={__('Warning!')}
|
|
|
|
contentLabel={__('Confirm External Resource')}
|
|
|
|
type="confirm"
|
|
|
|
confirmButtonLabel={__('Continue')}
|
|
|
|
onConfirmed={() => openResource()}
|
|
|
|
onAborted={closeModal}
|
|
|
|
>
|
2019-07-21 23:31:22 +02:00
|
|
|
<p>
|
|
|
|
{(uri && __('This link leads to an external website.')) ||
|
|
|
|
(path && __('This file has been shared with you by other people.'))}
|
|
|
|
</p>
|
|
|
|
<blockquote>{uri || path}</blockquote>
|
2021-11-03 20:47:19 +01:00
|
|
|
<p>{__('Odysee is not responsible for its content, click continue to proceed at your own risk.')}</p>
|
2019-07-04 13:15:40 +02:00
|
|
|
</Modal>
|
|
|
|
);
|
2019-05-12 16:51:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ModalOpenExternalResource;
|