mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-09 10:49:29 +00:00
feat(ui): add cross-platform window control styles
Persist automatic and explicit macOS, Windows, GNOME, and minimal control presets with localized settings and platform-aware fallback. Refs #31
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { resolveWindowControlStyle } from './windowControlStyle';
|
||||
|
||||
describe('resolveWindowControlStyle', () => {
|
||||
it('uses the platform convention for automatic style', () => {
|
||||
expect(resolveWindowControlStyle('auto', 'macos')).toBe('macos');
|
||||
expect(resolveWindowControlStyle('auto', 'windows')).toBe('windows');
|
||||
expect(resolveWindowControlStyle('auto', 'linux')).toBe('gnome');
|
||||
});
|
||||
|
||||
it('falls back to macOS styling while an unsupported platform is unresolved', () => {
|
||||
expect(resolveWindowControlStyle('auto', 'unknown')).toBe('macos');
|
||||
expect(resolveWindowControlStyle('auto', 'android')).toBe('macos');
|
||||
});
|
||||
|
||||
it('uses the desktop user agent while native platform detection is unresolved', () => {
|
||||
expect(resolveWindowControlStyle('auto', 'unknown', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)')).toBe('windows');
|
||||
expect(resolveWindowControlStyle('auto', 'unknown', 'Mozilla/5.0 (X11; Linux x86_64)')).toBe('gnome');
|
||||
expect(resolveWindowControlStyle('auto', 'unknown', 'Mozilla/5.0 (Linux; Android 14)')).toBe('macos');
|
||||
});
|
||||
|
||||
it('preserves an explicit style across platforms', () => {
|
||||
expect(resolveWindowControlStyle('macos', 'windows')).toBe('macos');
|
||||
expect(resolveWindowControlStyle('windows', 'linux')).toBe('windows');
|
||||
expect(resolveWindowControlStyle('gnome', 'macos')).toBe('gnome');
|
||||
expect(resolveWindowControlStyle('minimal', 'windows')).toBe('minimal');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { WindowControlStyle } from '../bindings/WindowControlStyle';
|
||||
|
||||
export type ResolvedWindowControlStyle = Exclude<WindowControlStyle, 'auto'>;
|
||||
|
||||
export const resolveWindowControlStyle = (
|
||||
style: WindowControlStyle,
|
||||
os: string,
|
||||
userAgent = ''
|
||||
): ResolvedWindowControlStyle => {
|
||||
if (style !== 'auto') return style;
|
||||
if (os === 'windows') return 'windows';
|
||||
if (os === 'linux') return 'gnome';
|
||||
if (os === 'unknown' && /Windows/i.test(userAgent)) return 'windows';
|
||||
if (os === 'unknown' && /Linux/i.test(userAgent) && !/Android/i.test(userAgent)) return 'gnome';
|
||||
return 'macos';
|
||||
};
|
||||
Reference in New Issue
Block a user