Merge pull request #757 from ente-io/update-dialog

App Update dialog
This commit is contained in:
Abhinav Kumar 2022-10-31 15:23:26 +05:30 committed by GitHub
commit a207845a67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 88 additions and 3 deletions

View file

@ -0,0 +1,18 @@
import { Box } from '@mui/material';
import React from 'react';
export default function DialogIcon({ icon }: { icon: React.ReactNode }) {
return (
<Box
className="DialogIcon"
sx={{
svg: {
width: '48px',
height: '48px',
},
color: 'stroke.secondary',
}}>
{icon}
</Box>
);
}

View file

@ -5,6 +5,12 @@ const DialogBoxBase = styled(Dialog)(({ theme }) => ({
padding: theme.spacing(1, 1.5), padding: theme.spacing(1, 1.5),
maxWidth: '346px', maxWidth: '346px',
}, },
'& .DialogIcon': {
padding: theme.spacing(2),
paddingBottom: theme.spacing(1),
},
'& .MuiDialogTitle-root': { '& .MuiDialogTitle-root': {
padding: theme.spacing(2), padding: theme.spacing(2),
paddingBottom: theme.spacing(1), paddingBottom: theme.spacing(1),
@ -12,6 +18,11 @@ const DialogBoxBase = styled(Dialog)(({ theme }) => ({
'& .MuiDialogContent-root': { '& .MuiDialogContent-root': {
padding: theme.spacing(2), padding: theme.spacing(2),
}, },
'.DialogIcon + .MuiDialogTitle-root': {
paddingTop: 0,
},
'.MuiDialogTitle-root + .MuiDialogContent-root': { '.MuiDialogTitle-root + .MuiDialogContent-root': {
paddingTop: 0, paddingTop: 0,
}, },

View file

@ -13,6 +13,7 @@ import DialogTitleWithCloseButton, {
} from './TitleWithCloseButton'; } from './TitleWithCloseButton';
import DialogBoxBase from './base'; import DialogBoxBase from './base';
import { DialogBoxAttributes } from 'types/dialogBox'; import { DialogBoxAttributes } from 'types/dialogBox';
import DialogIcon from './DialogIcon';
type IProps = React.PropsWithChildren< type IProps = React.PropsWithChildren<
Omit<DialogProps, 'onClose' | 'maxSize'> & { Omit<DialogProps, 'onClose' | 'maxSize'> & {
@ -48,6 +49,7 @@ export default function DialogBox({
maxWidth={size} maxWidth={size}
onClose={handleClose} onClose={handleClose}
{...props}> {...props}>
{attributes.icon && <DialogIcon icon={attributes.icon} />}
{attributes.title && ( {attributes.title && (
<DialogTitleWithCloseButton <DialogTitleWithCloseButton
onClose={ onClose={

View file

@ -120,13 +120,15 @@ export default function SingleInputForm(props: SingleInputFormProps) {
onClick={props.secondaryButtonAction} onClick={props.secondaryButtonAction}
size="large" size="large"
color="secondary" color="secondary"
sx={{ mt: 2, mb: 4, mr: 1, ...buttonSx }} sx={{
'&&&': { mt: 2, mb: 4, mr: 1, ...buttonSx },
}}
{...restSubmitButtonProps}> {...restSubmitButtonProps}>
{constants.CANCEL} {constants.CANCEL}
</Button> </Button>
)} )}
<SubmitButton <SubmitButton
sx={{ mt: 2, ...buttonSx }} sx={{ '&&&': { mt: 2, ...buttonSx } }}
buttonText={props.buttonText} buttonText={props.buttonText}
loading={loading} loading={loading}
{...restSubmitButtonProps} {...restSubmitButtonProps}

View file

@ -28,6 +28,8 @@ import {
import { CustomError } from 'utils/error'; import { CustomError } from 'utils/error';
import { clearLogsIfLocalStorageLimitExceeded } from 'utils/logging'; import { clearLogsIfLocalStorageLimitExceeded } from 'utils/logging';
import isElectron from 'is-electron'; import isElectron from 'is-electron';
import ElectronUpdateService from 'services/electron/update';
import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome';
export const MessageContainer = styled('div')` export const MessageContainer = styled('div')`
background-color: #111; background-color: #111;
@ -138,6 +140,27 @@ export default function App({ Component, err }) {
clearLogsIfLocalStorageLimitExceeded(); clearLogsIfLocalStorageLimitExceeded();
}, []); }, []);
useEffect(() => {
if (isElectron()) {
const showUpdateDialog = () =>
setDialogMessage({
icon: <AutoAwesomeIcon />,
title: constants.UPDATE_AVAILABLE,
content: constants.UPDATE_AVAILABLE_MESSAGE,
close: {
text: constants.INSTALL_ON_NEXT_LAUNCH,
variant: 'secondary',
},
proceed: {
action: () => ElectronUpdateService.updateAndRestart(),
text: constants.INSTALL_NOW,
variant: 'accent',
},
});
ElectronUpdateService.registerUpdateEventListener(showUpdateDialog);
}
});
const setUserOnline = () => setOffline(false); const setUserOnline = () => setOffline(false);
const setUserOffline = () => setOffline(true); const setUserOffline = () => setOffline(true);
const resetSharedFiles = () => setSharedFiles(null); const resetSharedFiles = () => setSharedFiles(null);

View file

@ -3,7 +3,6 @@ import { ElectronAPIs } from 'types/electron';
class ElectronService { class ElectronService {
private electronAPIs: ElectronAPIs; private electronAPIs: ElectronAPIs;
private isBundledApp: boolean = false;
constructor() { constructor() {
this.electronAPIs = globalThis['ElectronAPIs']; this.electronAPIs = globalThis['ElectronAPIs'];

View file

@ -0,0 +1,23 @@
import { ElectronAPIs } from 'types/electron';
class ElectronUpdateService {
private electronAPIs: ElectronAPIs;
constructor() {
this.electronAPIs = globalThis['ElectronAPIs'];
}
registerUpdateEventListener(showUpdateDialog: () => void) {
if (this.electronAPIs?.registerUpdateEventListener) {
this.electronAPIs.registerUpdateEventListener(showUpdateDialog);
}
}
updateAndRestart() {
if (this.electronAPIs?.updateAndRestart) {
this.electronAPIs.updateAndRestart();
}
}
}
export default new ElectronUpdateService();

View file

@ -1,6 +1,7 @@
import { ButtonProps } from '@mui/material'; import { ButtonProps } from '@mui/material';
export interface DialogBoxAttributes { export interface DialogBoxAttributes {
icon?: React.ReactNode;
title?: string; title?: string;
staticBackdrop?: boolean; staticBackdrop?: boolean;
nonClosable?: boolean; nonClosable?: boolean;

View file

@ -65,4 +65,6 @@ export interface ElectronAPIs {
logToDisk: (msg: string) => void; logToDisk: (msg: string) => void;
convertHEIC(fileData: Uint8Array): Promise<Uint8Array>; convertHEIC(fileData: Uint8Array): Promise<Uint8Array>;
openLogDirectory: () => void; openLogDirectory: () => void;
registerUpdateEventListener: (showUpdateDialog: () => void) => void;
updateAndRestart: () => void;
} }

View file

@ -825,6 +825,10 @@ const englishConstants = {
UPLOADED_TO_SINGLE_COLLECTION: 'Uploaded to single collection', UPLOADED_TO_SINGLE_COLLECTION: 'Uploaded to single collection',
UPLOADED_TO_SEPARATE_COLLECTIONS: 'Uploaded to separate collections', UPLOADED_TO_SEPARATE_COLLECTIONS: 'Uploaded to separate collections',
NEVERMIND: 'Nevermind', NEVERMIND: 'Nevermind',
UPDATE_AVAILABLE: 'Update available',
UPDATE_AVAILABLE_MESSAGE: 'A new version of ente is ready to be installed.',
INSTALL_NOW: `Install now`,
INSTALL_ON_NEXT_LAUNCH: 'Install on next launch',
}; };
export default englishConstants; export default englishConstants;