Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(launch): resize HUD overlay to fit system language prompt

EtienneLescot3a81f554509b
diff --git a/src/components/launch/LaunchWindow.test.tsx b/src/components/launch/LaunchWindow.test.tsx
index 29a67374b..bd8bfb62d 100644
--- a/src/components/launch/LaunchWindow.test.tsx
+++ b/src/components/launch/LaunchWindow.test.tsx
@@ -78,20 +78,24 @@ vi.mock("@/native", () => ({
},
}));
+const i18nState = vi.hoisted(() => ({
+ value: {
+ locale: "en",
+ setLocale: vi.fn(),
+ systemLocaleSuggestion: null as string | null,
+ acceptSystemLocaleSuggestion: vi.fn(),
+ dismissSystemLocaleSuggestion: vi.fn(),
+ resolveSystemLocaleSuggestion: vi.fn(),
+ },
+}));
+
vi.mock("@/i18n/loader", () => ({
getAvailableLocales: () => ["en"],
getLocaleName: () => "English",
}));
vi.mock("@/contexts/I18nContext", () => ({
- useI18n: () => ({
- locale: "en",
- setLocale: vi.fn(),
- systemLocaleSuggestion: null,
- acceptSystemLocaleSuggestion: vi.fn(),
- dismissSystemLocaleSuggestion: vi.fn(),
- resolveSystemLocaleSuggestion: vi.fn(),
- }),
+ useI18n: () => i18nState.value,
useScopedT: () => (key: string) => {
const translations: Record<string, string> = {
"sourceSelector.defaultSourceName": "Screen",
@@ -115,6 +119,11 @@ vi.mock("@/contexts/I18nContext", () => ({
"tooltips.hideHUD": "Hide HUD",
"tooltips.closeApp": "Close App",
language: "Language",
+ "systemLanguagePrompt.title": "Use your system language?",
+ "systemLanguagePrompt.description":
+ "We detected English as your system language. Do you want to switch OpenScreen to English?",
+ "systemLanguagePrompt.keepDefault": "Keep current language",
+ "systemLanguagePrompt.switch": "Switch to English",
};
return translations[key] ?? key;
},
@@ -208,6 +217,10 @@ describe("LaunchWindow record button", () => {
recorderState.value.toggleRecording.mockClear();
selectedSourceChangedListeners = [];
sourceSelectorClosedListeners = [];
+ i18nState.value.systemLocaleSuggestion = null;
+ i18nState.value.acceptSystemLocaleSuggestion.mockClear();
+ i18nState.value.dismissSystemLocaleSuggestion.mockClear();
+ i18nState.value.resolveSystemLocaleSuggestion.mockClear();
stubElectronAPI(vi.fn(async () => null));
});
@@ -341,3 +354,84 @@ describe("LaunchWindow record button", () => {
});
});
});
+
+describe("LaunchWindow system language prompt", () => {
+ beforeEach(() => {
+ platformState.value = "darwin";
+ class ResizeObserver {
+ observe() {
+ return undefined;
+ }
+ unobserve() {
+ return undefined;
+ }
+ disconnect() {
+ return undefined;
+ }
+ }
+ vi.stubGlobal("ResizeObserver", ResizeObserver);
+ recorderState.value.toggleRecording.mockClear();
+ selectedSourceChangedListeners = [];
+ sourceSelectorClosedListeners = [];
+ i18nState.value.systemLocaleSuggestion = null;
+ i18nState.value.acceptSystemLocaleSuggestion.mockClear();
+ i18nState.value.dismissSystemLocaleSuggestion.mockClear();
+ i18nState.value.resolveSystemLocaleSuggestion.mockClear();
+ stubElectronAPI(vi.fn(async () => null));
+ });
+
+ afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ });
+
+ it("grows the HUD overlay tall enough to fit the prompt so its buttons stay clickable", async () => {
+ i18nState.value.systemLocaleSuggestion = "zh-CN";
+
+ renderLaunchWindow();
+
+ const prompt = await screen.findByText("Use your system language?");
+ expect(prompt).toBeInTheDocument();
+
+ // jsdom reports zero layout, so stub the prompt's box: 32px top offset
+ // (the panel's `top-8`) plus a realistic height forces the resize path
+ // to compute a window that contains the prompt's full extent.
+ const promptBox = { width: 480, height: 130 };
+ vi.spyOn(prompt.parentElement as HTMLElement, "getBoundingClientRect").mockReturnValue({
+ top: 32,
+ left: 60,
+ right: 60 + promptBox.width,
+ bottom: 32 + promptBox.height,
+ width: promptBox.width,
+ height: promptBox.height,
+ x: 60,
+ y: 32,
+ toJSON: () => ({}),
+ });
+
+ await waitFor(() => {
+ expect(window.electronAPI.setHudOverlaySize).toHaveBeenCalled();
+ });
+
+ const sizeMock = window.electronAPI.setHudOverlaySize as unknown as {
+ mock: { calls: Array<[number, number]> };
+ };
+ const [, height] = sizeMock.mock.calls[sizeMock.mock.calls.length - 1];
+ // Must at least cover the prompt (32 + 130) plus the TOP_MARGIN slack (24).
+ expect(height).toBeGreaterThanOrEqual(32 + promptBox.height + 24);
+ });
+
+ it("routes the switch and keep-default buttons to the i18n context", async () => {
+ i18nState.value.systemLocaleSuggestion = "zh-CN";
+
+ renderLaunchWindow();
+
+ await screen.findByText("Use your system language?");
+
+ fireEvent.click(screen.getByRole("button", { name: "Switch to English" }));
+ expect(i18nState.value.acceptSystemLocaleSuggestion).toHaveBeenCalledTimes(1);
+
+ fireEvent.click(screen.getByRole("button", { name: "Keep current language" }));
+ expect(i18nState.value.dismissSystemLocaleSuggestion).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsx
index 6b614caae..e01c2964a 100644
--- a/src/components/launch/LaunchWindow.tsx
+++ b/src/components/launch/LaunchWindow.tsx
@@ -148,6 +148,7 @@ export function LaunchWindow() {
const languageMenuPanelRef = useRef<HTMLDivElement | null>(null);
const hudBarRef = useRef<HTMLDivElement | null>(null);
const deviceSelectorRef = useRef<HTMLDivElement | null>(null);
+ const systemLocalePromptRef = useRef<HTMLDivElement | null>(null);
// Measured bar height, anchors the popups above the tall vertical tray so they don't overlap it.
const [hudBarHeight, setHudBarHeight] = useState(0);
const [languageMenuStyle, setLanguageMenuStyle] = useState<{
@@ -351,6 +352,19 @@ export function LaunchWindow() {
halfWidth = Math.max(halfWidth, centerX - rect.left, rect.right - centerX);
}
+ // The system-language prompt is anchored at `top-8` (32px) of the renderer; the
+ // bottom-anchored overlay only reserves enough room for the bar, so without this
+ // the prompt's buttons get clipped above the OS window's visible area (issue #30).
+ if (systemLocalePromptRef.current) {
+ const rect = systemLocalePromptRef.current.getBoundingClientRect();
+ // scrollHeight covers the un-clipped box if the viewport is currently too short.
+ const promptHeight = rect.height || systemLocalePromptRef.current.scrollHeight;
+ if (promptHeight > 0) {
+ topFromBottom = Math.max(topFromBottom, 32 + promptHeight);
+ }
+ halfWidth = Math.max(halfWidth, centerX - rect.left, rect.right - centerX);
+ }
+
setHudBarHeight((prev) => {
const next = Math.round(barEl.scrollHeight);
return Math.abs(prev - next) > 1 ? next : prev;
@@ -402,6 +416,10 @@ export function LaunchWindow() {
(el: HTMLDivElement | null) => observeHudElement(el, languageMenuPanelRef),
[observeHudElement],
);
+ const setSystemLocalePromptEl = useCallback(
+ (el: HTMLDivElement | null) => observeHudElement(el, systemLocalePromptRef),
+ [observeHudElement],
+ );
const hudIgnoreMouseEventsRef = useRef<boolean | undefined>(undefined);
const setHudMouseEventsEnabled = useCallback(
@@ -621,6 +639,7 @@ export function LaunchWindow() {
>
{systemLocaleSuggestion && (
<div
+ ref={setSystemLocalePromptEl}
data-hud-interactive="true"
className={`fixed top-8 left-1/2 z-30 w-[calc(100vw-1rem)] max-w-[520px] -translate-x-1/2 rounded-xl border border-white/15 bg-[rgba(20,20,28,0.95)] p-3 shadow-2xl backdrop-blur-xl text-white animate-in fade-in-0 zoom-in-95 duration-200 ${styles.electronNoDrag}`}
>