From 5f182ba778363a32ec06aa28ad48eed0255a2775 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 31 Oct 2022 11:05:41 +0530 Subject: [PATCH 1/4] use electron update api to show update dialog --- src/pages/_app.tsx | 21 +++++++++++++++++++++ src/services/electron/common.ts | 1 - src/services/electron/update.ts | 23 +++++++++++++++++++++++ src/types/electron/index.ts | 2 ++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/services/electron/update.ts diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index c71a80ceb..ed7d23c3e 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -28,6 +28,7 @@ import { import { CustomError } from 'utils/error'; import { clearLogsIfLocalStorageLimitExceeded } from 'utils/logging'; import isElectron from 'is-electron'; +import ElectronUpdateService from 'services/electron/update'; export const MessageContainer = styled('div')` background-color: #111; @@ -138,6 +139,26 @@ export default function App({ Component, err }) { clearLogsIfLocalStorageLimitExceeded(); }, []); + useEffect(() => { + if (isElectron()) { + const showUpdateDialog = () => + setDialogMessage({ + title: constants.STOP_WATCHING_FOLDER, + content: constants.STOP_WATCHING_DIALOG_MESSAGE, + close: { + text: constants.CANCEL, + variant: 'secondary', + }, + proceed: { + action: () => ElectronUpdateService.updateAndRestart(), + text: constants.YES_STOP, + variant: 'danger', + }, + }); + ElectronUpdateService.registerUpdateEventListener(showUpdateDialog); + } + }); + const setUserOnline = () => setOffline(false); const setUserOffline = () => setOffline(true); const resetSharedFiles = () => setSharedFiles(null); diff --git a/src/services/electron/common.ts b/src/services/electron/common.ts index b7e5711c2..b1b301298 100644 --- a/src/services/electron/common.ts +++ b/src/services/electron/common.ts @@ -3,7 +3,6 @@ import { ElectronAPIs } from 'types/electron'; class ElectronService { private electronAPIs: ElectronAPIs; - private isBundledApp: boolean = false; constructor() { this.electronAPIs = globalThis['ElectronAPIs']; diff --git a/src/services/electron/update.ts b/src/services/electron/update.ts new file mode 100644 index 000000000..7bffda4ba --- /dev/null +++ b/src/services/electron/update.ts @@ -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(); diff --git a/src/types/electron/index.ts b/src/types/electron/index.ts index dd80880e3..3d0791549 100644 --- a/src/types/electron/index.ts +++ b/src/types/electron/index.ts @@ -65,4 +65,6 @@ export interface ElectronAPIs { logToDisk: (msg: string) => void; convertHEIC(fileData: Uint8Array): Promise; openLogDirectory: () => void; + registerUpdateEventListener: (showUpdateDialog: () => void) => void; + updateAndRestart: () => void; } From 50117f23e1319d4252f56a7ae68dc38c19260892 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 31 Oct 2022 13:18:21 +0530 Subject: [PATCH 2/4] fix singleInputForm button spacing --- src/components/SingleInputForm.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/SingleInputForm.tsx b/src/components/SingleInputForm.tsx index 81b9be9c9..9f1622720 100644 --- a/src/components/SingleInputForm.tsx +++ b/src/components/SingleInputForm.tsx @@ -120,13 +120,15 @@ export default function SingleInputForm(props: SingleInputFormProps) { onClick={props.secondaryButtonAction} size="large" color="secondary" - sx={{ mt: 2, mb: 4, mr: 1, ...buttonSx }} + sx={{ + '&&&': { mt: 2, mb: 4, mr: 1, ...buttonSx }, + }} {...restSubmitButtonProps}> {constants.CANCEL} )} Date: Mon, 31 Oct 2022 13:52:41 +0530 Subject: [PATCH 3/4] add support for icon in dialog box --- src/components/DialogBox/DialogIcon.tsx | 18 ++++++++++++++++++ src/components/DialogBox/base.tsx | 11 +++++++++++ src/components/DialogBox/index.tsx | 2 ++ src/types/dialogBox/index.ts | 1 + 4 files changed, 32 insertions(+) create mode 100644 src/components/DialogBox/DialogIcon.tsx diff --git a/src/components/DialogBox/DialogIcon.tsx b/src/components/DialogBox/DialogIcon.tsx new file mode 100644 index 000000000..cebda8d7a --- /dev/null +++ b/src/components/DialogBox/DialogIcon.tsx @@ -0,0 +1,18 @@ +import { Box } from '@mui/material'; +import React from 'react'; + +export default function DialogIcon({ icon }: { icon: React.ReactNode }) { + return ( + + {icon} + + ); +} diff --git a/src/components/DialogBox/base.tsx b/src/components/DialogBox/base.tsx index 395c55cc6..1b4ddf092 100644 --- a/src/components/DialogBox/base.tsx +++ b/src/components/DialogBox/base.tsx @@ -5,6 +5,12 @@ const DialogBoxBase = styled(Dialog)(({ theme }) => ({ padding: theme.spacing(1, 1.5), maxWidth: '346px', }, + + '& .DialogIcon': { + padding: theme.spacing(2), + paddingBottom: theme.spacing(1), + }, + '& .MuiDialogTitle-root': { padding: theme.spacing(2), paddingBottom: theme.spacing(1), @@ -12,6 +18,11 @@ const DialogBoxBase = styled(Dialog)(({ theme }) => ({ '& .MuiDialogContent-root': { padding: theme.spacing(2), }, + + '.DialogIcon + .MuiDialogTitle-root': { + paddingTop: 0, + }, + '.MuiDialogTitle-root + .MuiDialogContent-root': { paddingTop: 0, }, diff --git a/src/components/DialogBox/index.tsx b/src/components/DialogBox/index.tsx index 5f70304c6..fce23fd69 100644 --- a/src/components/DialogBox/index.tsx +++ b/src/components/DialogBox/index.tsx @@ -13,6 +13,7 @@ import DialogTitleWithCloseButton, { } from './TitleWithCloseButton'; import DialogBoxBase from './base'; import { DialogBoxAttributes } from 'types/dialogBox'; +import DialogIcon from './DialogIcon'; type IProps = React.PropsWithChildren< Omit & { @@ -48,6 +49,7 @@ export default function DialogBox({ maxWidth={size} onClose={handleClose} {...props}> + {attributes.icon && } {attributes.title && ( Date: Mon, 31 Oct 2022 13:53:00 +0530 Subject: [PATCH 4/4] update update dialog message --- src/pages/_app.tsx | 12 +++++++----- src/utils/strings/englishConstants.tsx | 4 ++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index ed7d23c3e..7abaf05ed 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -29,6 +29,7 @@ import { CustomError } from 'utils/error'; import { clearLogsIfLocalStorageLimitExceeded } from 'utils/logging'; import isElectron from 'is-electron'; import ElectronUpdateService from 'services/electron/update'; +import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome'; export const MessageContainer = styled('div')` background-color: #111; @@ -143,16 +144,17 @@ export default function App({ Component, err }) { if (isElectron()) { const showUpdateDialog = () => setDialogMessage({ - title: constants.STOP_WATCHING_FOLDER, - content: constants.STOP_WATCHING_DIALOG_MESSAGE, + icon: , + title: constants.UPDATE_AVAILABLE, + content: constants.UPDATE_AVAILABLE_MESSAGE, close: { - text: constants.CANCEL, + text: constants.INSTALL_ON_NEXT_LAUNCH, variant: 'secondary', }, proceed: { action: () => ElectronUpdateService.updateAndRestart(), - text: constants.YES_STOP, - variant: 'danger', + text: constants.INSTALL_NOW, + variant: 'accent', }, }); ElectronUpdateService.registerUpdateEventListener(showUpdateDialog); diff --git a/src/utils/strings/englishConstants.tsx b/src/utils/strings/englishConstants.tsx index 032d55515..6cc9d3164 100644 --- a/src/utils/strings/englishConstants.tsx +++ b/src/utils/strings/englishConstants.tsx @@ -825,6 +825,10 @@ const englishConstants = { UPLOADED_TO_SINGLE_COLLECTION: 'Uploaded to single collection', UPLOADED_TO_SEPARATE_COLLECTIONS: 'Uploaded to separate collections', 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;