Skip to content

[Fix] Some things missed in the EOS Overlay PR #1563

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 10 commits into from
Jul 16, 2022
50 changes: 44 additions & 6 deletions electron/legendary/eos_overlay/eos_overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { logError, LogPrefix, logWarning } from '../../logger/logger'
import { runLegendaryCommand } from '../library'
import { LegendaryGame } from '../games'
import { killPattern } from '../../utils'
import { Runner } from '../../types'
import { Game } from '../../games'
import { verifyWinePrefix } from '../../launcher'

const currentVersionPath = join(legendaryConfigPath, 'overlay_version.json')
const installedVersionPath = join(legendaryConfigPath, 'overlay_install.json')
Expand Down Expand Up @@ -39,6 +42,10 @@ function getStatus(): {

async function getLatestVersion() {
if (!existsSync(currentVersionPath)) {
// HACK: `overlay_version.json` isn't created when the overlay isn't installed
if (!isInstalled()) {
return ''
}
await updateInfo()
if (!existsSync(currentVersionPath)) {
logError(
Expand All @@ -55,6 +62,11 @@ async function getLatestVersion() {
}

async function updateInfo() {
// Without the overlay being installed, this will do nothing at all.
// So we can just skip running the command if that's the case
if (!isInstalled()) {
return
}
await runLegendaryCommand(['status'], {
logMessagePrefix: 'Updating EOS Overlay information'
})
Expand Down Expand Up @@ -127,8 +139,17 @@ function cancelInstallOrUpdate() {
}

async function enable(
prefix: string
appName: string,
runner: Runner
): Promise<{ wasEnabled: boolean; installNow?: boolean }> {
let prefix = ''
if (isLinux) {
const game = Game.get(appName, runner)
await verifyWinePrefix(game)
const { winePrefix, wineVersion } = await game.getSettings()
prefix =
wineVersion.type === 'proton' ? join(winePrefix, 'pfx') : winePrefix
}
if (!isInstalled()) {
const { response } = await dialog.showMessageBox({
title: t('setting.eosOverlay.notInstalledTitle', 'Overlay not installed'),
Expand All @@ -148,7 +169,15 @@ async function enable(
return { wasEnabled: true }
}

async function disable(prefix: string) {
async function disable(appName: string, runner: Runner) {
let prefix = ''
if (isLinux) {
const game = Game.get(appName, runner)
const { winePrefix, wineVersion } = await game.getSettings()
prefix =
wineVersion.type === 'proton' ? join(winePrefix, 'pfx') : winePrefix
}

await runLegendaryCommand(
['eos-overlay', 'disable', ...(prefix ? ['--prefix', prefix] : [])],
{ logMessagePrefix: 'Disabling EOS Overlay' }
Expand All @@ -159,12 +188,21 @@ function isInstalled() {
return existsSync(installedVersionPath)
}

async function isEnabled(prefix: string) {
/**
* Checks if the EOS Overlay is enabled (either for a specific game on Linux or globally on Windows)
* @param appName required on Linux, does nothing on Windows
* @param runner required on Linux, does nothing on Windows
* @returns Enabled = True; Disabled = False
*/
async function isEnabled(appName?: string, runner?: Runner) {
let enabled = false

// The overlay can't be enabled globally on Linux
if (isLinux && !prefix) {
return false
let prefix = ''
if (isLinux || !(appName && runner)) {
const game = Game.get(appName, runner)
const { winePrefix, wineVersion } = await game.getSettings()
prefix =
wineVersion.type === 'proton' ? join(winePrefix, 'pfx') : winePrefix
}

await runLegendaryCommand(
Expand Down
12 changes: 6 additions & 6 deletions electron/legendary/eos_overlay/ipc_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ ipcMain.handle('updateEosOverlayInfo', updateInfo)
ipcMain.handle('installEosOverlay', install)
ipcMain.handle('removeEosOverlay', remove)
ipcMain.handle('cancelEosOverlayInstallOrUpdate', cancelInstallOrUpdate)
ipcMain.handle('enableEosOverlay', async (e, prefix) => {
return enable(prefix)
ipcMain.handle('enableEosOverlay', async (e, appName, runner) => {
return enable(appName, runner)
})
ipcMain.handle('disableEosOverlay', async (e, prefix) => {
return disable(prefix)
ipcMain.handle('disableEosOverlay', async (e, appName, runner) => {
return disable(appName, runner)
})
ipcMain.handle('isEosOverlayEnabled', async (e, prefix) => {
return isEnabled(prefix)
ipcMain.handle('isEosOverlayEnabled', async (e, appName?, runner?) => {
return isEnabled(appName, runner)
})
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function CurrentDownload({ appName, runner }: Props) {
<Box sx={{ width: '100%', mr: 1 }}>
<LinearProgress
variant="determinate"
value={progress.percent}
value={progress.percent || 0}
/>
</Box>
<Box sx={{ minWidth: 35 }}>
Expand Down
109 changes: 49 additions & 60 deletions src/screens/Game/GameSubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './index.css'

import React, { useContext, useEffect, useState } from 'react'

import { AppSettings, GameSettings, GameStatus, Runner } from 'src/types'
import { AppSettings, GameStatus, Runner } from 'src/types'

import { SmallInfo } from 'src/components/UI'
import { createNewWindow, getGameInfo, repair } from 'src/helpers'
Expand Down Expand Up @@ -99,12 +99,15 @@ export default function GamesSubmenu({
const isWin = platform === 'win32'
const isMac = platform === 'darwin'
const isLinux = platform === 'linux'
const [info, setInfo] = useState({ prefix: '', wine: '' } as otherInfo)
const [isNative, setIsNative] = useState(false)
const [info, setInfo] = useState<otherInfo>({
prefix: '',
wine: ''
} as otherInfo)
const [isNative, setIsNative] = useState<boolean>(false)
const [steamRefresh, setSteamRefresh] = useState<boolean>(false)
const [addedToSteam, setAddedToSteam] = useState<boolean>(false)
const [eosOverlayEnabled, setEosOverlayEnabled] = useState(false)
const [eosOverlayRefresh, setEosOverlayRefresh] = useState(false)
const [eosOverlayEnabled, setEosOverlayEnabled] = useState<boolean>(false)
const [eosOverlayRefresh, setEosOverlayRefresh] = useState<boolean>(false)
const eosOverlayAppName = '98bc04bc842e4906993fd6d6644ffb8d'
const { t } = useTranslation('gamepage')

Expand Down Expand Up @@ -179,6 +182,43 @@ export default function GamesSubmenu({
ipcRenderer.send('addShortcut', appName, runner, true)
}

async function handleEosOverlay() {
setEosOverlayRefresh(true)
if (eosOverlayEnabled) {
await ipcRenderer.invoke('disableEosOverlay', appName, runner)
setEosOverlayEnabled(false)
} else {
const initialEnableResult = await ipcRenderer.invoke(
'enableEosOverlay',
appName,
runner
)
const { installNow } = initialEnableResult
let { wasEnabled } = initialEnableResult

if (installNow) {
await handleGameStatus({
appName: eosOverlayAppName,
runner: 'legendary',
status: 'installing'
})

await ipcRenderer.invoke('installEosOverlay')
await handleGameStatus({
appName: eosOverlayAppName,
runner: 'legendary',
status: 'done'
})

wasEnabled = (
await ipcRenderer.invoke('enableEosOverlay', appName, runner)
).wasEnabled
}
setEosOverlayEnabled(wasEnabled)
}
setEosOverlayRefresh(false)
}

async function handleAddToSteam() {
setSteamRefresh(true)
if (addedToSteam) {
Expand Down Expand Up @@ -230,67 +270,16 @@ export default function GamesSubmenu({
setAddedToSteam(added)
})

ipcRenderer
.invoke('requestSettings', appName)
.then(async (response: GameSettings | AppSettings) => {
console.log(response)
const enabled = await ipcRenderer.invoke(
'isEosOverlayEnabled',
response.winePrefix
)
setEosOverlayEnabled(enabled)
})
}, [])

useEffect(() => {
const { status } =
libraryStatus.filter(
(game: GameStatus) => game.appName === eosOverlayAppName
)[0] || {}
setEosOverlayRefresh(status === 'installing')
}, [eosOverlayRefresh])

async function handleEosOverlay() {
const { winePrefix, wineVersion } = await ipcRenderer.invoke(
'requestSettings',
appName
)
const actualPrefix =
wineVersion.type === 'proton' ? `${winePrefix}/pfx` : winePrefix

if (eosOverlayEnabled) {
await ipcRenderer.invoke('disableEosOverlay', actualPrefix)
setEosOverlayEnabled(false)
} else {
const initialEnableResult = await ipcRenderer.invoke(
'enableEosOverlay',
actualPrefix
)
const { installNow } = initialEnableResult
let { wasEnabled } = initialEnableResult

if (installNow) {
await handleGameStatus({
appName: eosOverlayAppName,
runner: 'legendary',
status: 'installing'
})
setEosOverlayRefresh(true)
await ipcRenderer.invoke('installEosOverlay')
await handleGameStatus({
appName: eosOverlayAppName,
runner: 'legendary',
status: 'done'
})
setEosOverlayRefresh(false)
wasEnabled = (
await ipcRenderer.invoke('enableEosOverlay', actualPrefix)
).wasEnabled
}

setEosOverlayEnabled(wasEnabled)
}
}
ipcRenderer
.invoke('isEosOverlayEnabled', appName, runner)
.then((enabled) => setEosOverlayEnabled(enabled))
}, [])

const refreshCircle = () => {
return <CircularProgress className="link button is-text is-link" />
Expand Down
Loading