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

[Tech] Enable sandboxing for ipcRenderer Processes #1783

Merged
merged 20 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1d7a8ad
Refactored all ipcRenderer calls into preload script
BrettCleary Sep 3, 2022
a2f465f
preload script working, context isolation enabled
BrettCleary Sep 6, 2022
b98c4a7
Cleaning up code, adding comments documenting design decisions
BrettCleary Sep 7, 2022
91068c8
preload path in vite.config plugin, checks if legendary folder exists…
BrettCleary Sep 7, 2022
c9a4d41
Merge branch 'main' of github.com:Heroic-Games-Launcher/HeroicGamesLa…
flavioislima Sep 7, 2022
7c0049f
[Fix] Check if Legendary's `metadata` folder exists before trying to …
CommandMC Sep 7, 2022
335a88e
Merge branch 'beta' into enableSandboxing
BrettCleary Sep 7, 2022
66d7657
refactor ipcRenderer calls in Tools component
BrettCleary Sep 9, 2022
1cc2224
fixing yarn codecheck issues with window.api calls
BrettCleary Sep 12, 2022
e96e7b2
fixed type issues window api install and rm wine
BrettCleary Sep 12, 2022
d8bf7b8
Merge remote-tracking branch 'upstream/beta' into enableSandboxing
BrettCleary Sep 12, 2022
67f0319
changed frontend error call to logError, removed superfluous comments
BrettCleary Sep 12, 2022
e41bdcd
installParams type now used in library api, library will refresh inst…
BrettCleary Sep 15, 2022
c60b240
Merge branch 'beta' into enableSandboxing
BrettCleary Sep 15, 2022
2ddd9d0
cleaning up after resolving conflicts with beta
BrettCleary Sep 15, 2022
2d2e15b
removing multiple imports
BrettCleary Sep 15, 2022
4268d3a
fixing wine progress issue, rm isDefault
BrettCleary Sep 16, 2022
7d96511
renaming handleProgressOf to handleProgressOfWineManager
BrettCleary Sep 16, 2022
906edaa
wine manager download progress fixes
BrettCleary Sep 18, 2022
c069fbd
typing wine api methods
BrettCleary Sep 18, 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
26 changes: 13 additions & 13 deletions src/backend/api/library.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
import { ipcRenderer } from 'electron'
import { Runner, InstallPlatform, LaunchParams } from '../../common/types'
import { Runner, InstallParams, LaunchParams } from '../../common/types'

export const removeFolder = (args: [path: string, folderName: string]) =>
ipcRenderer.send('removeFolder', args)

