Skip to content

Commit 01bd91d

Browse files
authored
🤖 feat: default folder picker to home directory in server mode (#1018)
_Generated with `mux`_ In server mode, the directory picker now defaults to the user's home directory (~) instead of the current working directory (.). - Added `general.getHomeDirectory` API endpoint - Frontend fetches home dir on mount and uses it as the default initial path for the DirectoryPickerModal
1 parent 2fe9791 commit 01bd91d

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/browser/components/ProjectCreateModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export const ProjectCreateModal: React.FC<ProjectCreateModalProps> = ({
185185
</Dialog>
186186
<DirectoryPickerModal
187187
isOpen={isDirPickerOpen}
188-
initialPath={path || "."}
188+
initialPath={path || "~"}
189189
onClose={() => setIsDirPickerOpen(false)}
190190
onSelectPath={handleWebPickerPathSelected}
191191
/>

src/node/services/projectService.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,23 @@ describe("ProjectService", () => {
132132
if (result.success) throw new Error("Expected failure");
133133
expect(result.error).toContain("ENOENT");
134134
});
135+
136+
it("expands ~ to home directory", async () => {
137+
const result = await service.listDirectory("~");
138+
139+
expect(result.success).toBe(true);
140+
if (!result.success) throw new Error("Expected success");
141+
142+
expect(result.data.path).toBe(os.homedir());
143+
});
144+
145+
it("expands ~/subpath to home directory subpath", async () => {
146+
const result = await service.listDirectory("~/.");
147+
148+
expect(result.success).toBe(true);
149+
if (!result.success) throw new Error("Expected success");
150+
151+
expect(result.data.path).toBe(os.homedir());
152+
});
135153
});
136154
});

src/node/services/projectService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { log } from "@/node/services/log";
99
import type { BranchListResult } from "@/common/orpc/types";
1010
import type { FileTreeNode } from "@/common/utils/git/numstatParser";
1111
import * as path from "path";
12+
import * as os from "os";
1213

1314
/**
1415
* List directory contents for the DirectoryPickerModal.
@@ -17,7 +18,12 @@ import * as path from "path";
1718
* - children are the immediate subdirectories (not recursive)
1819
*/
1920
async function listDirectory(requestedPath: string): Promise<FileTreeNode> {
20-
const normalizedRoot = path.resolve(requestedPath || ".");
21+
// Expand ~ to home directory (path.resolve doesn't handle tilde)
22+
const expanded =
23+
requestedPath === "~" || requestedPath.startsWith("~/")
24+
? requestedPath.replace("~", os.homedir())
25+
: requestedPath;
26+
const normalizedRoot = path.resolve(expanded || ".");
2127
const entries = await fsPromises.readdir(normalizedRoot, { withFileTypes: true });
2228

2329
const children: FileTreeNode[] = entries

0 commit comments

Comments
 (0)