Skip to content
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

[UI/UX] Replace native dialogs #1891

Merged
merged 25 commits into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from 18 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@
"typescript": "^4.6.3",
"vite": "^3.0.3",
"vite-plugin-electron": "^0.8.3",
"vite-plugin-svgr": "^2.2.1",
"vite-tsconfig-paths": "^3.5.0"
"vite-plugin-svgr": "^2.2.1"
}
}
2 changes: 1 addition & 1 deletion src/backend/anticheat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { heroicAnticheatDataPath, isLinux } from '../constants'
import * as axios from 'axios'
import { logInfo, LogPrefix, logWarning } from '../logger/logger'
import { readFileSync, writeFileSync } from 'graceful-fs'
import { AntiCheatInfo } from 'common/types'
import { AntiCheatInfo } from '@@/common/types'
import { runOnceWhenOnline } from '../online_monitor'

async function downloadAntiCheatData() {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
InstallPlatform,
ConnectivityChangedCallback,
ConnectivityStatus
} from '../../common/types'
} from '@@/common/types'

export const notify = (notification: string[]) =>
ipcRenderer.send('Notify', notification)
Expand Down
4 changes: 1 addition & 3 deletions src/backend/api/library.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron'
import { Runner, InstallParams, LaunchParams } from '../../common/types'
import { Runner, InstallParams, LaunchParams } from '@@/common/types'

export const removeFolder = (args: [path: string, folderName: string]) =>
ipcRenderer.send('removeFolder', args)
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/backend/api/menu.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron'
import { Runner } from '../../common/types'
import { Runner } from '@@/common/types'

export const removeShortcut = (appName: string, runner: Runner) =>
ipcRenderer.send('removeShortcut', appName, runner)
Expand Down
18 changes: 12 additions & 6 deletions src/backend/api/misc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GOGCloudSavesLocation } from 'common/types/gog'
import { GOGCloudSavesLocation } from '@@/common/types/gog'
import { ipcRenderer } from 'electron'
import { Runner, Tools } from '../../common/types'
import { Runner, Tools, ButtonOptions, DialogType } from '@@/common/types'

export const clearCache = () => ipcRenderer.send('clearCache')
export const resetHeroic = () => ipcRenderer.send('resetHeroic')
Expand Down 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,
type: DialogType,
buttons?: Array<ButtonOptions>
) => 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
2 changes: 1 addition & 1 deletion src/backend/api/wine.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipcRenderer } from 'electron'
import { RuntimeName, WineVersionInfo } from '../../common/types'
import { RuntimeName, WineVersionInfo } from '@@/common/types'
import { ProgressInfo, State } from 'heroic-wine-downloader'

