Skip to content

Commit ca5f75e

Browse files
committed
refactor: remove ts-results dependency, use native error handling
1 parent a3ae2ed commit ca5f75e

File tree

11 files changed

+348
-393
lines changed

11 files changed

+348
-393
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
"redux": "^5.0.1",
6969
"tailwind-merge": "^3.3.1",
7070
"tailwindcss": "^4.1.16",
71-
"ts-results": "^3.3.0",
7271
"tsx": "^4.20.6",
7372
"typescript": "^5.9.3",
7473
"universal-analytics": "^0.5.3",

src/main/actions.ts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ export const init: ThunkActionCreator = () => async (dispatch, getState) => {
2929
// Discover apps for this target
3030
const target = targetRegistry.getById(targetInfo.id);
3131
if (target) {
32-
const appsResult = await target.discoverApps();
33-
if (appsResult.ok) {
32+
try {
33+
const apps = await target.discoverApps();
3434
dispatch(targetSlice.actions.appsUpdated({
3535
targetId: target.id,
36-
apps: appsResult.val,
36+
apps,
3737
}));
3838
dispatch(targetSlice.actions.discoveryCompleted(target.id));
39+
} catch (error) {
40+
console.error(`Failed to discover apps for ${target.id}:`, error);
3941
}
4042
}
4143
}
@@ -88,13 +90,7 @@ export const debug: ThunkActionCreator<{ targetId: string; app: AppInfo }>
8890
}
8991

9092
// Launch the app using the target adapter
91-
const connectionResult = await target.launch(app, {});
92-
93-
if (!connectionResult.ok) {
94-
throw connectionResult.val;
95-
}
96-
97-
const connection = connectionResult.val;
93+
const connection = await target.launch(app, {});
9894
const sessionId = connection.connectionId;
9995

