Skip to content

[UI/UX] Replace native dialogs #1891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
ca0e466
replaced native uninstall dialog box with uninstall modal
BrettCleary Oct 10, 2022
156b1f0
refactoring into dialog handler to reduce boilerplate
BrettCleary Oct 10, 2022
e054ffe
refactor and rm showErrorBox and openMessageBox
BrettCleary Oct 11, 2022
3a31e2c
refactor showMessageBox in backend into frontend modals, improved dia…
BrettCleary Oct 11, 2022
803669a
ButtonOptions interface, DialotType enum, generic showDialogBoxModalA…
BrettCleary Oct 11, 2022
33cd781
rename showErrorBoxModalAuto to showDialog, close messageBoxModal on …
BrettCleary Oct 11, 2022
fbe1822
updating arguments for showDialogBoxModalAuto backend and button opti…
BrettCleary Oct 11, 2022
4836a46
C:/Program Files/Git/src/ absolute import alias refactor
BrettCleary Oct 12, 2022
2b25f14
change from src to @
BrettCleary Oct 13, 2022
a1595d8
fix import
BrettCleary Oct 13, 2022
efa38cb
removing enum from common types so imports work
BrettCleary Oct 13, 2022
5cd7e61
Merge branch 'beta' into feat/replace_native_dialogs
BrettCleary Oct 13, 2022
6762caa
change to @@, backend now can use absolute imports
BrettCleary Oct 13, 2022
7195b32
Merge branch 'feat/replace_native_dialogs' of https://github.com/Hero…
BrettCleary Oct 13, 2022
b4418ad
updating tests
BrettCleary Oct 13, 2022
5908109
updated logger tests
BrettCleary Oct 13, 2022
fba5fd6
fixing logger tests again
BrettCleary Oct 13, 2022
5961bab
tests again
BrettCleary Oct 13, 2022
c20de6a
replace @@ with src folder names
BrettCleary Oct 20, 2022
ea9015c
max width on dialog modal
BrettCleary Oct 20, 2022
738dd42
add back removed stuff
BrettCleary Oct 20, 2022
87aabc9
Merge branch 'beta' into feat/replace_native_dialogs
BrettCleary Oct 20, 2022
c4b7a80
rename to showDialogBoxModalAuto
BrettCleary Oct 20, 2022
377194d
prettier
BrettCleary Oct 20, 2022
28e33fc
reverting unneccessary changed
BrettCleary Oct 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/backend/api/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ export const openDialog = async (args: Electron.OpenDialogOptions) =>

export const install = async (args: InstallParams) =>
ipcRenderer.invoke('install', args)
export const openMessageBox = async (args: Electron.MessageBoxOptions) =>
ipcRenderer.invoke('openMessageBox', args)
export const uninstall = async (
args: [appName: string, shouldRemovePrefix: boolean, runner: Runner]
) => ipcRenderer.invoke('uninstall', args)
Expand Down
14 changes: 10 additions & 4 deletions src/backend/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,18 @@ export const clipboardReadText = async () =>
export const clipboardWriteText = async (text: string) =>
ipcRenderer.send('clipboardWriteText', text)

