From f7c3a44056229a4206d814de72befab4b5ca07c7 Mon Sep 17 00:00:00 2001 From: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com> Date: Tue, 29 Mar 2022 10:06:42 -0700 Subject: [PATCH] Update electron to 17.3.0 --- package.json | 4 +--- scripts/esbuild.js | 40 --------------------------------- ts/sql/main.ts | 16 +++---------- ts/sql/mainWorkerBindings.ts | 13 ----------- ts/workers/heicConverterMain.ts | 21 ++++++----------- yarn.lock | 8 +++---- 6 files changed, 15 insertions(+), 87 deletions(-) delete mode 100644 ts/sql/mainWorkerBindings.ts diff --git a/package.json b/package.json index ebcfd8e3f..3eb2ad2b8 100644 --- a/package.json +++ b/package.json @@ -264,7 +264,7 @@ "cross-env": "5.2.0", "css-loader": "3.2.0", "debug": "4.3.3", - "electron": "17.2.0", + "electron": "17.3.0", "electron-builder": "23.0.1", "electron-mocha": "11.0.2", "electron-notarize": "0.1.1", @@ -412,8 +412,6 @@ "afterPack": "ts/scripts/after-pack.js", "afterSign": "ts/scripts/after-sign.js", "asarUnpack": [ - "ts/workers/heicConverter.bundle.js", - "ts/sql/mainWorker.bundle.js", "node_modules/better-sqlite3/build/Release/better_sqlite3.node" ], "files": [ diff --git a/scripts/esbuild.js b/scripts/esbuild.js index 8a4070380..1734a2801 100644 --- a/scripts/esbuild.js +++ b/scripts/esbuild.js @@ -83,43 +83,3 @@ esbuild.build({ entryPoints: [path.join(ROOT_DIR, 'preload.js')], outfile: path.join(ROOT_DIR, 'preload.bundle.js'), }); - -// HEIC worker -esbuild.build({ - ...bundleDefaults, - entryPoints: [path.join(ROOT_DIR, 'ts', 'workers', 'heicConverterWorker.ts')], - outfile: path.join(ROOT_DIR, 'ts', 'workers', 'heicConverter.bundle.js'), -}); - -// SQL worker -const libDir = path.join('..', '..', 'node_modules', 'better-sqlite3'); -const bindingFile = path.join( - libDir, - 'build', - 'Release', - 'better_sqlite3.node' -); - -esbuild.build({ - ...nodeDefaults, - bundle: true, - - plugins: [ - { - name: 'bindings', - setup(build) { - build.onResolve({ filter: /^bindings$/ }, () => ({ - path: path.join(ROOT_DIR, 'ts', 'sql', 'mainWorkerBindings.ts'), - })); - - build.onResolve({ filter: /^better_sqlite3\.node$/ }, () => ({ - path: bindingFile, - external: true, - })); - }, - }, - ], - - entryPoints: [path.join(ROOT_DIR, 'ts', 'sql', 'mainWorker.ts')], - outfile: path.join(ROOT_DIR, 'ts', 'sql', 'mainWorker.bundle.js'), -}); diff --git a/ts/sql/main.ts b/ts/sql/main.ts index a502970e3..f0968f257 100644 --- a/ts/sql/main.ts +++ b/ts/sql/main.ts @@ -4,13 +4,13 @@ import { join } from 'path'; import { Worker } from 'worker_threads'; import { format } from 'util'; +import { app } from 'electron'; import { strictAssert } from '../util/assert'; import { explodePromise } from '../util/explodePromise'; import type { LoggerType } from '../types/Logging'; import { isCorruptionError } from './errors'; -const ASAR_PATTERN = /app\.asar$/; const MIN_TRACE_DURATION = 40; export type InitializeOptions = Readonly<{ @@ -85,18 +85,8 @@ export class MainSQL { private onResponse = new Map>(); constructor() { - let appDir = join(__dirname, '..', '..'); - let isBundled = false; - - if (ASAR_PATTERN.test(appDir)) { - appDir = appDir.replace(ASAR_PATTERN, 'app.asar.unpacked'); - isBundled = true; - } - - const scriptDir = join(appDir, 'ts', 'sql'); - this.worker = new Worker( - join(scriptDir, isBundled ? 'mainWorker.bundle.js' : 'mainWorker.js') - ); + const scriptDir = join(app.getAppPath(), 'ts', 'sql', 'mainWorker.js'); + this.worker = new Worker(scriptDir); const { promise: onCorruption, resolve: resolveCorruption } = explodePromise(); diff --git a/ts/sql/mainWorkerBindings.ts b/ts/sql/mainWorkerBindings.ts deleted file mode 100644 index 34eae4b8d..000000000 --- a/ts/sql/mainWorkerBindings.ts +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2021 Signal Messenger, LLC -// SPDX-License-Identifier: AGPL-3.0-only - -// This is a shim that gets inserted in place of `bindings` npm module when -// building sql worker bundle. -module.exports = (binding: string) => { - if (binding === 'better_sqlite3.node') { - // eslint-disable-next-line global-require, import/no-unresolved - return require('better_sqlite3.node'); - } - - throw new Error(`Unknown binding ${binding}`); -}; diff --git a/ts/workers/heicConverterMain.ts b/ts/workers/heicConverterMain.ts index d900e681b..dd7824ed2 100644 --- a/ts/workers/heicConverterMain.ts +++ b/ts/workers/heicConverterMain.ts @@ -3,6 +3,7 @@ import { join } from 'path'; import { Worker } from 'worker_threads'; +import { app } from 'electron'; export type WrappedWorkerRequest = { readonly uuid: string; @@ -15,25 +16,17 @@ export type WrappedWorkerResponse = { readonly response?: File; }; -const ASAR_PATTERN = /app\.asar$/; - export function getHeicConverter(): ( uuid: string, data: Uint8Array ) => Promise { - let appDir = join(__dirname, '..', '..'); - let isBundled = false; - if (ASAR_PATTERN.test(appDir)) { - appDir = appDir.replace(ASAR_PATTERN, 'app.asar.unpacked'); - isBundled = true; - } - const scriptDir = join(appDir, 'ts', 'workers'); - const worker = new Worker( - join( - scriptDir, - isBundled ? 'heicConverter.bundle.js' : 'heicConverterWorker.js' - ) + const scriptDir = join( + app.getAppPath(), + 'ts', + 'workers', + 'heicConverterWorker.js' ); + const worker = new Worker(scriptDir); const ResponseMap = new Map< string, diff --git a/yarn.lock b/yarn.lock index a94d02fa2..6331aae26 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6172,10 +6172,10 @@ electron-window@^0.8.0: dependencies: is-electron-renderer "^2.0.0" -electron@17.2.0: - version "17.2.0" - resolved "https://registry.yarnpkg.com/electron/-/electron-17.2.0.tgz#a5c42c16352ea968fcb5d1ce256bec51e7d140fe" - integrity sha512-eNXhPVEUofkgAeqRFvTizzYecoCMyS0Rar08WZHSAw9wjfZXawYMvTpjjjk9GiX9W/+Cjxua4YtGn5bOTabc0A== +electron@17.3.0: + version "17.3.0" + resolved "https://registry.yarnpkg.com/electron/-/electron-17.3.0.tgz#cdcc46a7a3cd0b6f2a1757fbeb807f6b2fce847e" + integrity sha512-KuYHCOw1a+CE9thZlWRqTScf6M81KLd6n5qpdBGb0rl62+50RUuau9CnYpBb3EJxrjsXLaiQCBBSdPsozf/XUg== dependencies: "@electron/get" "^1.13.0" "@types/node" "^14.6.2"