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

autoupdate tidying and cert patch #14942

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 44 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@
},
"stopAll": true
},
{
"name": "Debug Electron (Next)",
"configurations": [
"Debug Main Process (Next)",
"Debug Renderer Process"
],
"presentation": {
"hidden": false,
"group": "",
"order": 1
},
"stopAll": true
},
{
"name": "Debug Electron (Staging)",
"configurations": [
Expand Down Expand Up @@ -131,6 +144,37 @@
"sourceMaps": true,
"outFiles": []
},
{
"name": "Debug Main Process (Next)",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/out/main.js",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"runtimeArgs": [
"--no-sandbox",
"--remote-debugging-port=9230",
"--enable-logging",
"."
],
"env": {
"NODE_ENV": "development",
"SIMULATE_FS_ERRORS": "false",
"HIGHLIGHT_I18N": "false",
"BLUEBIRD_DEBUG": "0",
"FORCE_ALLOW_ELEVATED_SYMLINKING": "true",
"DEBUG_REACT_RENDERS": "false",
"START_DEVTOOLS": "true",
"IS_PREVIEW_BUILD": "true"
},
"envFile": "${workspaceFolder}/.env",
"console": "integratedTerminal",
"sourceMaps": true,
"outFiles": []
},
{
"name": "Debug Main Process (Staging)",
"type": "node",
Expand Down
66 changes: 55 additions & 11 deletions src/extensions/updater/SettingsUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,64 @@ class SettingsUpdate extends ComponentEx<IProps, {}> {
public render(): JSX.Element {
const { t, installType, updateChannel } = this.props;

const renderDevelopmentAlert = () => {
if(process.env.NODE_ENV === 'development')
return (
<div>
<ControlLabel>
<Alert>
{t('Vortex is running in development mode and version will always remain at 0.0.1. Updates will be checked but they won\'t be downloaded or installed.')}
</Alert>
</ControlLabel>
</div>
);
return null;
}

const renderPreviewAlert = () => {
if(updateChannel === 'next')
return (
<div>
<ControlLabel>
<Alert>
{t('Vortex is running in preview mode and using the hidden \'next\' update channel.')}
</Alert>
</ControlLabel>
</div>
);
return null;
}

// managed or development
if (installType === 'managed') {
return (
<ControlLabel>
{t('Update')}
<Alert>
{t('Vortex was installed through a third-party service which will take care of updating it.')}
</Alert>
</ControlLabel>
);

// managed and not development
if(process.env.NODE_ENV !== 'development') {
return (
<ControlLabel>
<Alert>
{t('Vortex was installed through a third-party service which will take care of updating it.')}
</Alert>
</ControlLabel>
);
}

// managed and development

}

// regular
return (
<form>
<form>
<FormGroup controlId='updateChannel'>

<ControlLabel>
{t('Update')}
<More id='more-update-channel' name={t('Update Channel')}>
{getText('update-channel', t)}
</More>
</ControlLabel>
</ControlLabel>

<FormControl
componentClass='select'
onChange={this.selectChannel}
Expand All @@ -56,6 +94,11 @@ class SettingsUpdate extends ComponentEx<IProps, {}> {
<option value='beta'>{t('Beta')}</option>
<option value='none'>{t('No automatic updates')}</option>
</FormControl>

{ renderPreviewAlert() }

{ renderDevelopmentAlert() }

<ControlLabel>
{updateChannel === 'none' ? [(
<Alert key='manual-update-warning' bsStyle='warning'>
Expand All @@ -72,7 +115,8 @@ class SettingsUpdate extends ComponentEx<IProps, {}> {
}

private checkNow = () => {
ipcRenderer.send('check-for-updates', 'stable');
// send what updateChannel you are on, unless it's none, then send stable
ipcRenderer.send('check-for-updates', this.props.updateChannel === 'none' ? 'stable' : this.props.updateChannel);
}

private selectChannel = (evt) => {
Expand Down
62 changes: 42 additions & 20 deletions src/extensions/updater/autoupdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,19 @@ function setupAutoUpdate(api: IExtensionApi) {
const state: () => IState = () => api.store.getState();
let notified: boolean = false;
let channelOverride: UpdateChannel;
if (process.env['IS_PREVIEW_BUILD'] === 'yes') {
log('info', 'forcing update channel for preview builds so that we don\'t automatically '
+ 'downgrade');

if (process.env.IS_PREVIEW_BUILD === 'true') {
log('info', 'forcing update channel for preview builds so that we don\'t automatically downgrade');
api.store.dispatch(setUpdateChannel('next'));
} else if (state().settings.update.channel === 'next') {
api.store.dispatch(setUpdateChannel('beta'));
}

log('info', 'setupAutoUpdate complete');

const queryUpdate = (version: string): Promise<void> => {
return new Promise<void>((resolve, reject) => {

if (semver.satisfies(version, '^' + autoUpdater.currentVersion.version)) {
// don't warn on a "compatible" update
return resolve();
Expand All @@ -91,7 +94,7 @@ function setupAutoUpdate(api: IExtensionApi) {
id: 'vortex-update-notification',
type: 'info',
title: 'Major update available',
message: 'After installing this update you shouldn\'t go back to an older version.',
message: `(${version}) After installing this update you shouldn't go back to an older version.`,
noDismiss: true,
actions: [
{
Expand Down Expand Up @@ -153,7 +156,7 @@ function setupAutoUpdate(api: IExtensionApi) {
});

autoUpdater.on('update-available', (info: UpdateInfo) => {
log('info', 'found update available', info.version);
log('info', 'found update available', info);
const installedVersion = semver.parse(getApplication().version);
const version = semver.parse(info.version);

Expand Down Expand Up @@ -240,7 +243,7 @@ function setupAutoUpdate(api: IExtensionApi) {
type: 'success',
message: 'Update available',
actions: [
{
/*{
title: 'Changelog',
action: () => {
api.store.dispatch(showDialog('info', `Changelog ${info.version}`, {
Expand All @@ -249,7 +252,7 @@ function setupAutoUpdate(api: IExtensionApi) {
{ label: 'Close' },
]));
},
},
},*/
{
title: 'Restart & Install',
action: () => {
Expand All @@ -265,28 +268,44 @@ function setupAutoUpdate(api: IExtensionApi) {
if (!state().session.base.networkConnected) {
log('info', 'Not checking for updates because network is offline');
}
log('info', 'checking for vortex update');

log('info', 'checking for vortex update:', channel);
const didOverride = channelOverride !== undefined;
autoUpdater.allowPrerelease = channel !== 'stable';
autoUpdater.allowPrerelease = channel !== 'stable';

autoUpdater.setFeedURL({
provider: 'github',
owner: 'Nexus-Mods',
repo: channel === 'next' ? 'Vortex-Next' : 'Vortex',
private: false,
publisherName: [
'Black Tree Gaming Limited',
'Black Tree Gaming Ltd'],
'Black Tree Gaming Ltd'
],
});
autoUpdater.allowDowngrade = true;
autoUpdater.autoDownload = false;

log('info', 'update config is ', {
provider: 'github',
owner: 'Nexus-Mods',
repo: channel === 'next' ? 'Vortex-Next' : 'Vortex',
allowPrerelease: channel !== 'stable'
});

autoUpdater.checkForUpdates()
.then(check => {
log('info', 'completed update check');
if (truthy(check.downloadPromise)) {
check.downloadPromise.catch(err => {
log('warn', 'Checking for update failed', err);
});
}

// do a check here for if a regular type (properly installed, not dev or epic or whatever)
// then that's the only time that we want to do the auto download
if (api.getState().app.installType === 'regular') {
if (truthy(check.downloadPromise)) {
check.downloadPromise.catch(err => {
log('warn', 'Checking for update failed', err);
});
}
}

if (!didOverride && (channelOverride !== undefined)) {
return checkNow(channelOverride);
Expand All @@ -303,14 +322,17 @@ function setupAutoUpdate(api: IExtensionApi) {

ipcMain.on('set-update-channel', (event, channel: any, manual: boolean) => {
try {
log('info', 'set channel', { channel, manual });
if ((channel !== 'none')
&& ((channelOverride === undefined) || manual)
&& (process.env.NODE_ENV !== 'development')
&& (process.env.IGNORE_UPDATES !== 'yes')) {
log('info', 'set channel', { channel, manual, channelOverride });

if ((channel !== 'none')
&& ((channelOverride === undefined) || manual)
//&& (process.env.NODE_ENV !== 'development')
&& (process.env.IGNORE_UPDATES !== 'yes')) {

if (manual) {
channelOverride = channel;
}

checkNow(channel);
}
} catch (err) {
Expand Down
16 changes: 14 additions & 2 deletions src/extensions/updater/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,29 @@ function init(context: IExtensionContext): boolean {
context.registerSettings('Vortex', SettingsUpdate);

context.onceMain(() => {

try {
if (context.api.getState().app.installType === 'regular') {
if (context.api.getState().app.installType === 'regular' ||
process.env.NODE_ENV === 'development'
) {
setupAutoUpdater(context.api);
}
} catch (err) {
log('error', 'failed to check for update', err.message);
}

log('info', 'updater config', {
isPreviewBuild: process.env.IS_PREVIEW_BUILD,
installType: context.api.getState().app.installType,
updateChannel: context.api.getState().settings.update.channel
});
});

context.once(() => {
if (context.api.getState().app.installType !== 'regular') {


if (context.api.getState().app.installType !== 'regular' &&
process.env.NODE_ENV !== 'development') {
return;
}

Expand Down
Loading