updater: add NMv2 support

sigh
pull/160/head
CanadaHonk 5 months ago
parent 403878f068
commit 175388f956

@ -15,5 +15,7 @@ module.exports = {
APP_PROTOCOL: p,
API_ENDPOINT: settings.get('API_ENDPOINT') || (d + '/api'),
NEW_UPDATE_ENDPOINT: settings.get('NEW_UPDATE_ENDPOINT') || 'https://updates.discord.com/',
UPDATE_ENDPOINT: settings.get('UPDATE_ENDPOINT') || (d + '/api')
UPDATE_ENDPOINT: settings.get('UPDATE_ENDPOINT') || (d + '/api'),
DISABLE_WINDOWS_64BIT_TRANSITION: false,
OPTIN_WINDOWS_64BIT_TRANSITION_PROGRESSION: false
};

@ -23,7 +23,7 @@ const M = require('module'); // Module
const b = join(paths.getExeDir(), 'modules'); // Base dir
if (process.platform === 'win32') try {
for (const m of require('fs').readdirSync(b)) M.globalPaths.push(join(b, m)); // For each module dir, add to globalPaths
for (const m of require('fs').readdirSync(b)) M.globalPaths.unshift(join(b, m)); // For each module dir, add to globalPaths
} catch { log('Init', 'Failed to QS globalPaths') }
// inject Module.globalPaths into resolve lookups as it was removed in Electron >=17 and Discord depend on this workaround

@ -119,8 +119,11 @@ const initNew = async (inst) => {
toSend = -1;
const retryOptions = {
skip_host_delta: true,
skip_module_delta: {}
skip_host_delta: false,
skip_module_delta: {},
skip_all_module_delta: false,
skip_windows_arch_update: false,
optin_windows_transition_progression: false
};
while (true) {
@ -154,7 +157,10 @@ const initNew = async (inst) => {
});
if (!installedAnything) {
await inst.startCurrentVersion();
await inst.startCurrentVersion({
skip_windows_arch_update: false,
optin_windows_transition_progression: false
});
inst.collectGarbage();
return launchMain();

@ -12,6 +12,14 @@ const TASK_STATE_FAILED = 'Failed';
const TASK_STATE_WAITING = 'Waiting';
const TASK_STATE_WORKING = 'Working';
// discord made breaking changes without any api versioning wow!!
// so we have to read the node module to determine the version
let updaterVersion = 1;
const updaterPath = paths.getExeDir() + '/updater.node';
const updaterContents = require('fs').readFileSync(updaterPath, 'utf8');
if (updaterContents.includes('Determined this is an architecture transition')) updaterVersion = 2;
log('Updater', 'Determined native module version', updaterVersion);
class Updater extends require('events').EventEmitter {
constructor(options) {
@ -19,7 +27,7 @@ class Updater extends require('events').EventEmitter {
let Native;
try {
Native = options.nativeUpdaterModule ?? require(paths.getExeDir() + '/updater');
Native = options.nativeUpdaterModule ?? require(updaterPath);
} catch (e) {
log('Updater', e); // Error when requiring
@ -172,7 +180,7 @@ class Updater extends require('events').EventEmitter {
_commitModulesInner(versions) {
const base = join(this._getHostPath(), 'modules');
for (const m in versions.current_modules) Module.globalPaths.push(join(base, `${m}-${versions.current_modules[m]}`));
for (const m in versions.current_modules) Module.globalPaths.unshift(join(base, `${m}-${versions.current_modules[m]}`));
}
_recordDownloadProgress(name, progress) {
@ -228,12 +236,28 @@ class Updater extends require('events').EventEmitter {
else if (progress.task.ModuleInstall != null) this._recordInstallProgress(progress.task.ModuleInstall.version.module.name, progress, progress.task.ModuleInstall.version.version, progress.task.ModuleInstall.from_version != null);
}
constructQueryCurrentVersionsRequest(options) {
if (updaterVersion === 1) return 'QueryCurrentVersions';
return {
QueryCurrentVersions: {
options
}
};
}
queryCurrentVersionsWithOptions(options) {
return this._sendRequest(this.constructQueryCurrentVersionsRequest(options));
}
queryCurrentVersions() {
return this._sendRequest('QueryCurrentVersions');
return this.queryCurrentVersionsWithOptions(null);
}
queryCurrentVersionsWithOptionsSync(options) {
return this._handleSyncResponse(this._sendRequestSync(this.constructQueryCurrentVersionsRequest(options)));
}
queryCurrentVersionsSync() {
return this._handleSyncResponse(this._sendRequestSync('QueryCurrentVersions'));
return this.queryCurrentVersionsWithOptionsSync(null);
}
repair(progressCallback) {
@ -290,8 +314,8 @@ class Updater extends require('events').EventEmitter {
}
async startCurrentVersion(options) {
const versions = await this.queryCurrentVersions();
async startCurrentVersion(queryOptions, options) {
const versions = await this.queryCurrentVersionsWithOptions(queryOptions);
await this.setRunningManifest(versions.last_successful_update);
this._startCurrentVersionInner(options, versions);
@ -301,10 +325,10 @@ class Updater extends require('events').EventEmitter {
this._startCurrentVersionInner(options, this.queryCurrentVersionsSync());
}
async commitModules(versions) {
async commitModules(queryOptions, versions) {
if (this.committedHostVersion == null) throw 'No host';
this._commitModulesInner(versions ?? await this.queryCurrentVersions());
this._commitModulesInner(versions ?? await this.queryCurrentVersionsWithOptions(queryOptions));
}
queryAndTruncateHistory() {
@ -324,7 +348,6 @@ class Updater extends require('events').EventEmitter {
return this.nativeUpdater.create_shortcut(options);
}
}
@ -345,7 +368,9 @@ module.exports = {
release_channel: buildInfo.releaseChannel,
platform: process.platform === 'win32' ? 'win' : 'osx',
repository_url,
root_path
root_path,
user_data_path: paths.getUserData(),
current_os_arch: process.platform === 'win32' ? (['AMD64', 'IA64'].includes(process.env.PROCESSOR_ARCHITEW6432 ?? process.env.PROCESSOR_ARCHITECTURE) ? 'x64' : 'x86') : null
});
return instance.valid;

Loading…
Cancel
Save