🐛 fix(mac-window): 固定使用 macOS 原生窗口控制

- macOS 窗口创建时启用原生标题栏与红黄绿控制
- 移除主题切换及持久化偏好,兼容旧前端禁用调用
- 保持 Windows/Linux 自定义无边框窗口并补充回归测试
This commit is contained in:
Syngnat
2026-07-30 21:06:12 +08:00
parent aec34a031a
commit c4e7142309
17 changed files with 68 additions and 112 deletions

View File

@@ -240,7 +240,6 @@ import {
SelectLogDirectory,
SelectSavedQueryDirectory,
SetApplicationBrandIcon,
SetMacNativeWindowControls,
SetWindowTranslucency,
} from '../wailsjs/go/app/App';
import { getAntdLocale } from './i18n/frameworkLocale';
@@ -2285,7 +2284,7 @@ function App() {
}, [connections, openSecurityUpdateSettings, runSecurityUpdateRound, securityUpdateStatus, t]);
const isMacRuntime = runtimePlatform === 'darwin'
|| (runtimePlatform === '' && /mac/i.test(detectNavigatorPlatform()));
const useNativeMacWindowControls = isMacRuntime && appearance.useNativeMacWindowControls === true;
const useNativeMacWindowControls = isMacRuntime;
const activeShortcutPlatform = getShortcutPlatform(isMacRuntime);
const macWindowDiagnosticsEnabled = shouldEnableMacWindowDiagnostics(
isMacRuntime,
@@ -2405,17 +2404,6 @@ function App() {
}
}, [macWindowDiagnosticsEnabled, useNativeMacWindowControls]);
useEffect(() => {
if (!isStoreHydrated || !isMacRuntime) {
return;
}
const backendApp = (window as any).go?.app?.App;
if (typeof backendApp?.SetMacNativeWindowControls !== 'function') {
return;
}
void safeWindowRuntimeCall(() => SetMacNativeWindowControls(useNativeMacWindowControls), undefined);
}, [isMacRuntime, isStoreHydrated, useNativeMacWindowControls]);
useEffect(() => {
if (!macWindowDiagnosticsEnabled) {
return;
@@ -6362,20 +6350,6 @@ function App() {
})}
</>,
)}
{isMacRuntime ? renderThemeSettingsSection(
t('app.theme.mac_window.title'),
renderThemeSettingsRow({
label: t('app.theme.mac_window.use_native_controls'),
hint: t('app.theme.mac_window.restart_hint'),
control: (
<Switch
checked={appearance.useNativeMacWindowControls === true}
onChange={(checked) => setAppearance({ useNativeMacWindowControls: checked })}
/>
),
}),
t('app.theme.mac_window.use_native_controls_hint'),
) : null}
{renderThemeSettingsSection(
t('app.theme.startup_window.title'),
renderThemeSettingsRow({
@@ -7174,24 +7148,6 @@ function App() {
</div>
</div>
</div>
{isMacRuntime ? (
<div style={utilityPanelStyle}>
<div style={{ marginBottom: 8, fontWeight: 500 }}>{t('app.theme.mac_window.title')}</div>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
<div>
<div style={{ fontWeight: 500 }}>{t('app.theme.mac_window.use_native_controls')}</div>
<div style={{ ...utilityMutedTextStyle, marginTop: 4 }}>{t('app.theme.mac_window.use_native_controls_hint')}</div>
</div>
<Switch
checked={appearance.useNativeMacWindowControls === true}
onChange={(checked) => setAppearance({ useNativeMacWindowControls: checked })}
/>
</div>
<div style={{ fontSize: 12, color: darkMode ? 'rgba(255,255,255,0.5)' : 'rgba(16,24,40,0.55)', marginTop: 8 }}>
{t('app.theme.mac_window.restart_hint')}
</div>
</div>
) : null}
<div style={utilityPanelStyle}>
<div style={{ marginBottom: 8, fontWeight: 500 }}>{t('app.theme.startup_window.title')}</div>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>

View File

@@ -16,7 +16,6 @@ const storeState = vi.hoisted(() => ({
enabled: true,
opacity: 1,
blur: 0,
useNativeMacWindowControls: false,
},
}));

View File

@@ -36,7 +36,6 @@ const storeState = vi.hoisted(() => ({
enabled: true,
opacity: 1,
blur: 0,
useNativeMacWindowControls: false,
},
}));

View File

@@ -26,7 +26,6 @@ const storeState = vi.hoisted(() => ({
enabled: true,
opacity: 1,
blur: 0,
useNativeMacWindowControls: false,
uiVersion: 'v1' as 'v1' | 'v2',
},
}));

View File

@@ -76,7 +76,7 @@ describe('store appearance persistence', () => {
expect(appearance.enabled).toBe(false);
expect(appearance.opacity).toBe(0.75);
expect(appearance.blur).toBe(6);
expect(appearance.useNativeMacWindowControls).toBe(true);
expect(appearance).not.toHaveProperty('useNativeMacWindowControls');
expect(appearance.tableDoubleClickAction).toBe('open-data');
expect(appearance.v2SidebarSearchMode).toBe('command');
expect(appearance.v2CommandSearchPersistentFilterEnabled).toBe(false);

View File

@@ -157,7 +157,6 @@ export interface AppearanceSettings
enabled: boolean;
opacity: number;
blur: number;
useNativeMacWindowControls: boolean;
tableDoubleClickAction: TableDoubleClickAction;
v2SidebarSearchMode: "command" | "filter";
v2CommandSearchPersistentFilterEnabled: boolean;
@@ -181,7 +180,6 @@ export const DEFAULT_APPEARANCE: AppearanceSettings = {
enabled: true,
opacity: 1.0,
blur: 0,
useNativeMacWindowControls: false,
tableDoubleClickAction: "open-data",
v2SidebarSearchMode: "command",
v2CommandSearchPersistentFilterEnabled: false,
@@ -2959,10 +2957,6 @@ const sanitizeAppearance = (
typeof appearance.blur === "number"
? appearance.blur
: DEFAULT_APPEARANCE.blur,
useNativeMacWindowControls:
typeof appearance.useNativeMacWindowControls === "boolean"
? appearance.useNativeMacWindowControls
: DEFAULT_APPEARANCE.useNativeMacWindowControls,
tableDoubleClickAction: sanitizeTableDoubleClickAction(
appearance.tableDoubleClickAction,
),