Skip to content

Commit 43c0d8b

Browse files
committed
shell bug fixes
1 parent bb6f950 commit 43c0d8b

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/main/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function createWindow(): void {
7575
titleBarStyle: "hiddenInset",
7676
show: false,
7777
webPreferences: {
78-
nodeIntegration: false,
78+
nodeIntegration: true,
7979
contextIsolation: true,
8080
preload: path.join(__dirname, "preload.js"),
8181
enableBlinkFeatures: "GetDisplayMedia",

src/main/services/shell.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as fs from "node:fs";
12
import * as os from "node:os";
23
import { type IpcMainInvokeEvent, ipcMain, type WebContents } from "electron";
34
import * as pty from "node-pty";
@@ -38,13 +39,44 @@ export function registerShellIpc(): void {
3839

3940
const shell = getDefaultShell();
4041
const homeDir = os.homedir();
42+
let workingDir = cwd || homeDir;
43+
44+
// Validate that the directory exists
45+
if (!fs.existsSync(workingDir)) {
46+
console.warn(
47+
`Shell session ${sessionId}: cwd "${workingDir}" does not exist, falling back to home directory`,
48+
);
49+
workingDir = homeDir;
50+
}
51+
52+
console.log(
53+
`Creating shell session ${sessionId}: shell=${shell}, cwd=${workingDir}`,
54+
);
55+
56+
// Build environment with proper locale settings for macOS
57+
const env = { ...process.env } as Record<string, string>;
58+
59+
// On macOS, ensure locale is properly set for shell compatibility
60+
if (os.platform() === "darwin" && !process.env.LC_ALL) {
61+
const locale = process.env.LC_CTYPE || "en_US.UTF-8";
62+
env.LANG = locale;
63+
env.LC_ALL = locale;
64+
env.LC_MESSAGES = locale;
65+
env.LC_NUMERIC = locale;
66+
env.LC_COLLATE = locale;
67+
env.LC_MONETARY = locale;
68+
}
69+
70+
// Spawn as login shell to properly load PATH and environment
71+
const shellArgs = ["-l"];
4172

42-
const ptyProcess = pty.spawn(shell, [], {
73+
const ptyProcess = pty.spawn(shell, shellArgs, {
4374
name: "xterm-256color",
4475
cols: 80,
4576
rows: 24,
46-
cwd: cwd || homeDir,
47-
env: process.env as Record<string, string>,
77+
cwd: workingDir,
78+
env,
79+
encoding: null,
4880
});
4981

5082
// Send data to renderer
@@ -53,7 +85,10 @@ export function registerShellIpc(): void {
5385
});
5486

5587
// Handle exit
56-
ptyProcess.onExit(() => {
88+
ptyProcess.onExit(({ exitCode, signal }) => {
89+
console.error(
90+
`Shell session ${sessionId} exited with code ${exitCode}, signal ${signal}`,
91+
);
5792
event.sender.send(`shell:exit:${sessionId}`);
5893
sessions.delete(sessionId);
5994
});

0 commit comments

Comments
 (0)