export const toggleDXVK = (
Expand Down
2 changes: 1 addition & 1 deletion src/backend/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
AppSettings,
GlobalConfigVersion,
WineInstallation
} from 'common/types'
} from '@@/common/types'
import { LegendaryUser } from './legendary/user'
import {
currentGlobalConfigVersion,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { join, resolve } from 'path'
import Store from 'electron-store'
import { parse } from '@node-steam/vdf'

import { GameConfigVersion, GlobalConfigVersion } from 'common/types'
import { GameConfigVersion, GlobalConfigVersion } from '@@/common/types'
import { logDebug, LogPrefix } from './logger/logger'
import { createNewLogFileAndClearOldOnces } from './logger/logfile'
import { env } from 'process'
Expand Down
2 changes: 1 addition & 1 deletion src/backend/dialog/__mocks__/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const dialog = jest.requireActual('../dialog')

dialog.showErrorBoxModalAuto = jest.fn()
dialog.showDialogBoxModalAuto = jest.fn()

module.exports = dialog
export {}
41 changes: 33 additions & 8 deletions src/backend/dialog/dialog.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,55 @@
import { LogPrefix, logWarning } from '../logger/logger'
import { BrowserWindow, dialog } from 'electron'
import { ButtonOptions, DialogType } from '@@/common/types'

const { showErrorBox } = dialog
const { showErrorBox, showMessageBox } = dialog

function showErrorBoxModalAuto(props: {
function showDialogBoxModalAuto(props: {
event?: Electron.IpcMainInvokeEvent
title: string
error: string
message: string
type: DialogType
buttons?: Array<ButtonOptions>
}) {
if (props.event) {
props.event.sender.send('showErrorDialog', props.title, props.error)
props.event.sender.send(
'showDialog',
props.title,
props.message,
props.type,
props.buttons
)
} 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.message,
props.type,
props.buttons
)
} catch (error) {
logWarning(['showErrorBoxModalAuto:', error], {
logWarning(['showDialogBoxModalAuto:', error], {
prefix: LogPrefix.Backend
})
showErrorBox(props.title, props.error)
switch (props.type) {
case 'ERROR':
showErrorBox(props.title, props.message)
break
default:
showMessageBox(BrowserWindow.getAllWindows()[0], {
title: props.title,
message: props.message
})
break
}
}
}
}

export { showErrorBoxModalAuto }
export { showDialogBoxModalAuto }
10 changes: 0 additions & 10 deletions src/backend/dialog/ipc_handler.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/backend/game_config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { existsSync, readFileSync, writeFileSync } from 'graceful-fs'

import { GameConfigVersion, GameSettings } from 'common/types'
import { GameConfigVersion, GameSettings } from '@@/common/types'
import { GlobalConfig } from './config'
import {
currentGameConfigVersion,
Expand Down
6 changes: 3 additions & 3 deletions src/backend/games.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GOGCloudSavesLocation, GogInstallInfo } from 'common/types/gog'
import { LegendaryInstallInfo } from 'common/types/legendary'
import { GOGCloudSavesLocation, GogInstallInfo } from '@@/common/types/gog'
import { LegendaryInstallInfo } from '@@/common/types/legendary'
import {
ExecResult,
ExtraInfo,
GameInfo,
GameSettings,
InstallArgs
} from 'common/types'
} from '@@/common/types'

import { BrowserWindow } from 'electron'
import { join } from 'path'
Expand Down
16 changes: 9 additions & 7 deletions src/backend/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
ExecResult,
InstallArgs,
InstalledInfo
} from 'common/types'
} from '@@/common/types'
import { appendFileSync, existsSync, rmSync } from 'graceful-fs'
import {
heroicGamesConfigPath,
Expand Down Expand Up @@ -47,9 +47,9 @@ import {
GOGCloudSavesLocation,
GogInstallInfo,
GogInstallPlatform
} from 'common/types/gog'
} from '@@/common/types/gog'
import { t } from 'i18next'
import { showErrorBoxModalAuto } from '../dialog/dialog'
import { showDialogBoxModalAuto } from '../dialog/dialog'

