Skip to content

Commit

Permalink
Move function to tools instead of importing from main
Browse files Browse the repository at this point in the history
  • Loading branch information
arielj committed Oct 1, 2023
1 parent 126ae39 commit c04f991
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 47 deletions.
46 changes: 1 addition & 45 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
DiskSpaceData,
StatusPromise,
GamepadInputEvent,
WineCommandArgs,
ExecResult,
Runner
} from 'common/types'
import * as path from 'path'
Expand Down Expand Up @@ -51,7 +49,6 @@ import { GOGUser } from './storeManagers/gog/user'
import { NileUser } from './storeManagers/nile/user'
import {
clearCache,
execAsync,
isEpicServiceOffline,
handleExit,
openUrlOrFile,
Expand Down Expand Up @@ -109,7 +106,7 @@ import {
} from './logger/logger'
import { gameInfoStore } from 'backend/storeManagers/legendary/electronStores'
import { getFonts } from 'font-list'
import { prepareWineLaunch, runWineCommand } from './launcher'
import { runWineCommand } from './launcher'
import shlex from 'shlex'
import { initQueue } from './downloadmanager/downloadqueue'
import {
Expand Down Expand Up @@ -591,31 +588,6 @@ ipcMain.on('removeFolder', async (e, [path, folderName]) => {
removeFolder(path, folderName)
})

export async function runWineCommandOnGame(
runner: Runner,
appName: string,
{ commandParts, wait = false, protonVerb, startFolder }: WineCommandArgs
): Promise<ExecResult> {
if (gameManagerMap[runner].isNative(appName)) {
logError('runWineCommand called on native game!', LogPrefix.Gog)
return { stdout: '', stderr: '' }
}
const { folder_name, install } = gameManagerMap[runner].getGameInfo(appName)
const gameSettings = await gameManagerMap[runner].getSettings(appName)

await prepareWineLaunch(runner, appName)

return runWineCommand({
gameSettings,
installFolderName: folder_name,
gameInstallPath: install.install_path,
commandParts,
wait,
protonVerb,
startFolder
})
}

ipcMain.handle('runWineCommand', async (e, args) => runWineCommand(args))

/// IPC handlers begin here.
Expand Down Expand Up @@ -1548,22 +1520,6 @@ ipcMain.handle('getFonts', async (event, reload) => {
return cachedFonts
})

ipcMain.handle(
'runWineCommandForGame',
async (event, { appName, commandParts, runner }) => {
if (isWindows) {
return execAsync(commandParts.join(' '))
}

// FIXME: Why are we using `runinprefix` here?
return runWineCommandOnGame(runner, appName, {
commandParts,
wait: false,
protonVerb: 'runinprefix'
})
}
)

ipcMain.handle('getShellPath', async (event, path) => getShellPath(path))

ipcMain.handle('clipboardReadText', () => clipboard.readText())
Expand Down
45 changes: 43 additions & 2 deletions src/backend/tools.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GameSettings, Runner } from 'common/types'
import { ExecResult, GameSettings, Runner, WineCommandArgs } from 'common/types'
import axios from 'axios'
import {
existsSync,
Expand All @@ -25,6 +25,7 @@ import path, { dirname, join } from 'path'
import { isOnline } from './online_monitor'
import { showDialogBoxModalAuto } from './dialog/dialog'
import {
prepareWineLaunch,
runWineCommand,
setupEnvVars,
setupWineEnvVars,
Expand All @@ -39,7 +40,6 @@ import {
import { lt as semverLt } from 'semver'
import { gameManagerMap } from './storeManagers'
import { ipcMain } from 'electron'
import { runWineCommandOnGame } from './main'
import { sendFrontendMessage } from './main_window'

export const DXVK = {
Expand Down Expand Up @@ -706,6 +706,47 @@ function getVkd3dUrl(): string {
return 'https://api.github.com/repos/Heroic-Games-Launcher/vkd3d-proton/releases/latest'
}

ipcMain.handle(
'runWineCommandForGame',
async (event, { appName, commandParts, runner }) => {
if (isWindows) {
return execAsync(commandParts.join(' '))
}

// FIXME: Why are we using `runinprefix` here?
return runWineCommandOnGame(runner, appName, {
commandParts,
wait: false,
protonVerb: 'runinprefix'
})
}
)

async function runWineCommandOnGame(
runner: Runner,
appName: string,
{ commandParts, wait = false, protonVerb, startFolder }: WineCommandArgs
): Promise<ExecResult> {
if (gameManagerMap[runner].isNative(appName)) {
logError('runWineCommand called on native game!', LogPrefix.Gog)
return { stdout: '', stderr: '' }
}
const { folder_name, install } = gameManagerMap[runner].getGameInfo(appName)
const gameSettings = await gameManagerMap[runner].getSettings(appName)

await prepareWineLaunch(runner, appName)

return runWineCommand({
gameSettings,
installFolderName: folder_name,
gameInstallPath: install.install_path,
commandParts,
wait,
protonVerb,
startFolder
})
}

// Calls WineCFG or Winetricks. If is WineCFG, use the same binary as wine to launch it to dont update the prefix
ipcMain.handle('callTool', async (event, { tool, exe, appName, runner }) => {
const gameSettings = await gameManagerMap[runner].getSettings(appName)
Expand Down

0 comments on commit c04f991

Please sign in to comment.