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

[Bugfix] Fixed epic service status check. #932

Merged
merged 5 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
4 changes: 2 additions & 2 deletions electron/dxvk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const DXVK = {
return exec(updatedVersionfile)
})
.catch((error) => {
logError(error, LogPrefix.DXVKInstaller)
logError(`${error}`, LogPrefix.DXVKInstaller)
logError(
'error when removing DXVK, please try again',
LogPrefix.DXVKInstaller
Expand All @@ -142,7 +142,7 @@ export const DXVK = {
return exec(updatedVersionfile)
})
.catch((error) => {
logError(error, LogPrefix.DXVKInstaller)
logError(`${error}`, LogPrefix.DXVKInstaller)
logError(
'error when installing DXVK, please try launching the game again',
LogPrefix.DXVKInstaller
Expand Down
12 changes: 6 additions & 6 deletions electron/legendary/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { LegendaryUser } from './user'
import {
errorHandler,
execAsync,
isEpicOffline,
isEpicServiceOffline,
isOnline,
removeSpecialcharacters
} from '../utils'
Expand Down Expand Up @@ -133,7 +133,7 @@ class LegendaryGame extends Game {
try {
productSlug = await this.getProductSlug(namespace)
} catch (error) {
logError(error, LogPrefix.Legendary)
logError(`${error}`, LogPrefix.Legendary)
productSlug = this.appName
}
epicUrl = `https://store-content.ak.epicgames.com/api/${lang}/content/products/${productSlug}`
Expand Down Expand Up @@ -222,7 +222,7 @@ class LegendaryGame extends Game {
)
logInfo(`Finished Moving ${title}`, LogPrefix.Legendary)
})
.catch((error) => logError(error, LogPrefix.Legendary))
.catch((error) => logError(`${error}`, LogPrefix.Legendary))
return newInstallPath
}

Expand Down Expand Up @@ -516,7 +516,7 @@ Categories=Game;
}

public async launch(launchArguments?: string) {
const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
const isOffline = !(await isOnline()) || epicOffline
let envVars = ''
let gameMode: string
Expand Down Expand Up @@ -704,7 +704,7 @@ Categories=Game;
return { stderr, command, gameSettings }
})
.catch((error) => {
logError(error, LogPrefix.Legendary)
logError(`${error}`, LogPrefix.Legendary)
const { stderr } = error
return { stderr, command, gameSettings }
})
Expand All @@ -730,7 +730,7 @@ Categories=Game;
logInfo(['creating new prefix', fixedWinePrefix], LogPrefix.Backend)
return execAsync(initPrefixCommand)
.then(() => logInfo('Prefix created succesfuly!', LogPrefix.Backend))
.catch((error) => logError(error, LogPrefix.Backend))
.catch((error) => logError(`${error}`, LogPrefix.Backend))
}
}

