Allow https to follow redirections when requesting latest release data from github.
This commit is contained in:
parent
3ecf05e6ab
commit
8ca6e21969
1 changed files with 22 additions and 9 deletions
|
@ -176,11 +176,11 @@ ipcMain.on('version-info-requested', () => {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let result = '';
|
let result = '';
|
||||||
|
const onSuccess = res => {
|
||||||
const req = https.get(Object.assign(opts, url.parse(latestReleaseAPIURL)), res => {
|
|
||||||
res.on('data', data => {
|
res.on('data', data => {
|
||||||
result += data;
|
result += data;
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
const tagName = JSON.parse(result).tag_name;
|
const tagName = JSON.parse(result).tag_name;
|
||||||
const [, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
|
const [, remoteVersion] = tagName.match(/^v([\d.]+(?:-?rc\d+)?)$/);
|
||||||
|
@ -199,14 +199,27 @@ ipcMain.on('version-info-requested', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
req.on('error', err => {
|
const requestLatestRelease = (apiUrl, alreadyRedirected = false) => {
|
||||||
console.log('Failed to get current version from GitHub. Error:', err);
|
const req = https.get(Object.assign(opts, url.parse(apiUrl)), res => {
|
||||||
if (rendererWindow) {
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
||||||
rendererWindow.webContents.send('version-info-received', null);
|
requestLatestRelease(res.headers.location, true);
|
||||||
}
|
} else {
|
||||||
});
|
onSuccess(res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (alreadyRedirected) return;
|
||||||
|
req.on('error', err => {
|
||||||
|
console.log('Failed to get current version from GitHub. Error:', err);
|
||||||
|
if (rendererWindow) {
|
||||||
|
rendererWindow.webContents.send('version-info-received', null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
requestLatestRelease(latestReleaseAPIURL);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('get-auth-token', event => {
|
ipcMain.on('get-auth-token', event => {
|
||||||
|
|
Loading…
Reference in a new issue