class GOGGame extends Game {
public appName: string
Expand Down Expand Up @@ -336,9 +336,10 @@ class GOGGame extends Game {
this.logFileLocation,
`Launch aborted: ${launchPrepFailReason}`
)
showErrorBoxModalAuto({
showDialogBoxModalAuto({
title: t('box.error.launchAborted', 'Launch aborted'),
error: launchPrepFailReason!
message: launchPrepFailReason!,
type: 'ERROR'
})
return false
}
Expand All @@ -363,9 +364,10 @@ class GOGGame extends Game {
this.logFileLocation,
`Launch aborted: ${wineLaunchPrepFailReason}`
)
showErrorBoxModalAuto({
showDialogBoxModalAuto({
title: t('box.error.launchAborted', 'Launch aborted'),
error: wineLaunchPrepFailReason!
message: wineLaunchPrepFailReason!,
type: 'ERROR'
})
return false
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/gog/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
GOGImportData,
ExecResult,
CallRunnerOptions
} from 'common/types'
import { GOGCloudSavesLocation, GogInstallInfo } from 'common/types/gog'
} from '@@/common/types'
import { GOGCloudSavesLocation, GogInstallInfo } from '@@/common/types/gog'
import { join } from 'node:path'
import { existsSync, readFileSync } from 'graceful-fs'

Expand Down
2 changes: 1 addition & 1 deletion src/backend/gog/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { copySync } from 'fs-extra'
import path from 'node:path'
import { GOGLibrary } from './library'
import { GameInfo, InstalledInfo } from 'common/types'
import { GameInfo, InstalledInfo } from '@@/common/types'
import { execAsync, quoteIfNecessary } from '../utils'
import { GameConfig } from '../game_config'
import { logError, logInfo, LogPrefix, logWarning } from '../logger/logger'
Expand Down
2 changes: 1 addition & 1 deletion src/backend/gog/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios'
import { logError, logInfo, LogPrefix, logWarning } from '../logger/logger'
import { GOGLoginData } from 'common/types'
import { GOGLoginData } from '@@/common/types'
import { configStore, libraryStore } from '../gog/electronStores'
import { errorHandler } from '../utils'
import { isOnline } from '../online_monitor'
Expand Down
18 changes: 10 additions & 8 deletions src/backend/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ import {
GameSettings,
LaunchPreperationResult,
RpcClient
} from 'common/types'
} from '@@/common/types'
import { spawn } from 'child_process'
import shlex from 'shlex'
import { Game } from './games'
import { isOnline } from './online_monitor'
import { showErrorBoxModalAuto } from './dialog/dialog'
import { showDialogBoxModalAuto } from './dialog/dialog'

async function prepareLaunch(
game: LegendaryGame | GOGGame,
Expand Down Expand Up @@ -151,12 +151,13 @@ async function prepareWineLaunch(game: LegendaryGame | GOGGame): Promise<{
// Verify that a Wine binary is set
// This happens when there aren't any Wine versions installed
if (!gameSettings.wineVersion.bin) {
showErrorBoxModalAuto({
showDialogBoxModalAuto({
title: i18next.t('box.error.wine-not-found.title', 'Wine Not Found'),
error: i18next.t(
message: i18next.t(
'box.error.wine-not-found.message',
'No Wine Version Selected. Check Game Settings!'
)
),
type: 'ERROR'
})
return { success: false }
}
Expand All @@ -180,16 +181,17 @@ async function prepareWineLaunch(game: LegendaryGame | GOGGame): Promise<{
)
)
if (!bottleExists) {
showErrorBoxModalAuto({
showDialogBoxModalAuto({
title: i18next.t(
'box.error.cx-bottle-not-found.title',
'CrossOver bottle not found'
),
error: i18next.t(
message: i18next.t(
'box.error.cx-bottle-not-found.message',
`The CrossOver bottle "{{bottle_name}}" does not exist, can't launch!`,
{ bottle_name: gameSettings.wineCrossoverBottle }
)
),
type: 'ERROR'
})
return { success: false }
}
Expand Down
14 changes: 8 additions & 6 deletions src/backend/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
GameInfo,
InstallArgs,
InstallPlatform
} from 'common/types'
} from '@@/common/types'
import { Game } from '../games'
import { GameConfig } from '../game_config'
import { GlobalConfig } from '../config'
Expand Down Expand Up @@ -40,7 +40,7 @@ import { removeNonSteamGame } from '../shortcuts/nonesteamgame/nonesteamgame'
import shlex from 'shlex'
import { t } from 'i18next'
import { isOnline } from '../online_monitor'
import { showErrorBoxModalAuto } from '../dialog/dialog'
import { showDialogBoxModalAuto } from '../dialog/dialog'

class LegendaryGame extends Game {
public appName: string
Expand Down Expand Up @@ -582,9 +582,10 @@ class LegendaryGame extends Game {
this.logFileLocation,
`Launch aborted: ${launchPrepFailReason}`
)
showErrorBoxModalAuto({
showDialogBoxModalAuto({
title: t('box.error.launchAborted', 'Launch aborted'),
error: launchPrepFailReason!
message: launchPrepFailReason!,
type: 'ERROR'
})
return false
}
Expand Down Expand Up @@ -614,9 +615,10 @@ class LegendaryGame extends Game {
this.logFileLocation,
`Launch aborted: ${wineLaunchPrepFailReason}`
)
showErrorBoxModalAuto({
showDialogBoxModalAuto({
title: t('box.error.launchAborted', 'Launch aborted'),
error: wineLaunchPrepFailReason!
message: wineLaunchPrepFailReason!,
type: 'ERROR'
})
return false
}
Expand Down