2018-07-28 12:47:45 +05:00
|
|
|
// @flow
|
2022-07-07 16:48:42 -04:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2019-03-04 23:46:57 -05:00
|
|
|
// @if TARGET='app'
|
2018-04-16 18:51:35 -04:00
|
|
|
import { ipcRenderer } from 'electron';
|
2019-03-04 23:46:57 -05:00
|
|
|
// @endif
|
2018-02-23 17:24:00 -07:00
|
|
|
import { Modal } from 'modal/modal';
|
2021-02-01 19:59:34 -03:00
|
|
|
import LastReleaseChanges from 'component/lastReleaseChanges';
|
2017-12-08 05:08:50 -05:00
|
|
|
|
2018-07-28 12:47:45 +05:00
|
|
|
type Props = {
|
2022-07-07 16:48:42 -04:00
|
|
|
closeModal: (any) => any,
|
2018-07-28 12:47:45 +05:00
|
|
|
declineAutoUpdate: () => any,
|
2022-07-07 16:48:42 -04:00
|
|
|
errorWhileUpdating: boolean,
|
|
|
|
isDownloading: boolean,
|
|
|
|
isUpdateAvailable: boolean,
|
2018-07-28 12:47:45 +05:00
|
|
|
};
|
|
|
|
|
2021-02-01 19:59:34 -03:00
|
|
|
const ModalAutoUpdateDownloaded = (props: Props) => {
|
2022-07-07 16:48:42 -04:00
|
|
|
const { closeModal, declineAutoUpdate, errorWhileUpdating, isDownloading, isUpdateAvailable } = props;
|
|
|
|
const [waitingForAutoUpdateResponse, setWaitingForAutoUpdateResponse] = useState(false);
|
2018-07-28 12:47:45 +05:00
|
|
|
|
2021-02-01 19:59:34 -03:00
|
|
|
const handleConfirm = () => {
|
2022-07-07 16:48:42 -04:00
|
|
|
setWaitingForAutoUpdateResponse(true);
|
2021-02-01 19:59:34 -03:00
|
|
|
ipcRenderer.send('autoUpdateAccepted');
|
|
|
|
};
|
2018-07-28 12:47:45 +05:00
|
|
|
|
2021-02-01 19:59:34 -03:00
|
|
|
const handleAbort = () => {
|
|
|
|
declineAutoUpdate();
|
|
|
|
closeModal();
|
|
|
|
};
|
2017-12-22 01:42:04 -05:00
|
|
|
|
2022-07-07 16:48:42 -04:00
|
|
|
useEffect(() => {
|
|
|
|
setWaitingForAutoUpdateResponse(false);
|
|
|
|
}, [errorWhileUpdating, isDownloading, isUpdateAvailable]);
|
|
|
|
|
2021-02-01 19:59:34 -03:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
isOpen
|
|
|
|
type="confirm"
|
|
|
|
contentLabel={__('Upgrade Downloaded')}
|
|
|
|
title={__('LBRY leveled up')}
|
2022-07-07 16:48:42 -04:00
|
|
|
confirmButtonLabel={isDownloading ? __('Downloading...') : __('Upgrade Now')}
|
|
|
|
abortButtonLabel={isDownloading ? __('Keep browsing') : __('Not Now')}
|
|
|
|
confirmButtonDisabled={!isUpdateAvailable || isDownloading || waitingForAutoUpdateResponse}
|
2021-02-01 19:59:34 -03:00
|
|
|
onConfirmed={handleConfirm}
|
|
|
|
onAborted={handleAbort}
|
|
|
|
>
|
|
|
|
<LastReleaseChanges />
|
2022-07-07 16:48:42 -04:00
|
|
|
{errorWhileUpdating && <p>{__('There was an error while updating. Please try again.')}</p>}
|
2021-02-01 19:59:34 -03:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|
2017-12-08 05:08:50 -05:00
|
|
|
|
|
|
|
export default ModalAutoUpdateDownloaded;
|