export const openDialog = async (args: Electron.OpenDialogOptions) =>
ipcRenderer.invoke('openDialog', args)
interface InstallArgs {
appName: string
path: string
installDlcs: boolean
sdlList: string[]
installLanguage?: string
runner: Runner
platformToInstall?: InstallPlatform
}
export const install = async (args: InstallArgs) =>

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, checkboxChecked: boolean, runner: Runner]
args: [appName: string, shouldRemovePrefix: boolean, runner: Runner]
) => ipcRenderer.invoke('uninstall', args)
export const repair = async (appName: string, runner: Runner) =>
ipcRenderer.invoke('repair', appName, runner)
Expand All @@ -38,8 +30,16 @@ export const importGame = async (args: ImportGameArgs) =>
ipcRenderer.invoke('importGame', args)

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const handleSetGameStatus = (callback: any) =>
export const handleSetGameStatus = (callback: any) => {
ipcRenderer.on('setGameStatus', callback)
return () => {
ipcRenderer.removeListener('setGameStatus', callback)
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
// export const setGameStatusRemoveListener = (onGameStatusUpdate: any) => {
// ipcRenderer.removeListener('setGameStatus', onGameStatusUpdate)
// }
BrettCleary marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const handleProgressOf = (version: string, callback: any) =>
ipcRenderer.on('progressOf' + version, callback)
BrettCleary marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
3 changes: 0 additions & 3 deletions src/backend/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ export const getAnticheatInfo = async (namespace: string) =>

export const requestSettingsRemoveListeners = () =>
ipcRenderer.removeAllListeners('requestSettings')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const setGameStatusRemoveListener = (onGameStatusUpdate: any) =>
ipcRenderer.removeListener('setGameStatus', onGameStatusUpdate)

export const clipboardReadText = async () =>
ipcRenderer.invoke('clipboardReadText')
Expand Down
16 changes: 8 additions & 8 deletions src/backend/gog/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ export class GOGLibrary {
return
}
this.refreshInstalled()
for (const game of libraryStore.get('games', []) as GameInfo[]) {
const copyObject = { ...game }
if (this.installedGames.has(game.app_name)) {
copyObject.install = this.installedGames.get(game.app_name)!
copyObject.is_installed = true
}
this.library.set(game.app_name, copyObject)
}
BrettCleary marked this conversation as resolved.
Show resolved Hide resolved

if (!isOnline()) {
for (const game of libraryStore.get('games', []) as GameInfo[]) {
const copyObject = { ...game }
if (this.installedGames.has(game.app_name)) {
copyObject.install = this.installedGames.get(game.app_name)!
copyObject.is_installed = true
}
this.library.set(game.app_name, copyObject)
}
return
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
ipcMain,
powerSaveBlocker,
protocol,
screen
screen,
clipboard
} from 'electron'
import './updater'
import { autoUpdater } from 'electron-updater'
Expand Down Expand Up @@ -118,7 +119,6 @@ import { gameInfoStore } from './legendary/electronStores'
import { getFonts } from 'font-list'
import { verifyWinePrefix } from './launcher'
import shlex from 'shlex'
import { clipboard } from 'electron'

const { showMessageBox, showOpenDialog } = dialog
const isWindows = platform() === 'win32'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import classNames from 'classnames'
import React, { useContext, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { faDiscord, faPatreon } from '@fortawesome/free-brands-svg-icons'
import {
faCoffee,
faUserAlt,
faWineGlass
} from '@fortawesome/free-solid-svg-icons'
import { openDiscordLink, getGameInfo } from 'frontend/helpers'

import ContextProvider from 'frontend/state/ContextProvider'
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/helpers/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ async function install({
path: `${path}`,
installDlcs,
sdlList,
runner
runner,
platformToInstall
})
.finally(() => {
if (progress.percent === 100) {
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/hooks/hasProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ export const hasProgress = (appName: string) => {
})
}
}
window.api.handleSetGameStatus(onGameStatusUpdate)
const setGameStatusRemoveListener =
window.api.handleSetGameStatus(onGameStatusUpdate)

return () => {
window.api.setGameStatusRemoveListener(onGameStatusUpdate)
setGameStatusRemoveListener()
}
}, [])

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { initShortcuts } from './helpers/shortcuts'
import { configStore } from './helpers/electronStores'

window.addEventListener('error', (ev: ErrorEvent) => {
window.api.logError(ev.error.stack)
window.api.logError(ev.error)
})

const Backend = new HttpApi(null, {
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/screens/Game/GamePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import {
sendKill,
size,
syncSaves,
updateGame,
ipcRenderer
updateGame
} from 'frontend/helpers'
import { Link, NavLink, useParams } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
Expand Down
7 changes: 1 addition & 6 deletions src/frontend/screens/Game/GameSubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import React, { useContext, useEffect, useState } from 'react'
import { AppSettings, GameStatus, Runner } from 'common/types'

import { SmallInfo } from 'frontend/components/UI'
import {
createNewWindow,
getGameInfo,
repair,
ipcRenderer
} from 'frontend/helpers'
import { createNewWindow, getGameInfo, repair } from 'frontend/helpers'
import { useTranslation } from 'react-i18next'
import ContextProvider from 'frontend/state/ContextProvider'
import { uninstall } from 'frontend/helpers/library'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import {
getProgress,
install,
size,
writeConfig,
ipcRenderer
writeConfig
} from 'frontend/helpers'
import ContextProvider from 'frontend/state/ContextProvider'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ export default function RecentlyPlayed({ handleModal, onlyInstalled }: Props) {
}

useEffect(() => {
window.api.handleSetGameStatus(onGameStatusUpdates)
const setGameStatusRemoveListener =
window.api.handleSetGameStatus(onGameStatusUpdates)

return () => {
window.api.setGameStatusRemoveListener(onGameStatusUpdates)
setGameStatusRemoveListener()
}
})

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/screens/Library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ export default function Library(): JSX.Element {
const notInstalled = library.filter(
(g) => !g.is_installed && !installing.includes(g.app_name)
)
const installingGames = library.filter((g) =>
installing.includes(g.app_name)
const installingGames = library.filter(
(g) => !g.is_installed && installing.includes(g.app_name)
)
library = sortInstalled
? [...installed, ...installingGames, ...notInstalled]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export const AdvancedSettings = ({
const storage: Storage = window.localStorage
storage.removeItem('updates')
return window.api.clearCache()
return refreshLibrary({ fullRefresh: true, runInBackground: true })
}

return (
Expand Down
12 changes: 10 additions & 2 deletions src/frontend/screens/Settings/components/LogSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ export default function LogSettings({ isDefault, appName }: LogSettingsProps) {

const getLogContent = () => {
window.api
.getLogContent({ isDefault, appName, defaultLast })
.getLogContent({
isDefault,
appName: isDefault ? '' : appName,
defaultLast
})
BrettCleary marked this conversation as resolved.
Show resolved Hide resolved
.then((content: string) => {
setLogFileContent(content)
setLogFileExist(true)
Expand All @@ -98,7 +102,11 @@ export default function LogSettings({ isDefault, appName }: LogSettingsProps) {
}, [isDefault, defaultLast])

function showLogFileInFolder() {
window.api.showLogFileInFolder({ isDefault, appName })
window.api.showLogFileInFolder({
isDefault,
appName: isDefault ? '' : appName,
defaultLast
})
BrettCleary marked this conversation as resolved.
Show resolved Hide resolved
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ import CreateNewFolder from '@mui/icons-material/CreateNewFolder'
import { EnviromentVariable, WrapperVariable, Runner } from 'common/types'
import { Path } from 'frontend/types'
import Backspace from '@mui/icons-material/Backspace'
import { getGameInfo, ipcRenderer } from 'frontend/helpers'
import { getGameInfo } from 'frontend/helpers'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCircleInfo } from '@fortawesome/free-solid-svg-icons'
import { faFolderOpen } from '@fortawesome/free-solid-svg-icons'
import { faCircleInfo, faFolderOpen } from '@fortawesome/free-solid-svg-icons'
import {
ColumnProps,
TableInput
Expand Down
7 changes: 3 additions & 4 deletions src/frontend/state/GlobalState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
InstalledInfo,
RefreshOptions,
Runner,
WineVersionInfo
WineVersionInfo,
UserInfo
} from 'common/types'
import { Category, LibraryTopSectionOptions } from 'frontend/types'
import { TFunction, withTranslation } from 'react-i18next'
Expand All @@ -17,8 +18,7 @@ import {
getPlatform,
install,
launch,
notify,
ipcRenderer
notify
} from '../helpers'
import { i18n, t } from 'i18next'

Expand All @@ -32,7 +32,6 @@ import {
libraryStore,
wineDownloaderInfoStore
} from '../helpers/electronStores'
import { UserInfo } from 'common/types'

const storage: Storage = window.localStorage

Expand Down