Skip to content

Commit e9a962e

Browse files
committed
Add Electron diagnostics
1 parent 73f06fb commit e9a962e

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
desktop: patch
3+
---
4+
5+
Add a 'diagnostics' command to help debug Electron issues

apps/desktop/build.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { fileURLToPath } from 'node:url';
66

77
const config: Configuration = {
88
artifactName: '${productName}-${version}-${platform}-${arch}.${ext}',
9-
asarUnpack: ['resources/**', '**/node_modules/@the-dev-tools/server/dist/server', '**/node_modules/@the-dev-tools/cli/dist/cli'],
9+
asarUnpack: [
10+
'resources/**',
11+
'**/node_modules/@the-dev-tools/server/dist/server',
12+
'**/node_modules/@the-dev-tools/cli/dist/cli',
13+
],
1014
extraMetadata: {
1115
name: 'DevTools',
1216
},

apps/desktop/src/main/index.ts

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Command, FetchHttpClient, Path, Url } from '@effect/platform';
1+
import { Command, FetchHttpClient, FileSystem, Path, Url } from '@effect/platform';
22
import * as NodeContext from '@effect/platform-node/NodeContext';
33
import * as NodeRuntime from '@effect/platform-node/NodeRuntime';
44
import { Config, Console, Effect, pipe, Runtime } from 'effect';
@@ -7,6 +7,7 @@ import { autoUpdater } from 'electron-updater';
77
import child_process from 'node:child_process';
88
import os from 'node:os';
99
import { Agent } from 'undici';
10+
import packageJson from '../../package.json';
1011
import { CustomUpdateProvider, UpdateOptions } from './update';
1112

1213
// Workaround to allow unlimited concurrent HTTP/1.1 connections
@@ -256,22 +257,56 @@ const desktop = pipe(
256257
);
257258

258259
const args = process.argv.slice(process.defaultApp ? 2 : 1);
259-
const cli = pipe(
260-
Effect.gen(function* () {
261-
const path = yield* Path.Path;
260+
const cli = Effect.gen(function* () {
261+
const path = yield* Path.Path;
262262

263-
const dist = yield* pipe(
264-
import.meta.resolve('@the-dev-tools/cli'),
265-
Url.fromString,
266-
Effect.flatMap(path.fromFileUrl),
267-
);
263+
const dist = yield* pipe(import.meta.resolve('@the-dev-tools/cli'), Url.fromString, Effect.flatMap(path.fromFileUrl));
268264

269-
yield* execFile(path.join(dist, 'cli'), args);
265+
yield* execFile(path.join(dist, 'cli'), args);
270266

271-
app.quit();
272-
}),
273-
);
267+
app.quit();
268+
});
274269

275-
const main = args.length > 0 ? cli : desktop;
270+
const logPath = Effect.fn(function* (title: string, path: string) {
271+
const fs = yield* FileSystem.FileSystem;
272+
const exists = yield* pipe(fs.access(path, { ok: true }), Effect.isSuccess);
273+
yield* Effect.log(`${title} - ${path} - [${exists ? 'OK' : 'N/A'}]`);
274+
});
275+
276+
const diagnostics = Effect.gen(function* () {
277+
const path = yield* Path.Path;
278+
279+
yield* Effect.log(`version ${packageJson.version}`);
280+
281+
yield* logPath('__dirname', __dirname);
282+
283+
yield* logPath('cwd', process.cwd());
284+
285+
yield* logPath('app.getAppPath()', app.getAppPath());
286+
287+
const root = path.join(app.getAppPath(), '../..');
288+
yield* logPath('root', root);
289+
290+
yield* logPath('import.meta.filename', import.meta.filename);
291+
292+
const resolvedPath = import.meta.resolve('.');
293+
yield* Effect.log(`import.meta.resolve - ${resolvedPath}`);
294+
295+
const serverPath = yield* pipe(
296+
import.meta.resolve('@the-dev-tools/server'),
297+
Url.fromString,
298+
Effect.flatMap(path.fromFileUrl),
299+
);
300+
yield* logPath('@the-dev-tools/server', serverPath);
301+
yield* logPath('@the-dev-tools/server unpacked', serverPath.replaceAll('app.asar', 'app.asar.unpacked'));
302+
303+
app.quit();
304+
});
305+
306+
const main = Effect.gen(function* () {
307+
if (args[0] === 'diagnostics') return yield* diagnostics;
308+
if (args.length > 0) return yield* cli;
309+
return yield* desktop;
310+
});
276311

277312
pipe(main, Effect.provide(NodeContext.layer), Effect.provide(FetchHttpClient.layer), NodeRuntime.runMain);

0 commit comments

Comments
 (0)