Skip to content

Commit

Permalink
Add trap for no internet - re #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed Nov 28, 2022
1 parent 8641489 commit ce49eb9
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions modAssist_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1601,13 +1601,13 @@ function processModFolders_post(newFolder = false) {
maCache.set(thisModDetail.md5Sum, thisModDetail.storable)
}
} catch (e) {
log.log.danger(`Couldn't process ${thisFile.name}: ${e}`, 'folder-reader')
log.log.danger(`Couldn't process file: ${thisFile.name} :: ${e}`, 'folder-reader')
}

loadingWindow_current()
})
} catch (e) {
log.log.danger(`Couldn't process ${folder}: ${e}`, 'folder-reader')
log.log.danger(`Couldn't process folder: ${folder} :: ${e}`, 'folder-reader')
}
}
})
Expand Down Expand Up @@ -1706,33 +1706,35 @@ app.whenReady().then(() => {
tray.setToolTip('FSG Mod Assist')
tray.on('click', () => { windows.main.show() })

const request = net.request(hubURL)
if ( net.isOnline() ) {
const request = net.request(hubURL)

request.on('response', (response) => {
log.log.info(`Got modHubData.json: ${response.statusCode}`, 'local-cache')
let mhResp = ''
response.on('data', (chunk) => { mhResp = mhResp + chunk.toString() })
response.on('end', () => {
fs.writeFileSync(path.join(app.getPath('userData'), 'modHubData.json'), mhResp)
loadModHub()
request.on('response', (response) => {
log.log.info(`Got modHubData.json: ${response.statusCode}`, 'local-cache')
let mhResp = ''
response.on('data', (chunk) => { mhResp = mhResp + chunk.toString() })
response.on('end', () => {
fs.writeFileSync(path.join(app.getPath('userData'), 'modHubData.json'), mhResp)
loadModHub()
})
})
})
request.on('error', (error) => { log.log.info(`Network error : ${error}`, 'net-request') })
request.end()

const request2 = net.request(hubVerURL)

request2.on('response', (response) => {
log.log.info(`Got modHubVersion.json: ${response.statusCode}`, 'local-cache')
let mhResp = ''
response.on('data', (chunk) => { mhResp = mhResp + chunk.toString() })
response.on('end', () => {
fs.writeFileSync(path.join(app.getPath('userData'), 'modHubVersion.json'), mhResp)
loadModHubVer()
request.on('error', (error) => { log.log.info(`Network error : ${error}`, 'net-request') })
request.end()

const request2 = net.request(hubVerURL)

request2.on('response', (response) => {
log.log.info(`Got modHubVersion.json: ${response.statusCode}`, 'local-cache')
let mhResp = ''
response.on('data', (chunk) => { mhResp = mhResp + chunk.toString() })
response.on('end', () => {
fs.writeFileSync(path.join(app.getPath('userData'), 'modHubVersion.json'), mhResp)
loadModHubVer()
})
})
})
request2.on('error', (error) => { log.log.info(`Network error : ${error}`, 'net-request') })
request2.end()
request2.on('error', (error) => { log.log.info(`Network error : ${error}`, 'net-request') })
request2.end()
}

app.on('second-instance', () => {
// Someone tried to run a second instance, we should focus our window.
Expand Down

0 comments on commit ce49eb9

Please sign in to comment.