10096
// Determine connection type
@@ -160,13 +156,7 @@ export const debugPath: ThunkActionCreator<string> = () => async () => {
160156
export const addRemoteDevice: ThunkActionCreator<RemoteDeviceOptions>
161157
= (options) => async (dispatch) => {
162158
try {
163-
const targetResult = await targetRegistry.addRemoteDevice(options);
164-
165-
if (!targetResult.ok) {
166-
throw targetResult.val;
167-
}
168-
169-
const target = targetResult.val;
159+
const target = await targetRegistry.addRemoteDevice(options);
170160

171161
// Register target in Redux store
172162
dispatch(
@@ -180,13 +170,15 @@ export const addRemoteDevice: ThunkActionCreator<RemoteDeviceOptions>
180170
);
181171

182172
// Discover apps from the new target
183-
const appsResult = await target.discoverApps();
184-
if (appsResult.ok) {
173+
try {
174+
const apps = await target.discoverApps();
185175
dispatch(targetSlice.actions.appsUpdated({
186176
targetId: target.id,
187-
apps: appsResult.val,
177+
apps,
188178
}));
189179
dispatch(targetSlice.actions.discoveryCompleted(target.id));
180+
} catch (error) {
181+
console.error(`Failed to discover apps for ${target.id}:`, error);
190182
}
191183

192184
void dialog.showMessageBox({
@@ -221,14 +213,12 @@ export const refreshDeviceApps: ThunkActionCreator<string> = (targetId) => async
221213
}
222214

223215
// Discover apps from the target
224-
const appsResult = await target.discoverApps();
225-
if (appsResult.ok) {
226-
dispatch(targetSlice.actions.appsUpdated({
227-
targetId,
228-
apps: appsResult.val,
229-
}));
230-
dispatch(targetSlice.actions.discoveryCompleted(targetId));
231-
}
216+
const apps = await target.discoverApps();
217+
dispatch(targetSlice.actions.appsUpdated({
218+
targetId,
219+
apps,
220+
}));
221+
dispatch(targetSlice.actions.discoveryCompleted(targetId));
232222
} catch (error) {
233223
const errorMessage = error instanceof Error ? error.message : String(error);
234224
dialog.showErrorBox("Refresh Device Error", errorMessage);

src/main/targets/local/adapter.ts

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { spawn } from "child_process";
22
import path from "node:path";
33

44
import getPort from "get-port";
5-
import { Result } from "ts-results";
65
import { v4 } from "uuid";
76

87
import type { AppInfo } from "../../../reducers/target";
@@ -33,67 +32,57 @@ export class LocalTargetAdapter implements TargetAdapter {
3332
}
3433
}
3534

36-
async discoverApps(): Promise<Result<AppInfo[], Error>> {
37-
return Result.wrapAsync(async () => {
38-
const { adapter } = await importByPlatform();
39-
const result = await adapter.readAll();
40-
41-
if (!result.ok) {
42-
throw result.val;
43-
}
44-
45-
const apps = result.val;
46-
47-
// Return apps with metadata (device context is added by caller)
48-
return apps.map((app) => ({
49-
...app,
50-
metadata: {
51-
platform: process.platform,
52-
},
53-
}));
54-
});
35+
async discoverApps(): Promise<AppInfo[]> {
36+
const { adapter } = await importByPlatform();
37+
const apps = await adapter.readAll();
38+
39+
// Return apps with metadata (device context is added by caller)
40+
return apps.map((app) => ({
41+
...app,
42+
metadata: {
43+
platform: process.platform,
44+
},
45+
}));
5546
}
5647

5748
async launch(
5849
app: AppInfo,
5950
options: LaunchOptions = {},
60-
): Promise<Result<DebugConnection, Error>> {
61-
return Result.wrapAsync(async () => {
62-
if (!app.exePath) {
63-
throw new Error("App does not have an executable path");
64-
}
65-
66-
const nodePort = await getPort();
67-
const windowPort = await getPort();
68-
69-
const debugFlags = options.debugFlags ?? [
70-
`--inspect=${nodePort}`,
71-
`--remote-debugging-port=${windowPort}`,
72-
"--remote-allow-origins=devtools://devtools",
73-
];
74-
75-
const sp = spawn(app.exePath, debugFlags, {
76-
cwd: options.cwd ?? (process.platform === "win32" ? path.dirname(app.exePath) : "/"),
77-
env: options.env,
78-
});
79-
80-
const connectionId = v4();
81-
82-
const connection: DebugConnection = {
83-
connectionId,
84-
debugPorts: {
85-
node: nodePort,
86-
renderer: windowPort,
87-
},
88-
processHandle: sp,
89-
cleanup: () => {
90-
sp.kill();
91-
return Promise.resolve();
92-
},
93-
};
94-
95-
return connection;
51+
): Promise<DebugConnection> {
52+
if (!app.exePath) {
53+
throw new Error("App does not have an executable path");
54+
}
55+
56+
const nodePort = await getPort();
57+
const windowPort = await getPort();
58+
59+
const debugFlags = options.debugFlags ?? [
60+
`--inspect=${nodePort}`,
61+
`--remote-debugging-port=${windowPort}`,
62+
"--remote-allow-origins=devtools://devtools",
63+
];
64+
65+
const sp = spawn(app.exePath, debugFlags, {
66+
cwd: options.cwd ?? (process.platform === "win32" ? path.dirname(app.exePath) : "/"),
67+
env: options.env,
9668
});
69+
70+
const connectionId = v4();
71+
72+
const connection: DebugConnection = {
73+
connectionId,
74+
debugPorts: {
75+
node: nodePort,
76+
renderer: windowPort,
77+
},
78+
processHandle: sp,
79+
cleanup: () => {
80+
sp.kill();
81+
return Promise.resolve();
82+
},
83+
};
84+
85+
return connection;
9786
}
9887

9988
async disconnect(): Promise<void> {

0 commit comments

Comments
 (0)