From 175388f95630ecd8fa289e2caf626cc73f1ad46e Mon Sep 17 00:00:00 2001 From: CanadaHonk Date: Wed, 22 Nov 2023 21:36:43 +0000 Subject: [PATCH] updater: add NMv2 support sigh --- src/Constants.js | 4 +++- src/index.js | 2 +- src/splash/index.js | 12 ++++++++--- src/updater/updater.js | 45 ++++++++++++++++++++++++++++++++---------- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/Constants.js b/src/Constants.js index 8249fc3..ce18933 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -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 }; \ No newline at end of file diff --git a/src/index.js b/src/index.js index 42b5875..41fe9bd 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/src/splash/index.js b/src/splash/index.js index 3121fe3..298d00a 100644 --- a/src/splash/index.js +++ b/src/splash/index.js @@ -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(); diff --git a/src/updater/updater.js b/src/updater/updater.js index 0b005b7..4b851a8 100644 --- a/src/updater/updater.js +++ b/src/updater/updater.js @@ -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;