Fix patching Win32 updater with OpenAsar (#1667)

This is more generic rewrite allowing for more paths to be added in the future for whatever reason (like a rename in future Discord versions).

(The "OpenAsar" code previously was completely wrong)
This commit is contained in:
CanadaHonk 2023-08-18 23:54:35 +01:00 committed by GitHub
parent ccd2ce8baf
commit d582e61ec3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { app, autoUpdater } from "electron"; import { app } from "electron";
import { existsSync, mkdirSync, readdirSync, renameSync, statSync, writeFileSync } from "fs"; import { existsSync, mkdirSync, readdirSync, renameSync, statSync, writeFileSync } from "fs";
import { basename, dirname, join } from "path"; import { basename, dirname, join } from "path";
@ -80,20 +80,22 @@ function patchLatest() {
// Windows Host Updates install to a new folder app-{HOST_VERSION}, so we // Windows Host Updates install to a new folder app-{HOST_VERSION}, so we
// need to reinject // need to reinject
function patchUpdater() { function patchUpdater() {
try { // Array of autoStart paths to try
const autoStartScript = join(require.main!.filename, "..", "autoStart", "win32.js"); const autoStartPaths = [
const { update } = require(autoStartScript); join(require.main!.filename, "..", "autoStart", "win32.js"), // Vanilla
join(require.main!.filename, "..", "autoStart.js") // OpenAsar
];
require.cache[autoStartScript]!.exports.update = function () { for (const path of autoStartPaths) {
try {
const { update } = require(path);
require.cache[path]!.exports.update = function () {
update.apply(this, arguments); update.apply(this, arguments);
patchLatest(); patchLatest();
}; };
} catch { } catch {
// OpenAsar uses electrons autoUpdater on Windows // Ignore as non-critical
const { quitAndInstall } = autoUpdater; }
autoUpdater.quitAndInstall = function () {
patchLatest();
quitAndInstall.call(this);
};
} }
} }