Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 0 additions & 323 deletions apps/desktop/src/lib/trpc/routers/terminal/terminal.stream.test.ts

This file was deleted.

9 changes: 9 additions & 0 deletions apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { projects, workspaces, worktrees } from "@superset/local-db";
import { TRPCError } from "@trpc/server";
import { observable } from "@trpc/server/observable";
import { eq } from "drizzle-orm";
import { appState } from "main/lib/app-state";
import { localDb } from "main/lib/local-db";
import { getDaemonTerminalManager } from "main/lib/terminal";
import {
Expand All @@ -14,6 +15,7 @@ import { z } from "zod";
import { publicProcedure, router } from "../..";
import { assertWorkspaceUsable } from "../workspaces/utils/usability";
import { getWorkspacePath } from "../workspaces/utils/worktree";
import { resolveTerminalThemeType } from "./theme-type";
import { resolveCwd } from "./utils";

const DEBUG_TERMINAL = process.env.SUPERSET_TERMINAL_DEBUG === "1";
Expand Down Expand Up @@ -66,6 +68,7 @@ export const createTerminalRouter = () => {
initialCommands: z.array(z.string()).optional(),
skipColdRestore: z.boolean().optional(),
allowKilled: z.boolean().optional(),
themeType: z.enum(["dark", "light"]).optional(),
}),
)
.mutation(async ({ input }) => {
Expand All @@ -81,6 +84,7 @@ export const createTerminalRouter = () => {
initialCommands,
skipColdRestore,
allowKilled,
themeType,
} = input;

const workspace = localDb
Expand Down Expand Up @@ -115,6 +119,10 @@ export const createTerminalRouter = () => {
.where(eq(projects.id, workspace.projectId))
.get()
: undefined;
const resolvedThemeType = resolveTerminalThemeType({
requestedThemeType: themeType,
persistedThemeState: appState.data.themeState,
});
Comment on lines +122 to +125
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's find and examine the terminal.ts file around the specified lines
find . -name "terminal.ts" -path "*/trpc/routers/terminal/*" | head -5

Repository: superset-sh/superset

Length of output: 120


🏁 Script executed:

# Check nativeTheme usage in the codebase
rg -n --type=ts 'nativeTheme' -g '!node_modules/**' | head -20

Repository: superset-sh/superset

Length of output: 280


🏁 Script executed:

# Look at the theme-type.ts file to understand the resolveTerminalThemeType function
find . -name "theme-type.ts" -path "*/terminal/*" | head -5

Repository: superset-sh/superset

Length of output: 122


🏁 Script executed:

# Read terminal.ts around lines 124-127 to verify the actual code
cat -n apps/desktop/src/lib/trpc/routers/terminal/terminal.ts | sed -n '115,135p'

Repository: superset-sh/superset

Length of output: 707


🏁 Script executed:

# Read theme-type.ts to check the function signature and defaults
cat -n apps/desktop/src/lib/trpc/routers/terminal/theme-type.ts

Repository: superset-sh/superset

Length of output: 1260


🏁 Script executed:

# Also check the imports at the top of terminal.ts to verify nativeTheme availability
cat -n apps/desktop/src/lib/trpc/routers/terminal/terminal.ts | head -30

Repository: superset-sh/superset

Length of output: 1419


🏁 Script executed:

# Check the input schema to see if themeType is optional or required
cat -n apps/desktop/src/lib/trpc/routers/terminal/terminal.ts | sed -n '60,90p'

Repository: superset-sh/superset

Length of output: 1051


🏁 Script executed:

# Look for where this tRPC procedure is called from to understand if themeType is always provided
rg -n 'createOrAttach' -A 2 -B 2 --type=ts -g '!node_modules/**' | head -40

Repository: superset-sh/superset

Length of output: 2887


🏁 Script executed:

# Search for where the tRPC terminal.createOrAttach is called from the renderer side
rg -n 'terminal\.createOrAttach' --type=ts -g '!node_modules/**' -A 5 -B 5

Repository: superset-sh/superset

Length of output: 7746


🏁 Script executed:

# Check if there's a renderer-side theme resolution that determines themeType
rg -n 'resolveTerminalThemeType' --type=ts -g '!node_modules/**' -B 3 -A 3

Repository: superset-sh/superset

Length of output: 19732


systemPrefersDark is not passed to resolveTerminalThemeType — "system" theme in the fallback path will always default to dark.

When the renderer doesn't send themeType and the persisted theme is "system", the function defaults systemPrefersDark to true, resolving to "dark". While the normal path sends themeType from the renderer, the fallback (cold restore or missing themeType) needs to detect the actual OS preference. Use Electron's nativeTheme.shouldUseDarkColors in the main process:

Suggested fix
+import { nativeTheme } from "electron";
 ...
 const resolvedThemeType = resolveTerminalThemeType({
 	requestedThemeType: themeType,
 	persistedThemeState: appState.data.themeState,
+	systemPrefersDark: nativeTheme.shouldUseDarkColors,
 });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const resolvedThemeType = resolveTerminalThemeType({
requestedThemeType: themeType,
persistedThemeState: appState.data.themeState,
});
import { nativeTheme } from "electron";
// ... other imports ...
import { appState } from "main/lib/app-state";
import { resolveTerminalThemeType } from "./theme-type";
// ... rest of file ...
const resolvedThemeType = resolveTerminalThemeType({
requestedThemeType: themeType,
persistedThemeState: appState.data.themeState,
systemPrefersDark: nativeTheme.shouldUseDarkColors,
});
🤖 Prompt for AI Agents
In `@apps/desktop/src/lib/trpc/routers/terminal/terminal.ts` around lines 124 -
127, The fallback path calling resolveTerminalThemeType currently omits
systemPrefersDark, causing persisted "system" theme to assume dark; update the
call that computes resolvedThemeType (where themeType and
appState.data.themeState are passed) to also provide the real OS preference by
reading Electron's nativeTheme.shouldUseDarkColors from the main process (expose
it via your existing IPC/getAPI if needed) and pass that boolean as
systemPrefersDark to resolveTerminalThemeType so "system" resolves correctly.


try {
const result = await terminal.createOrAttach({
Expand All @@ -130,6 +138,7 @@ export const createTerminalRouter = () => {
initialCommands,
skipColdRestore,
allowKilled,
themeType: resolvedThemeType,
portBase: workspace?.portBase,
});

Expand Down
Loading
Loading