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
25 changes: 3 additions & 22 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { getCurrentWindow } from "@tauri-apps/api/window";
import "./styles/base.css";
import "./styles/buttons.css";
import "./styles/sidebar.css";
Expand Down Expand Up @@ -54,6 +53,8 @@ import { useWorkspaceRestore } from "./features/workspaces/hooks/useWorkspaceRes
import { useResizablePanels } from "./features/layout/hooks/useResizablePanels";
import { useLayoutMode } from "./features/layout/hooks/useLayoutMode";
import { useSidebarToggles } from "./features/layout/hooks/useSidebarToggles";
import { useTransparencyPreference } from "./features/layout/hooks/useTransparencyPreference";
import { useWindowLabel } from "./features/layout/hooks/useWindowLabel";
import {
RightPanelCollapseButton,
SidebarCollapseButton,
Expand Down Expand Up @@ -84,19 +85,6 @@ import type {
WorkspaceInfo,
} from "./types";

function useWindowLabel() {
const [label, setLabel] = useState("main");
useEffect(() => {
try {
const window = getCurrentWindow();
setLabel(window.label ?? "main");
} catch {
setLabel("main");
}
}, []);
return label;
}

function MainApp() {
const {
settings: appSettings,
Expand Down Expand Up @@ -187,10 +175,7 @@ function MainApp() {
const [settingsSection, setSettingsSection] = useState<SettingsSection | null>(
null,
);
const [reduceTransparency, setReduceTransparency] = useState(() => {
const stored = localStorage.getItem("reduceTransparency");
return stored === "true";
});
const { reduceTransparency, setReduceTransparency } = useTransparencyPreference();
const dictationReady = dictationModel.status?.state === "ready";
const holdDictationKey = (appSettings.dictationHoldKey ?? "").toLowerCase();
const handleToggleDictation = useCallback(async () => {
Expand Down Expand Up @@ -309,10 +294,6 @@ function MainApp() {
);
}, [appSettings.defaultAccessMode]);

useEffect(() => {
localStorage.setItem("reduceTransparency", String(reduceTransparency));
}, [reduceTransparency]);

const { status: gitStatus, refresh: refreshGitStatus } =
useGitStatus(activeWorkspace);
const compactTab = isTablet ? tabletTab : activeTab;
Expand Down
17 changes: 17 additions & 0 deletions src/features/layout/hooks/useTransparencyPreference.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect, useState } from "react";

export function useTransparencyPreference(storageKey = "reduceTransparency") {
const [reduceTransparency, setReduceTransparency] = useState(() => {
const stored = localStorage.getItem(storageKey);
return stored === "true";
});

useEffect(() => {
localStorage.setItem(storageKey, String(reduceTransparency));
}, [reduceTransparency, storageKey]);

return {
reduceTransparency,
setReduceTransparency,
};
}
17 changes: 17 additions & 0 deletions src/features/layout/hooks/useWindowLabel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect, useState } from "react";
import { getCurrentWindow } from "@tauri-apps/api/window";

export function useWindowLabel(defaultLabel = "main") {
const [label, setLabel] = useState(defaultLabel);

useEffect(() => {
try {
const window = getCurrentWindow();
setLabel(window.label ?? defaultLabel);
} catch {
setLabel(defaultLabel);
}
}, [defaultLabel]);

return label;
}