Skip to content

Commit b0431f4

Browse files
committed
feat: close Settings Window after saving
1 parent fe32e71 commit b0431f4

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/main/ipcRoutes/window.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { windowRoute } from './window';
2+
import { showWindow } from '@main/window';
3+
import { describe, expect, it, vi, beforeEach } from 'vitest';
4+
5+
// Mock window module
6+
vi.mock('@main/window', () => ({
7+
showWindow: vi.fn(),
8+
}));
9+
10+
describe('windowRoute.showMainWindow', () => {
11+
beforeEach(() => {
12+
vi.clearAllMocks();
13+
});
14+
15+
it('should call showWindow function', async () => {
16+
await windowRoute.showMainWindow.handle({
17+
input: undefined,
18+
context: {} as any,
19+
});
20+
21+
expect(showWindow).toHaveBeenCalled();
22+
expect(showWindow).toHaveBeenCalledTimes(1);
23+
});
24+
25+
it('should handle showWindow being called multiple times', async () => {
26+
await windowRoute.showMainWindow.handle({
27+
input: undefined,
28+
context: {} as any,
29+
});
30+
await windowRoute.showMainWindow.handle({
31+
input: undefined,
32+
context: {} as any,
33+
});
34+
await windowRoute.showMainWindow.handle({
35+
input: undefined,
36+
context: {} as any,
37+
});
38+
39+
expect(showWindow).toHaveBeenCalledTimes(3);
40+
});
41+
42+
it('should handle errors from showWindow', async () => {
43+
(showWindow as any).mockImplementationOnce(() => {
44+
throw new Error('Failed to show window');
45+
});
46+
47+
await expect(
48+
windowRoute.showMainWindow.handle({
49+
input: undefined,
50+
context: {} as any,
51+
}),
52+
).rejects.toThrow('Failed to show window');
53+
});
54+
});

src/main/ipcRoutes/window.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
LauncherWindow,
88
closeSettingsWindow,
99
createSettingsWindow,
10+
showWindow,
1011
} from '@main/window/index';
1112

1213
const t = initIpc.create();
@@ -25,4 +26,7 @@ export const windowRoute = t.router({
2526
LauncherWindow.getInstance().blur();
2627
LauncherWindow.getInstance().hide();
2728
}),
29+
showMainWindow: t.procedure.input<void>().handle(async () => {
30+
showWindow();
31+
}),
2832
});

src/renderer/src/pages/settings/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ export default function Settings() {
6060
isClosable: true,
6161
variant: 'ui-tars-success',
6262
});
63+
64+
// Close settings window and show main window
65+
await api.closeSettingsWindow();
66+
await api.showMainWindow();
6367
};
6468

6569
const handleCancel = async () => {

0 commit comments

Comments
 (0)