Skip to content

Commit

Permalink
[Feat] Proper check if heroic can communicate with internet (#1677)
Browse files Browse the repository at this point in the history
* Added ping to check internet connection

* removed console.log

* Make log of error more clear

* Remove ping package and just use ping cli command

* Return if one ping succeed
  • Loading branch information
Nocccer committed Aug 17, 2022
1 parent 3389286 commit 43b7c97
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions electron/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ export const Winetricks = {
return execAsync(downloadCommand)
.then(() => {
exec(`chmod +x ${path}`)
logInfo('Downloaded Winetricks', LogPrefix.Backend)
logInfo('Downloaded Winetricks', LogPrefix.WineTricks)
})
.catch(() => {
logWarning('Error Downloading Winetricks', LogPrefix.Backend)
logWarning('Error Downloading Winetricks', LogPrefix.WineTricks)
})
},
run: async (wineVersion: WineInstallation, baseWinePrefix: string) => {
Expand Down
29 changes: 28 additions & 1 deletion electron/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,34 @@ function semverGt(target: string, base: string) {
}

function isOnline() {
return net.isOnline()
let online = net.isOnline()
if (online) {
const hosts = ['google.com', 'store.epicgames.com', 'gog.com']
const errors = [] as string[]
online = hosts.some((host) => {
const args = [host] as string[]

if (isWindows) {
args.push('-n', '1')
} else {
args.push('-c', '1')
}

const { status, stderr } = spawnSync('ping', args)
if (stderr.length) {
errors.push(
[`Ping of ${host} failed with:`, stderr.toString()].join('\n')
)
}
return status === 0
})

if (!online && errors.length) {
logError(errors.join('\n'), LogPrefix.Backend)
}
}

return online
}

export const getFileSize = fileSize.partial({ base: 2 })
Expand Down

0 comments on commit 43b7c97

Please sign in to comment.