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] Refactor Game Managers #2578

Merged
merged 26 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b9246ec
[Tech] Refactor game managers (#183)
BrettCleary Mar 17, 2023
42bc2a4
fix merge errors
BrettCleary Mar 28, 2023
4077228
fix build errors
BrettCleary Mar 28, 2023
3761817
rm unused vars
BrettCleary Mar 28, 2023
7cc5d04
prettier
BrettCleary Mar 28, 2023
d1ac2e7
Merge branch 'main' into tech/refactor_game_managers
BrettCleary Mar 28, 2023
6e97bfc
fix merge errors
BrettCleary Mar 28, 2023
6535396
change back to import folder
BrettCleary Mar 28, 2023
c004dd4
prettier fix
BrettCleary Mar 28, 2023
cb07624
revert importPath translation
BrettCleary Mar 28, 2023
f1d21d0
fix isNative check in main
BrettCleary Mar 28, 2023
12866ff
gog fixes
BrettCleary Mar 28, 2023
4fa0bfe
fix download manager successive installs
BrettCleary Mar 28, 2023
6261b35
fix gog import
BrettCleary Mar 28, 2023
4e616e7
fix deadcode
BrettCleary Mar 28, 2023
c97ed19
check anticheat on mac
BrettCleary Mar 28, 2023
242f960
rm main import
BrettCleary Mar 30, 2023
b151af0
add skip test on windows
BrettCleary Mar 30, 2023
063087b
Merge branch 'main' into tech/refactor_game_managers
BrettCleary Mar 30, 2023
40e050c
update games launch with merge changes
BrettCleary Mar 30, 2023
eaee68f
fix dead code
BrettCleary Mar 30, 2023
7cdc00b
move removeFolder to utils
BrettCleary Mar 30, 2023
7bcfb2d
import removeFolder fxn
BrettCleary Mar 30, 2023
4e0ae86
Merge branch 'main' of github.com:Heroic-Games-Launcher/HeroicGamesLa…
flavioislima Apr 6, 2023
6704007
chore: make variables names more generic
flavioislima Apr 6, 2023
3c436eb
tests: updated tests
flavioislima Apr 6, 2023
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
Prev Previous commit
Next Next commit
fix merge errors
  • Loading branch information
BrettCleary committed Mar 28, 2023
commit 6e97bfc9ea93f5981f333c54f14bb3d073cd64b3
13 changes: 7 additions & 6 deletions src/backend/downloadmanager/downloadqueue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { libraryManagerMap } from 'backend/storeManagers'
import { gameManagerMap, libraryManagerMap } from 'backend/storeManagers'
import { TypeCheckedStoreBackend } from './../electron_store'
import { logError, logInfo, LogPrefix, logWarning } from '../logger/logger'
import { getFileSize } from '../utils'
Expand Down Expand Up @@ -185,8 +185,8 @@ function cancelCurrentDownload({ removeDownloaded = false }) {

if (removeDownloaded) {
const { appName, runner } = currentElement!.params
const { folder_name } = getGame(appName, runner).getGameInfo()
removeFolder(currentElement.params.path, folder_name)
const { folder_name } = gameManagerMap[runner].getGameInfo(appName)
if (folder_name) removeFolder(currentElement.params.path, folder_name)
}
currentElement = null
}
Expand All @@ -211,14 +211,15 @@ function resumeCurrentDownload() {
function stopCurrentDownload() {
const { appName, runner } = currentElement!.params
callAbortController(appName)
getGame(appName, runner).stop(false)
gameManagerMap[runner].stop(appName, false)
}

// notify the user based on the status of the element and the status of the queue
function processNotification(element: DMQueueElement, status: DMStatus) {
const action = element.type === 'install' ? 'Installation' : 'Update'
const game = getGame(element.params.appName, element.params.runner)
const { title } = game.getGameInfo()
const { title } = gameManagerMap[element.params.runner].getGameInfo(
element.params.appName
)

if (status === 'abort') {
if (isPaused()) {
Expand Down
18 changes: 8 additions & 10 deletions src/backend/downloadmanager/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { gameManagerMap } from 'backend/storeManagers'
import { logError, LogPrefix, logWarning } from '../logger/logger'
import { isEpicServiceOffline } from '../utils'
import { DMStatus, InstallParams, InstallPlatform } from 'common/types'
import { DMStatus, InstallParams } from 'common/types'
import i18next from 'i18next'
import { notify, showDialogBoxModalAuto } from '../dialog/dialog'
import { isOnline } from '../online_monitor'
Expand Down Expand Up @@ -65,15 +65,13 @@ async function installQueueElement(params: InstallParams): Promise<{
}

try {
const installPlatform = platformToInstall as InstallPlatform
const installInstance = async () =>
gameManagerMap[runner].install(appName, {
path: path.replaceAll("'", ''),
installDlcs,
sdlList,
platformToInstall: installPlatform,
installLanguage
})
const { status, error } = await gameManagerMap[runner].install(appName, {
path: path.replaceAll("'", ''),
installDlcs,
sdlList,
platformToInstall,
installLanguage
})

if (status === 'error') {
errorMessage(error ?? '')
Expand Down
10 changes: 8 additions & 2 deletions src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import {
killPattern,
spawnAsync,
moveOnUnix,
moveOnWindows
moveOnWindows,
shutdownWine
} from '../../utils'
import {
ExtraInfo,
Expand Down Expand Up @@ -834,9 +835,14 @@ export async function forceUninstall(appName: string): Promise<void> {

// Could be removed if gogdl handles SIGKILL and SIGTERM for us
// which is send via AbortController
export async function stop(appName: string): Promise<void> {
export async function stop(appName: string, stopWine = true): Promise<void> {
const pattern = isLinux ? appName : 'gogdl'
killPattern(pattern)

if (stopWine && !isNative(appName) && isLinux) {
const gameSettings = await getSettings(appName)
await shutdownWine(gameSettings)
}
}

export function isGameAvailable(appName: string) {
Expand Down
10 changes: 8 additions & 2 deletions src/backend/storeManagers/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
getLegendaryBin,
killPattern,
moveOnUnix,
moveOnWindows
moveOnWindows,
shutdownWine
} from '../../utils'
import {
isMac,
Expand Down Expand Up @@ -964,13 +965,18 @@ export async function forceUninstall(appName: string) {

// Could be removed if legendary handles SIGKILL and SIGTERM for us
// which is send via AbortController
export async function stop(appName: string) {
export async function stop(appName: string, stopWine = true) {
// until the legendary bug gets fixed, kill legendary on mac
// not a perfect solution but it's the only choice for now

// @adityaruplaha: this is kinda arbitary and I don't understand it.
const pattern = process.platform === 'linux' ? appName : 'legendary'
killPattern(pattern)

if (stopWine && isNative(appName)) {
const gameSettings = await getSettings(appName)
await shutdownWine(gameSettings)
}
}

export function isGameAvailable(appName: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/types/game_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export interface GameManager {
uninstall: (args: RemoveArgs) => Promise<ExecResult>
update: (appName: string) => Promise<InstallResult>
forceUninstall: (appName: string) => Promise<void>
stop: (appName: string) => Promise<void>
stop: (appName: string, stopWine?: boolean) => Promise<void>
isGameAvailable: (appName: string) => boolean
}

Expand Down
1 change: 0 additions & 1 deletion src/frontend/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ButtonOptions,
LibraryTopSectionOptions,
DMQueueElement,
SideloadGame,
DownloadManagerState
} from 'common/types'

Expand Down