Skip to content

Commit aa22180

Browse files
committed
refactor electron style setting for mac only
Made-with: Cursor
1 parent e0e7bce commit aa22180

File tree

5 files changed

+42
-30
lines changed

5 files changed

+42
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ yarn.lock
4242
.env.development
4343

4444
.cursor
45+
.claude
4546

4647
# Public directory (large media files)
4748
public/

electron/main/index.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,6 +2718,8 @@ let installationLock: Promise<PromiseReturnType> = Promise.resolve({
27182718
// ==================== window create ====================
27192719
async function createWindow() {
27202720
const isMac = process.platform === 'darwin';
2721+
const isAppleSilicon = isMac && process.arch === 'arm64';
2722+
const supportsTransparency = isAppleSilicon;
27212723

27222724
// Ensure .eigent directories exist before anything else
27232725
ensureEigentDirectories();
@@ -2749,23 +2751,23 @@ async function createWindow() {
27492751
height: 800,
27502752
minWidth: 1050,
27512753
minHeight: 650,
2752-
// Use native frame on Windows for better native integration
2753-
frame: isWindows ? true : false,
27542754
show: false, // Don't show until content is ready to avoid white screen
2755-
// Only use transparency on macOS and Linux (not supported well on Windows)
2756-
transparent: !isWindows,
2757-
// Solid background on Windows (respect dark/light mode), fully transparent on macOS for native vibrancy
2758-
backgroundColor: isWindows
2759-
? nativeTheme.shouldUseDarkColors
2755+
// Only use transparency on Apple Silicon Macs (older Macs/Windows/Linux have rendering issues)
2756+
transparent: supportsTransparency,
2757+
// Solid background for non-transparent mode, fully transparent on Apple Silicon for native vibrancy
2758+
backgroundColor: supportsTransparency
2759+
? '#00000000'
2760+
: nativeTheme.shouldUseDarkColors
27602761
? '#1e1e1e'
2761-
: '#ffffff'
2762-
: '#00000000',
2762+
: '#ffffff',
27632763
// macOS-specific title bar styling
27642764
titleBarStyle: isMac ? 'hidden' : undefined,
27652765
trafficLightPosition: isMac ? { x: 10, y: 10 } : undefined,
27662766
icon: path.join(VITE_PUBLIC, 'favicon.ico'),
2767-
// Rounded corners on macOS and Linux (as original)
2768-
roundedCorners: !isWindows,
2767+
// Rounded corners on Apple Silicon Macs (transparent mode)
2768+
roundedCorners: supportsTransparency,
2769+
// Non-transparent platforms need a frame except macOS (which uses hidden titleBarStyle)
2770+
frame: isMac ? false : isWindows ? true : false,
27692771
// Windows-specific options
27702772
...(isWindows && {
27712773
autoHideMenuBar: true, // Hide menu bar on Windows for cleaner look
@@ -2783,8 +2785,8 @@ async function createWindow() {
27832785
},
27842786
});
27852787

2786-
// Apply native macOS effects
2787-
if (process.platform === 'darwin') {
2788+
// Apply native macOS visual effects only on Apple Silicon (transparent mode support)
2789+
if (supportsTransparency) {
27882790
win.once('ready-to-show', () => {
27892791
if (win && !win.isDestroyed()) {
27902792
try {
@@ -2797,7 +2799,7 @@ async function createWindow() {
27972799
// Make titlebar transparent
27982800
setTransparentTitlebar(win);
27992801

2800-
log.info('[MacOS] Applied native visual effects');
2802+
log.info('[MacOS] Applied native visual effects (Apple Silicon)');
28012803
} catch (error) {
28022804
log.error('[MacOS] Failed to apply native visual effects:', error);
28032805
}

electron/preload/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
5353
onExecuteAction: (callback: (action: string) => void) =>
5454
ipcRenderer.on('execute-action', (event, action) => callback(action)),
5555
getPlatform: () => process.platform,
56+
getArch: () => process.arch,
5657
getHomeDir: () => ipcRenderer.invoke('get-home-dir'),
5758
createWebView: (id: string, url: string) =>
5859
ipcRenderer.invoke('create-webview', id, url),

src/pages/Setting/General.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export default function SettingGeneral() {
8282

8383
useEffect(() => {
8484
const platform = window.electronAPI.getPlatform();
85-
console.log(platform);
85+
const arch = window.electronAPI.getArch();
86+
const isAppleSilicon = platform === 'darwin' && arch === 'arm64';
87+
8688
const baseThemes = [
8789
{
8890
img: dark,
@@ -96,7 +98,7 @@ export default function SettingGeneral() {
9698
},
9799
];
98100

99-
if (platform === 'darwin') {
101+
if (isAppleSilicon) {
100102
setThemeList([
101103
...baseThemes,
102104
{
@@ -107,6 +109,10 @@ export default function SettingGeneral() {
107109
]);
108110
} else {
109111
setThemeList(baseThemes);
112+
// If user previously had transparent mode on an unsupported device, fall back to dark
113+
if (appearance === 'transparent') {
114+
setAppearance('dark');
115+
}
110116
}
111117
}, []);
112118

@@ -236,8 +242,8 @@ export default function SettingGeneral() {
236242
return (
237243
<div className="m-auto h-auto w-full flex-1">
238244
{/* Header Section */}
239-
<div className="mx-auto flex w-full max-w-[900px] items-center justify-between px-6 pb-6 pt-8">
240-
<div className="flex w-full flex-row items-center justify-between gap-4">
245+
<div className="px-6 pb-6 pt-8 mx-auto flex w-full max-w-[900px] items-center justify-between">
246+
<div className="gap-4 flex w-full flex-row items-center justify-between">
241247
<div className="flex flex-col">
242248
<div className="text-heading-sm font-bold text-text-heading">
243249
{t('setting.general')}
@@ -246,10 +252,10 @@ export default function SettingGeneral() {
246252
</div>
247253
</div>
248254
{/* Content Section */}
249-
<div className="mb-xl flex flex-col gap-6">
255+
<div className="mb-xl gap-6 flex flex-col">
250256
{/* Profile Section */}
251-
<div className="item-center flex flex-row justify-between rounded-2xl bg-surface-secondary px-6 py-4">
252-
<div className="flex flex-col gap-2">
257+
<div className="item-center rounded-2xl bg-surface-secondary px-6 py-4 flex flex-row justify-between">
258+
<div className="gap-2 flex flex-col">
253259
<div className="text-body-base font-bold text-text-heading">
254260
{t('setting.profile')}
255261
</div>
@@ -263,7 +269,7 @@ export default function SettingGeneral() {
263269
/>
264270
</div>
265271
</div>
266-
<div className="flex items-center gap-sm">
272+
<div className="gap-sm flex items-center">
267273
<Button
268274
onClick={() => {
269275
window.location.href = `https://www.eigent.ai/dashboard?email=${authStore.email}`;
@@ -294,7 +300,7 @@ export default function SettingGeneral() {
294300
</div>
295301

296302
{/* Language Section */}
297-
<div className="item-center flex flex-row justify-between rounded-2xl bg-surface-secondary px-6 py-4">
303+
<div className="item-center rounded-2xl bg-surface-secondary px-6 py-4 flex flex-row justify-between">
298304
<div className="flex flex-1 items-center">
299305
<div className="text-body-base font-bold text-text-heading">
300306
{t('setting.language')}
@@ -304,7 +310,7 @@ export default function SettingGeneral() {
304310
<SelectTrigger className="w-48">
305311
<SelectValue placeholder={t('setting.select-language')} />
306312
</SelectTrigger>
307-
<SelectContent className="border bg-input-bg-default">
313+
<SelectContent className="bg-input-bg-default border">
308314
<SelectGroup>
309315
<SelectItem value="system">
310316
{t('setting.system-default')}
@@ -320,20 +326,20 @@ export default function SettingGeneral() {
320326
</div>
321327

322328
{/* Appearance Section */}
323-
<div className="item-center flex flex-col justify-between gap-4 rounded-2xl bg-surface-secondary px-6 py-4">
329+
<div className="item-center gap-4 rounded-2xl bg-surface-secondary px-6 py-4 flex flex-col justify-between">
324330
<div className="text-body-base font-bold text-text-heading">
325331
{t('setting.appearance')}
326332
</div>
327-
<div className="flex w-full flex-row items-center gap-md">
333+
<div className="gap-md flex w-full flex-row items-center">
328334
{themeList.map((item: any) => (
329335
<div
330336
key={item.label}
331-
className="group flex w-full flex-col items-center gap-sm hover:cursor-pointer"
337+
className="group gap-sm flex w-full flex-col items-center hover:cursor-pointer"
332338
onClick={() => setAppearance(item.value)}
333339
>
334340
<img
335341
src={item.img}
336-
className={`group-hover:border-bg-fill-info-primary aspect-[183/91.67] w-full rounded-lg border border-solid border-transparent transition-all ${
342+
className={`group-hover:border-bg-fill-info-primary rounded-lg aspect-[183/91.67] w-full border border-solid border-transparent transition-all ${
337343
item.value == appearance
338344
? 'border-bg-fill-info-primary'
339345
: ''
@@ -353,8 +359,8 @@ export default function SettingGeneral() {
353359
</div>
354360

355361
{/* Network Proxy Section */}
356-
<div className="flex flex-col gap-4 rounded-2xl bg-surface-secondary px-6 py-4">
357-
<div className="flex flex-col gap-1">
362+
<div className="gap-4 rounded-2xl bg-surface-secondary px-6 py-4 flex flex-col">
363+
<div className="gap-1 flex flex-col">
358364
<div className="text-body-base font-bold text-text-heading">
359365
{t('setting.network-proxy')}
360366
</div>

src/types/electron.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
interface IpcRenderer {
1616
getPlatform: () => string;
17+
getArch: () => string;
1718
minimizeWindow: () => void;
1819
toggleMaximizeWindow: () => void;
1920
closeWindow: () => void;
@@ -50,6 +51,7 @@ interface ElectronAPI {
5051
triggerMenuAction: (action: string) => void;
5152
onExecuteAction: (callback: (action: string) => void) => void;
5253
getPlatform: () => string;
54+
getArch: () => string;
5355
getHomeDir: () => Promise<string>;
5456
createWebView: (id: string, url: string) => Promise<any>;
5557
hideWebView: (id: string) => Promise<any>;

0 commit comments

Comments
 (0)