Expand Down
26 changes: 16 additions & 10 deletions electron/legendary/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../types'
import { LegendaryGame } from './games'
import { LegendaryUser } from './user'
import { execAsync, isEpicOffline, isOnline } from '../utils'
import { execAsync, isEpicServiceOffline, isOnline } from '../utils'
import {
installed,
legendaryBin,
Expand Down Expand Up @@ -84,9 +84,12 @@ class LegendaryLibrary {
public async refresh() {
logInfo('Refreshing Epic Games...', LogPrefix.Legendary)
const { showUnrealMarket } = await GlobalConfig.get().getSettings()
const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
if (epicOffline) {
logWarning('Epic is Offline right now, cannot update game list!')
logWarning(
'Epic is Offline right now, cannot update game list!',
LogPrefix.Backend
)
return
}

Expand Down Expand Up @@ -149,15 +152,15 @@ class LegendaryLibrary {
logInfo('Refreshing Epic Games...', LogPrefix.Legendary)
await this.refresh()
} catch (error) {
logError(error, LogPrefix.Legendary)
logError(`${error}`, LogPrefix.Legendary)
}
}

try {
this.refreshInstalled()
await this.loadAll()
} catch (error) {
logError(error, LogPrefix.Legendary)
logError(`${error}`, LogPrefix.Legendary)
}
const arr = Array.from(this.library.values()).sort(
(a: { title: string }, b: { title: string }) => {
Expand Down Expand Up @@ -207,7 +210,7 @@ class LegendaryLibrary {
*/
public async getInstallInfo(appName: string) {
const cache = installStore.get(appName) as InstallInfo
const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
logInfo(
'Getting More details with Legendary info command... ',
LogPrefix.Legendary
Expand All @@ -226,7 +229,7 @@ class LegendaryLibrary {
return info
} catch (error) {
logError('Error running the Legendary Info command', LogPrefix.Legendary)
logError(error, LogPrefix.Legendary)
logError(`${error}`, LogPrefix.Legendary)
}
}

Expand All @@ -242,9 +245,12 @@ class LegendaryLibrary {
if (!isLoggedIn || !online) {
return []
}
const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
if (epicOffline) {
logWarning('Epic servers are offline, cannot check for game updates')
logWarning(
'Epic servers are offline, cannot check for game updates',
LogPrefix.Backend
)
return []
}

Expand All @@ -260,7 +266,7 @@ class LegendaryLibrary {
logInfo(`Found ${updates.length} game(s) to update`, LogPrefix.Legendary)
return updates
} catch (error) {
logError(error, LogPrefix.Legendary)
logError(`${error}`, LogPrefix.Legendary)
}
}

Expand Down
2 changes: 1 addition & 1 deletion electron/legendary/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export class LegendaryUser {
try {
isLoggedIn = await LegendaryUser.isLoggedIn()
} catch (error) {
logError(error, LogPrefix.Backend)
logError(`${error}`, LogPrefix.Backend)
configStore.delete('userInfo')
}
if (isLoggedIn) {
Expand Down
22 changes: 11 additions & 11 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
clearCache,
errorHandler,
execAsync,
isEpicOffline,
isEpicServiceOffline,
getLegendaryVersion,
getSystemInfo,
handleExit,
Expand Down Expand Up @@ -528,7 +528,7 @@ ipcMain.handle('checkGameUpdates', () =>
LegendaryLibrary.get().listUpdateableGames()
)

ipcMain.handle('getEpicGamesStatus', () => isEpicOffline())
ipcMain.handle('getEpicGamesStatus', () => isEpicServiceOffline())

// Not ready to be used safely yet.
ipcMain.handle('updateAll', () => LegendaryLibrary.get().updateAllGames())
Expand Down Expand Up @@ -578,7 +578,7 @@ ipcMain.handle('getGameInfo', async (event, game) => {
info.extra = await Game.get(game).getExtraInfo(info.namespace)
return info
} catch (error) {
logError(error, LogPrefix.Backend)
logError(`${error}`, LogPrefix.Backend)
}
})

Expand All @@ -591,7 +591,7 @@ ipcMain.handle('getInstallInfo', async (event, game) => {
const info = await Game.get(game).getInstallInfo()
return info
} catch (error) {
logError(error, LogPrefix.Backend)
logError(`${error}`, LogPrefix.Backend)
return {}
}
})
Expand Down Expand Up @@ -857,7 +857,7 @@ ipcMain.handle('install', async (event, params) => {
return
}

const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
if (epicOffline) {
dialog.showErrorBox(
i18next.t('box.warning.title', 'Warning'),
Expand Down Expand Up @@ -915,7 +915,7 @@ ipcMain.handle('uninstall', async (event, game) => {
notify({ title, body: i18next.t('notify.uninstalled') })
logInfo('finished uninstalling', LogPrefix.Backend)
})
.catch((error) => logError(error, LogPrefix.Backend))
.catch((error) => logError(`${error}`, LogPrefix.Backend))
})

ipcMain.handle('repair', async (event, game) => {
Expand All @@ -939,7 +939,7 @@ ipcMain.handle('repair', async (event, game) => {
title,
body: i18next.t('notify.error.reparing', 'Error Repairing')
})
logError(error, LogPrefix.Backend)
logError(`${error}`, LogPrefix.Backend)
})
})

Expand All @@ -954,12 +954,12 @@ ipcMain.handle('moveInstall', async (event, [appName, path]: string[]) => {
title,
body: i18next.t('notify.error.move', 'Error Moving the Game')
})
logError(error, LogPrefix.Backend)
logError(`${error}`, LogPrefix.Backend)
}
})

ipcMain.handle('importGame', async (event, args) => {
const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
if (epicOffline) {
dialog.showErrorBox(
i18next.t('box.warning.title', 'Warning'),
Expand Down Expand Up @@ -1008,7 +1008,7 @@ ipcMain.handle('updateGame', async (e, game) => {
return
}

const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
if (epicOffline) {
dialog.showErrorBox(
i18next.t('box.warning.title', 'Warning'),
Expand Down Expand Up @@ -1153,7 +1153,7 @@ ipcMain.on('removeShortcut', async (event, appName: string) => {

ipcMain.handle('syncSaves', async (event, args) => {
const [arg = '', path, appName] = args
const epicOffline = await isEpicOffline()
const epicOffline = await isEpicServiceOffline()
if (epicOffline) {
logWarning('Epic is Offline right now, cannot sync saves!')
return 'Epic is Offline right now, cannot sync saves!'
Expand Down
48 changes: 38 additions & 10 deletions electron/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as axios from 'axios'
import { app, dialog, net, shell } from 'electron'
import { app, dialog, net, shell, Notification } from 'electron'
import { exec } from 'child_process'
import { existsSync, rm, stat } from 'graceful-fs'
import { promisify } from 'util'
import i18next from 'i18next'
import i18next, { t } from 'i18next'
import prettyBytes from 'pretty-bytes'
import si from 'systeminformation'
import Store from 'electron-store'
Expand Down Expand Up @@ -37,13 +37,41 @@ async function isOnline() {
return net.isOnline()
}

async function isEpicOffline() {
const epicStatusApi = 'https://status.epicgames.com/api/v2/status.json'
const { data } = await axios.default.get(epicStatusApi)
const {
status: { indicator }
} = data
return indicator === 'major'
async function isEpicServiceOffline(
type: 'Epic Games Store' | 'Fortnite' | 'Rocket League' = 'Epic Games Store'
) {
const epicStatusApi = 'https://status.epicgames.com/api/v2/components.json'
const notification = new Notification({
Nocccer marked this conversation as resolved.
Show resolved Hide resolved
title: `${type} ${t('epic.offline-notification-title', 'offline')}`,
body: t('offline-notification-body', 'Heroic will not work probably!'),
urgency: 'critical'
})

try {
const { data } = await axios.default.get(epicStatusApi)

for (const component of data.components) {
const { name: name, status: indicator } = component

// found component and checking status
if (name === type) {
const isOffline = indicator === 'major'
if (isOffline) {
notification.show()
}
return isOffline
}
}

notification.show()
return false
} catch (error) {
logError(
`Failed to get epic service status with ${error}`,
LogPrefix.Backend
)
return false
}
}

export const getLegendaryVersion = async () => {
Expand Down Expand Up @@ -286,7 +314,7 @@ export {
genericErrorMessage,
handleExit,
isOnline,
isEpicOffline,
isEpicServiceOffline,
openUrlOrFile,
semverGt,
showAboutWindow,
Expand Down
4 changes: 2 additions & 2 deletions electron/wine-downloader/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function installWineVersion(
}
})
.catch((error: Error) => {
logError(error.message, LogPrefix.WineDownloader)
logError(`${error.message}`, LogPrefix.WineDownloader)
return false
})

Expand Down Expand Up @@ -160,7 +160,7 @@ async function removeWineVersion(release: WineVersionInfo): Promise<boolean> {
try {
rmSync(release.installDir, { recursive: true })
} catch (error) {
logError(error, LogPrefix.WineDownloader)
logError(`${error}`, LogPrefix.WineDownloader)
logWarning(
`Couldn't remove folder ${release.installDir}! Still mark wine version ${release.version} as not installed!`,
LogPrefix.WineDownloader
Expand Down