export const handleShowErrorDialog = (
onError: (e: Electron.IpcRendererEvent, title: string, error: string) => void
export const handleShowDialog = (
onMessage: (
e: Electron.IpcRendererEvent,
title: string,
message: string,
isError: boolean,
buttons: Array<string>
) => void
) => {
ipcRenderer.on('showErrorDialog', onError)
ipcRenderer.on('showDialog', onMessage)
return () => {
ipcRenderer.removeListener('showErrorDialog', onError)
ipcRenderer.removeListener('showDialog', onMessage)
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/backend/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export const showUpdateSetting = async () =>
ipcRenderer.invoke('showUpdateSetting')
export const egsSync = async (args: string) =>
ipcRenderer.invoke('egsSync', args)
export const showErrorBox = async (args: [title: string, message: string]) =>
ipcRenderer.invoke('showErrorBox', args)

export const showLogFileInFolder = (args: {
appName: string
Expand Down
4 changes: 2 additions & 2 deletions src/backend/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ function showErrorBoxModalAuto(props: {
error: string
}) {
if (props.event) {
props.event.sender.send('showErrorDialog', props.title, props.error)
props.event.sender.send('showDialog', props.title, props.error, true)
} else {
let window: BrowserWindow | null
try {
window = BrowserWindow.getFocusedWindow()
if (!window) {
window = BrowserWindow.getAllWindows()[0]
}
window.webContents.send('showErrorDialog', props.title, props.error)
window.webContents.send('showDialog', props.title, props.error, true)
} catch (error) {
logWarning(['showErrorBoxModalAuto:', error], {
prefix: LogPrefix.Backend
Expand Down
10 changes: 0 additions & 10 deletions src/backend/dialog/ipc_handler.ts

This file was deleted.

47 changes: 10 additions & 37 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ import {
} from './online_monitor'
import { showErrorBoxModalAuto } from './dialog/dialog'

const { showMessageBox, showOpenDialog } = dialog
const { showOpenDialog } = dialog
const isWindows = platform() === 'win32'

let mainWindow: BrowserWindow
Expand Down Expand Up @@ -700,31 +700,19 @@ ipcMain.handle('getLatestReleases', async () => {
}
})

ipcMain.on('clearCache', () => {
ipcMain.on('clearCache', (event) => {
clearCache()
dialog.showMessageBox(mainWindow, {
title: i18next.t('box.cache-cleared.title', 'Cache Cleared'),
message: i18next.t(
'box.cache-cleared.message',
'Heroic Cache Was Cleared!'
),
buttons: [i18next.t('box.ok', 'Ok')]
})
event.sender.send(
'showDialog',
i18next.t('box.cache-cleared.title', 'Cache Cleared'),
i18next.t('box.cache-cleared.message', 'Heroic Cache Was Cleared!'),
false,
[i18next.t('box.ok', 'Ok')]
)
})

ipcMain.on('resetHeroic', async () => {
const { response } = await dialog.showMessageBox(mainWindow, {
title: i18next.t('box.reset-heroic.question.title', 'Reset Heroic'),
message: i18next.t(
'box.reset-heroic.question.message',
"Are you sure you want to reset Heroic? This will remove all Settings and Caching but won't remove your Installed games or your Epic credentials. Portable versions (AppImage, WinPortable, ...) of heroic needs to be restarted manually afterwards."
),
buttons: [i18next.t('box.no'), i18next.t('box.yes')]
})

if (response === 1) {
resetHeroic()
}
resetHeroic()
})

ipcMain.on('createNewWindow', async (e, url) =>
Expand Down Expand Up @@ -1069,20 +1057,6 @@ ipcMain.on('showItemInFolder', async (e, item) => {
showItemInFolder(item)
})

const openMessageBox = async (args: Electron.MessageBoxOptions) => {
const { response, checkboxChecked } = await showMessageBox(mainWindow, {
...args
})
return { response, checkboxChecked }
}

ipcMain.handle(
'openMessageBox',
async (_, args: Electron.MessageBoxOptions) => {
return openMessageBox(args)
}
)

ipcMain.handle('install', async (event, params) => {
const {
appName,
Expand Down Expand Up @@ -1585,7 +1559,6 @@ import './shortcuts/ipc_handler'
import './anticheat/ipc_handler'
import './legendary/eos_overlay/ipc_handler'
import './wine/runtimes/ipc_handler'
import './dialog/ipc_handler'

// import Store from 'electron-store'
// interface StoreMap {
Expand Down
Empty file.
50 changes: 50 additions & 0 deletions src/frontend/components/UI/Dialog/MessageBoxModal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import './index.css'
import React from 'react'
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader
} from 'frontend/components/UI/Dialog'

interface MessageBoxModalProps {
title: string
message: string
onClose: () => void
buttons: Array<string>
buttonsOnClick: Array<() => void>
}

const MessageBoxModal: React.FC<MessageBoxModalProps> = function (props) {
const getButtons = function () {
const allButtons = []
for (
let i = 0;
i < props.buttons.length && i < props.buttonsOnClick.length;
++i
) {
allButtons.push(
<button
onClick={props.buttonsOnClick[i]}
className={`button is-secondary outline`}
key={'messageBoxModalButton_' + i.toString()}
>
{props.buttons[i]}
</button>
)
}
return allButtons
}

return (
<Dialog onClose={props.onClose}>
<DialogHeader onClose={props.onClose} showCloseButton={true}>
{props.title}
</DialogHeader>
<DialogContent>{props.message}</DialogContent>
<DialogFooter>{getButtons()}</DialogFooter>
</Dialog>
)
}

export default MessageBoxModal
1 change: 1 addition & 0 deletions src/frontend/components/UI/Dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './components/Dialog'
export * from './components/DialogContent'
export * from './components/DialogFooter'
export * from './components/DialogHeader'
export * from './MessageBoxModal'
68 changes: 47 additions & 21 deletions src/frontend/components/UI/DialogHandler/index.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
import React, { useEffect, useState } from 'react'
import ContextProvider from 'frontend/state/ContextProvider'
import React, { useEffect, useContext } from 'react'
import MessageBoxModal from '../Dialog/MessageBoxModal'
import { ErrorDialog } from './components/ErrorDialog'

export default function DialogHandler() {
const [showErrorDialog, setShowErrorDialog] = useState(false)
const [errorTitle, setErrorTitle] = useState('')
const [errorMessage, setErrorMessage] = useState('')
const { dialogModalOptions, showDialogModal } = useContext(ContextProvider)

useEffect(() => {
const onError = (
const onMessage = (
e: Electron.IpcRendererEvent,
title: string,
error: string
message: string,
isError: boolean,
buttons: Array<string>
) => {
setErrorTitle(title)
setErrorMessage(error)
setShowErrorDialog(true)
showDialogModal({ title, message, isError, buttons })
}

const removeHandleShowErrorDialogListener =
window.api.handleShowErrorDialog(onError)
const removeHandleShowDialogListener =
window.api.handleShowDialog(onMessage)

//useEffect unmount
return () => {
removeHandleShowErrorDialogListener()
removeHandleShowDialogListener()
}
}, [])

function onCloseErrorDialog() {
setShowErrorDialog(false)
const buttonsOnClick: Array<() => void> = []
if (dialogModalOptions.buttons) {
for (let i = 0; i < dialogModalOptions.buttons.length; ++i) {
/* eslint-disable @typescript-eslint/no-empty-function */
const val =
dialogModalOptions.buttonsOnClick &&
i < dialogModalOptions.buttonsOnClick.length
? dialogModalOptions.buttonsOnClick[i]
: () => {}
/* eslint-enable @typescript-eslint/no-empty-function */
buttonsOnClick.push(() => {
val()
showDialogModal({ showDialog: false })
})
}
}

return (
<>
{showErrorDialog && (
<ErrorDialog
title={errorTitle}
error={errorMessage}
onClose={onCloseErrorDialog}
/>
)}
{dialogModalOptions.showDialog &&
(dialogModalOptions.isError ? (
<ErrorDialog
title={dialogModalOptions.title ? dialogModalOptions.title : ''}
error={dialogModalOptions.message ? dialogModalOptions.message : ''}
onClose={() => showDialogModal({ showDialog: false })}
/>
) : (
<MessageBoxModal
title={dialogModalOptions.title ? dialogModalOptions.title : ''}
message={
dialogModalOptions.message ? dialogModalOptions.message : ''
}
buttons={
dialogModalOptions.buttons ? dialogModalOptions.buttons : []
}
buttonsOnClick={buttonsOnClick}
onClose={() => showDialogModal({ showDialog: false })}
/>
))}
</>
)
}
4 changes: 2 additions & 2 deletions src/frontend/components/UI/ErrorComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ContextProvider from 'frontend/state/ContextProvider'

export default function ErrorComponent({ message }: { message: string }) {
const { t } = useTranslation()
const { refreshLibrary } = useContext(ContextProvider)
const { refreshLibrary, showResetDialog } = useContext(ContextProvider)

return (
<div className="errorComponent">
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function ErrorComponent({ message }: { message: string }) {

<button
className="button is-footer is-danger"
onClick={window.api.resetHeroic}
onClick={showResetDialog}
>
<div className="button-icontext-flex">
<div className="button-icon-flex">
Expand Down
1 change: 1 addition & 0 deletions src/frontend/components/UI/ToggleSwitch/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
justify-items: flex-start;
text-align: start;
cursor: pointer;
white-space: pre-line;
}

.hiddenCheckbox {
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/components/UI/UninstallModal/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.uninstallModalMessage {
margin-bottom: var(--space-md);
}
Loading