Skip to content

TagSpaces is an offline, open source, document manager with tagging support

chore: adding electron fuses and removing the use of @elife/pm2 lib

Ilian Sapundshievc28e63bee5e8
diff --git a/.erb/scripts/apply-fuses.js b/.erb/scripts/apply-fuses.js
new file mode 100644
index 000000000..63b7a4e33
--- /dev/null
+++ b/.erb/scripts/apply-fuses.js
@@ -0,0 +1,18 @@
+const { flipFuses, FuseVersion, FuseV1Options } = require('@electron/fuses');
+const path = require('path');
+
+exports.default = async function (context) {
+ const { electronPlatformName, appOutDir, packager } = context;
+ const ext = { darwin: '.app', win32: '.exe', linux: '' }[
+ electronPlatformName
+ ];
+ const electronBinary = path.join(
+ appOutDir,
+ `${packager.appInfo.productFilename}${ext}`,
+ );
+ await flipFuses(electronBinary, {
+ version: FuseVersion.V1,
+ resetAdHocDarwinSignature: electronPlatformName === 'darwin',
+ [FuseV1Options.RunAsNode]: false,
+ });
+};
diff --git a/release/app/package-lock.json b/release/app/package-lock.json
index a0332f312..bf1b508b1 100644
--- a/release/app/package-lock.json
+++ b/release/app/package-lock.json
@@ -10,7 +10,6 @@
"hasInstallScript": true,
"license": "AGPL-3.0",
"dependencies": {
- "@elife/pm2": "3.6.1",
"@tagspaces/extensions": "1.0.243",
"@tagspaces/tagspaces-common-node": "4.7.2",
"@tagspaces/tagspaces-ws": "4.8.0",
@@ -21,14 +20,6 @@
"@tagspacespro/extensions": "2.0.20"
}
},
- "node_modules/@elife/pm2": {
- "version": "3.6.1",
- "resolved": "https://registry.npmjs.org/@elife/pm2/-/pm2-3.6.1.tgz",
- "integrity": "sha512-JJed7e+0/o22FC4jY6xysH2t56DSbCH2lX6Wi8J2RREd0X6l6yflH8DR+jo48/i58Fi7oujndyRE+mjLkQ+YoA==",
- "dependencies": {
- "strip-ansi": "^6.0.0"
- }
- },
"node_modules/@kenjiuno/decompressrtf": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/@kenjiuno/decompressrtf/-/decompressrtf-0.1.4.tgz",
@@ -915,14 +906,6 @@
"node": ">=12.0"
}
},
- "node_modules/ansi-regex": {
- "version": "5.0.1",
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
- "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
- "engines": {
- "node": ">=8"
- }
- },
"node_modules/argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
@@ -2224,17 +2207,6 @@
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==",
"license": "ISC"
},
- "node_modules/strip-ansi": {
- "version": "6.0.1",
- "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
- "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
- "dependencies": {
- "ansi-regex": "^5.0.1"
- },
- "engines": {
- "node": ">=8"
- }
- },
"node_modules/strip-eof": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
@@ -2368,14 +2340,6 @@
}
},
"dependencies": {
- "@elife/pm2": {
- "version": "3.6.1",
- "resolved": "https://registry.npmjs.org/@elife/pm2/-/pm2-3.6.1.tgz",
- "integrity": "sha512-JJed7e+0/o22FC4jY6xysH2t56DSbCH2lX6Wi8J2RREd0X6l6yflH8DR+jo48/i58Fi7oujndyRE+mjLkQ+YoA==",
- "requires": {
- "strip-ansi": "^6.0.0"
- }
- },
"@kenjiuno/decompressrtf": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/@kenjiuno/decompressrtf/-/decompressrtf-0.1.4.tgz",
@@ -2843,11 +2807,6 @@
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.16.tgz",
"integrity": "sha512-TGw5yVi4saajsSEgz25grObGHEUaDrniwvA2qwSC060KfqGPdglhvPMA2lPIoxs3PQIItj2iag35fONcQqgUaQ=="
},
- "ansi-regex": {
- "version": "5.0.1",
- "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
- "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="
- },
"argparse": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
@@ -3759,14 +3718,6 @@
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz",
"integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ=="
},
- "strip-ansi": {
- "version": "6.0.1",
- "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
- "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
- "requires": {
- "ansi-regex": "^5.0.1"
- }
- },
"strip-eof": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/strip-eof/-/strip-eof-1.0.0.tgz",
diff --git a/release/app/package.json b/release/app/package.json
index 3011e5a16..d84d57298 100644
--- a/release/app/package.json
+++ b/release/app/package.json
@@ -17,7 +17,6 @@
"link-modules": "node -r ts-node/register ../../.erb/scripts/link-modules.ts"
},
"dependencies": {
- "@elife/pm2": "3.6.1",
"@tagspaces/extensions": "1.0.243",
"@tagspaces/tagspaces-common-node": "4.7.2",
"@tagspaces/tagspaces-ws": "4.8.0",
diff --git a/resources/builder.json b/resources/builder.json
index 815ee04ac..777fdacea 100644
--- a/resources/builder.json
+++ b/resources/builder.json
@@ -1,5 +1,6 @@
{
"appId": "org.tagspaces.desktopapp",
+ "afterPack": "./.erb/scripts/apply-fuses.js",
"asar": true,
"asarUnpack": ["**\\*.{node,dll}", "**/node_modules/wasm-vips/**/*"],
"files": ["dist/", "node_modules/", "package.json", ".env", "extconfig.js"],
diff --git a/src/main/main.ts b/src/main/main.ts
index 513774ff5..ff4514118 100644
--- a/src/main/main.ts
+++ b/src/main/main.ts
@@ -9,7 +9,6 @@
* `./src/main.js` using webpack. This gives us some performance wins.
*/
-import pm2 from '@elife/pm2';
import {
BrowserWindow,
BrowserWindowConstructorOptions,
@@ -18,7 +17,9 @@ import {
globalShortcut,
ipcMain,
shell,
+ utilityProcess,
} from 'electron';
+import type { UtilityProcess } from 'electron';
import windowStateKeeper from 'electron-window-state';
import findFreePorts from 'find-free-ports';
import path from 'path';
@@ -40,6 +41,7 @@ let mainWindow: BrowserWindow | null = null;
let globalShortcutsEnabled = false;
let startupFilePath: string | undefined;
let portableMode: boolean | undefined;
+let wsProcess: UtilityProcess | null = null;
const SUPPORTED_EXTS = new Set(['.md', '.mmd', '.txt', '.html', '.glb']);
// --- Debug/Dev Mode ---
@@ -384,45 +386,29 @@ function startWS() {
envPath = path.join(__dirname, '../.env');
}
const properties = propertiesReader(envPath);
- const results = new Promise((resolve, reject) => {
- findPort().then((freePort) => {
- try {
- pm2.start(
- {
- name: 'Tagspaces WS',
- script,
- cwd: filepath,
- args: ['-p', freePort, '-k', properties.get('KEY')],
- restartAt: [],
- },
- (err, pid) => {
- if (err && pid) {
- if (pid && pid.name) console.error(pid.name, err, pid);
- else console.error(err, pid);
- reject(err);
- } else if (err) {
- reject(err);
- } else {
- settings.setUsedWsPort(freePort);
- mainWindow?.webContents.send('start_ws', { port: freePort });
- console.debug('start_ws:' + freePort);
- resolve(
- `Starting ${pid.name} on ${pid.cwd} - pid (${pid.child.pid})`,
- );
- }
- },
+ findPort()
+ .then((freePort) => {
+ const scriptPath = path.join(filepath, script);
+ wsProcess = utilityProcess.fork(
+ scriptPath,
+ ['-p', String(freePort), '-k', String(properties.get('KEY') ?? '')],
+ { cwd: filepath, serviceName: 'TagspacesWS' },
+ );
+ wsProcess.on('spawn', () => {
+ settings.setUsedWsPort(freePort);
+ mainWindow?.webContents.send('start_ws', { port: freePort });
+ console.debug(
+ `start_ws:${freePort} - Tagspaces WS pid (${wsProcess?.pid})`,
);
- } catch (e) {
- console.error('pm2.start err:', e);
- reject(e);
- }
- });
- });
- results
- .then((results) => console.debug(results))
- .catch((err) => console.error('pm2.start err:', err));
+ });
+ wsProcess.on('exit', (code) => {
+ console.debug('Tagspaces WS exit code', code);
+ wsProcess = null;
+ });
+ })
+ .catch((err) => console.error('startWS err:', err));
} catch (ex) {
- console.error('pm2.start Exception __dirname:' + __dirname, ex);
+ console.error('startWS exception __dirname:' + __dirname, ex);
}
}
@@ -507,7 +493,8 @@ const createWindow = async (i18n: any) => {
mainWindow.webContents.on(
'render-process-gone',
(_, { reason, exitCode }) => {
- pm2.stopAll();
+ wsProcess?.kill();
+ wsProcess = null;
globalShortcut.unregisterAll();
app.quit();
},
@@ -563,8 +550,6 @@ app.on('window-all-closed', () => {
// Respect the macOS convention of having the application in memory even
// after all windows have been closed
if (!isMacLike) {
- // pm2.stopAll();
- // globalShortcut.unregisterAll();
app.quit();
}
});
@@ -582,7 +567,8 @@ app.on('activate', (event, hasVisibleWindows) => {
});
app.on('quit', () => {
- pm2.stopAll();
+ wsProcess?.kill();
+ wsProcess = null;
globalShortcut.unregisterAll();
});
@@ -609,8 +595,6 @@ app.on('web-contents-created', (event, contents) => {
});
// --- Startup ---
-startWS();
-
let appI18N: any;
protocol.register();
@@ -618,6 +602,7 @@ protocol.register();
app
.whenReady()
.then(() => {
+ startWS();
return i18nInit().then((i18n) => {
appI18N = i18n;
if (process.platform === 'darwin') {