Skip to content

Commit 6d41901

Browse files
committed
fix(server): expand home paths for app bundle actions
1 parent 5bf35ac commit 6d41901

4 files changed

Lines changed: 44 additions & 6 deletions

File tree

‎apps/server/src/assets/NativeAppIconResolver.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ it.effect("resolves the exact bundle path without Spotlight and caches the conve
4141
if (icon === null) return;
4242
expect(yield* fs.readFileString(icon)).toBe("converted icon");
4343
expect(yield* resolver.resolve(reference)).toBe(icon);
44+
expect(yield* resolver.resolve({ _tag: "app-path", path: "~/Build Output/My App.app" })).toBe(
45+
icon,
46+
);
4447
expect(commands.filter((command) => command === "/usr/bin/sips")).toHaveLength(1);
4548
expect(commands).not.toContain("/usr/bin/mdfind");
4649
expect(yield* resolver.resolve({ _tag: "app-path", path: "relative.app" })).toBeNull();
@@ -53,6 +56,7 @@ it.effect("resolves the exact bundle path without Spotlight and caches the conve
5356
),
5457
),
5558
Effect.provideService(HostProcess.Platform, "darwin"),
59+
Effect.provideService(HostProcess.HomeDirectory, root),
5660
);
5761
}).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
5862
);

‎apps/server/src/assets/NativeAppIconResolver.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
12
import type { NativeAppIconReference } from "@t3tools/contracts";
23
import * as Cache from "effect/Cache";
34
import * as Cause from "effect/Cause";
@@ -95,7 +96,8 @@ const resolveApplicationPath = Effect.fn("NativeAppIconResolver.resolveApplicati
9596
) {
9697
const path = yield* Path.Path;
9798
if (app._tag === "app-path") {
98-
return path.isAbsolute(app.path) && app.path.endsWith(".app") ? app.path : null;
99+
const appPath = expandHomePath(app.path, yield* HostProcess.HomeDirectory);
100+
return path.isAbsolute(appPath) && appPath.endsWith(".app") ? appPath : null;
99101
}
100102
const query =
101103
app._tag === "app-id"

‎apps/server/src/process/externalLauncher.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,36 @@ const layerTest = (input: {
9595
);
9696
};
9797

98+
it.effect("opens home-relative app bundles using the server home directory", () =>
99+
Effect.gen(function* () {
100+
const fs = yield* FileSystem.FileSystem;
101+
const path = yield* Path.Path;
102+
const bin = yield* fs.makeTempDirectoryScoped({ prefix: "t3-app-open-" });
103+
yield* fs.writeFileString(path.join(bin, "open"), "#!/bin/sh\n");
104+
yield* fs.chmod(path.join(bin, "open"), 0o755);
105+
const spawned: ChildProcess.StandardCommand[] = [];
106+
yield* Effect.gen(function* () {
107+
const launcher = yield* ExternalLauncher.ExternalLauncher;
108+
for (const cwd of ["~/Applications/My App.app", "/Applications/My App.app"]) {
109+
yield* launcher.launchEditor({ editor: "file-manager", cwd });
110+
}
111+
}).pipe(
112+
Effect.provide(
113+
layerTest({
114+
platform: "darwin",
115+
env: { PATH: bin },
116+
onSpawn: (command) => spawned.push(command),
117+
}),
118+
),
119+
Effect.provideService(HostProcess.HomeDirectory, "/Users/server"),
120+
);
121+
assert.deepEqual(
122+
spawned.map((command) => command.args),
123+
[["/Users/server/Applications/My App.app"], ["/Applications/My App.app"]],
124+
);
125+
}).pipe(Effect.provide(NodeServices.layer)),
126+
);
127+
98128
it.effect.skipIf(windowsHost)(
99129
"launched browsers and editors do not inherit ELECTRON_RUN_AS_NODE",
100130
() =>

‎apps/server/src/process/externalLauncher.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
12
import * as NodePath from "@effect/platform-node/NodePath";
23
import {
34
EDITORS,
@@ -500,21 +501,22 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
500501
return yield* new ExternalLauncherUnsupportedEditorError({ editor: input.editor });
501502
}
502503

504+
const target = expandHomePath(input.cwd, yield* HostProcess.HomeDirectory);
503505
if (input.reveal === true) {
504-
return yield* resolveFileManagerRevealLaunch(input.cwd, platform, env, command);
506+
return yield* resolveFileManagerRevealLaunch(target, platform, env, command);
505507
}
506508

507509
return {
508510
editor: editorDef.id,
509-
target: input.cwd,
511+
target,
510512
command,
511513
args:
512514
command === "explorer.exe" && env.WSL_DISTRO_NAME !== undefined
513-
? [resolveWslFileManagerPath(input.cwd, env.WSL_DISTRO_NAME)]
515+
? [resolveWslFileManagerPath(target, env.WSL_DISTRO_NAME)]
514516
: platform === "win32"
515517
? // Explorer interprets / as a switch and silently opens a fallback folder.
516-
[normalizeWindowsFileManagerPath(input.cwd)]
517-
: [input.cwd],
518+
[normalizeWindowsFileManagerPath(target)]
519+
: [target],
518520
};
519521
});
520522

0 commit comments

Comments
 (0)