Skip to content

Commit e85fc4d

Browse files
Make all break windows fade out at the same time
1 parent 2f860fa commit e85fc4d

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

app/global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ declare const ipcRenderer: {
1212
invokeGetAppInitialized: () => Promise<boolean>;
1313
invokeSetAppInitialized: () => Promise<void>;
1414
invokeBreakStart: () => Promise<void>;
15+
invokeBreakEnd: () => Promise<void>;
1516
onPlayEndSound: (
1617
cb: (type: string, volume?: number) => void,
1718
) => Promise<void>;
1819
onPlayStartSound: (
1920
cb: (type: string, volume?: number) => void,
2021
) => Promise<void>;
2122
onBreakStart: (cb: (breakEndTime: number) => void) => void;
23+
onBreakEnd: (cb: () => void) => void;
2224
};
2325

2426
declare const processEnv: {

app/main/lib/ipc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ ipcMain.handle(IpcChannel.BreakStart, (): void => {
5353
sendIpc(IpcChannel.BreakStart, breakEndTime);
5454
});
5555

56+
ipcMain.handle(IpcChannel.BreakEnd, (): void => {
57+
log.info(IpcChannel.BreakEnd);
58+
sendIpc(IpcChannel.BreakEnd);
59+
});
60+
5661
ipcMain.handle(
5762
IpcChannel.SoundStartPlay,
5863
(event: IpcMainInvokeEvent, type: SoundType, volume: number = 1): void => {

app/renderer/components/break.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ export default function Break() {
4646
setCountingDown(false);
4747
};
4848

49+
// Listen for break end broadcasts from other windows
50+
const handleBreakEnd = () => {
51+
setClosing(true);
52+
};
53+
4954
ipcRenderer.onBreakStart(handleBreakStart);
55+
ipcRenderer.onBreakEnd(handleBreakEnd);
5056

5157
// Delay or the window displays incorrectly.
5258
// FIXME: work out why and how to avoid this.
@@ -100,7 +106,9 @@ export default function Break() {
100106
if (isPrimary && settings && settings?.soundType !== SoundType.None) {
101107
ipcRenderer.invokeEndSound(settings.soundType, settings.breakSoundVolume);
102108
}
103-
setClosing(true);
109+
110+
// Broadcast to all windows to start their closing animations
111+
await ipcRenderer.invokeBreakEnd();
104112
}, [settings]);
105113

106114
if (settings === null || allowPostpone === null) {

app/renderer/preload.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ process.once("loaded", () => {
5353
invokeBreakStart: () => {
5454
return ipcRenderer.invoke("BREAK_START");
5555
},
56+
invokeBreakEnd: () => {
57+
return ipcRenderer.invoke("BREAK_END");
58+
},
5659
onPlayStartSound: (cb) => {
5760
ipcRenderer.on("SOUND_START_PLAY", (_event, type, volume = 1) => {
5861
cb(type, volume);
@@ -68,5 +71,10 @@ process.once("loaded", () => {
6871
cb(breakEndTime);
6972
});
7073
},
74+
onBreakEnd: (cb) => {
75+
ipcRenderer.on("BREAK_END", () => {
76+
cb();
77+
});
78+
},
7179
});
7280
});

app/types/ipc.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export enum IpcChannel {
22
AllowPostponeGet = "ALLOW_POSTPONE_GET",
33
AppInitializedSet = "APP_INITIALIZED_SET",
44
AppInitializedGet = "APP_INITIALIZED_GET",
5+
BreakEnd = "BREAK_END",
56
BreakLengthGet = "BREAK_LENGTH_GET",
67
BreakPostpone = "BREAK_POSTPONE",
78
BreakStart = "BREAK_START",

0 commit comments

Comments
 (0)