Skip to content

Commit a49bcc0

Browse files
committed
chore: improve typing
1 parent 74e3128 commit a49bcc0

23 files changed

Lines changed: 156 additions & 150 deletions

src/main/application/stop_timer_command_handler.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,32 @@
33
import { type CommandStatus, Success } from "@muspellheim/shared";
44

55
import type { StopTimerCommand } from "../../shared/domain/stop_timer_command";
6-
import { Clock } from "../../shared/domain/temporal";
76
import { TimerStoppedEvent } from "../../shared/domain/timer_stopped_event";
87
import { Timer } from "../infrastructure/timer";
98

109
export class StopTimerCommandHandler extends EventTarget {
1110
static create() {
12-
return new StopTimerCommandHandler(
13-
Clock.systemDefaultZone(),
14-
Timer.create(),
15-
);
11+
return new StopTimerCommandHandler(Timer.create());
1612
}
1713

1814
static createNull({
1915
fixedInstant = "2025-08-28T15:52:00Z",
2016
}: {
2117
fixedInstant?: string;
2218
}) {
23-
return new StopTimerCommandHandler(
24-
Clock.fixed(fixedInstant, "Europe/Berlin"),
25-
Timer.createNull({ fixedInstant }),
26-
);
19+
return new StopTimerCommandHandler(Timer.createNull({ fixedInstant }));
2720
}
2821

29-
#clock: Clock;
3022
#timer: Timer;
3123

32-
private constructor(clock: Clock, timer: Timer) {
24+
private constructor(timer: Timer) {
3325
super();
34-
this.#clock = clock;
3526
this.#timer = timer;
3627
}
3728

3829
async handle(_command: StopTimerCommand): Promise<CommandStatus> {
3930
this.#timer.stop();
40-
this.dispatchEvent(
41-
TimerStoppedEvent.create({ timestamp: this.#clock.instant() }),
42-
);
31+
this.dispatchEvent(TimerStoppedEvent.create());
4332
return new Success();
4433
}
4534
}

src/main/index.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ import { BurnUpQueryHandler } from "./application/burn_up_query_handler";
2121
import { TimesheetQueryHandler } from "./application/timesheet_query_handler";
2222
import { Settings } from "../shared/domain/settings";
2323
import { TimerState } from "./domain/timer_state";
24-
import { IntervalElapsedEvent } from "../shared/domain/interval_elapsed_event";
25-
import { TimerStartedEvent } from "../shared/domain/timer_started_event";
26-
import { TimerStoppedEvent } from "../shared/domain/timer_stopped_event";
24+
import {
25+
INTERVAL_ELAPSED_EVENT,
26+
IntervalElapsedEvent,
27+
} from "../shared/domain/interval_elapsed_event";
28+
import {
29+
TIMER_STARTED_EVENT,
30+
TimerStartedEvent,
31+
} from "../shared/domain/timer_started_event";
32+
import {
33+
TIMER_STOPPED_EVENT,
34+
TimerStoppedEvent,
35+
} from "../shared/domain/timer_stopped_event";
2736
import { EventStore } from "./infrastructure/event_store";
2837
import { HolidayRepository } from "./infrastructure/holiday_repository";
2938
import { VacationRepository } from "./infrastructure/vacation_repository";
@@ -289,20 +298,20 @@ function createWindow() {
289298
}
290299

291300
function createMainToLogWindowChannels(window: BrowserWindow) {
292-
startTimerCommandHandler.addEventListener(TimerStartedEvent.TYPE, (event) =>
301+
startTimerCommandHandler.addEventListener(TIMER_STARTED_EVENT, (event) =>
293302
window.webContents.send(
294303
TIMER_STARTED_CHANNEL,
295304
TimerStartedEvent.create(event as TimerStartedEvent),
296305
),
297306
);
298-
stopTimerCommandHandler.addEventListener(TimerStoppedEvent.TYPE, (event) =>
307+
stopTimerCommandHandler.addEventListener(TIMER_STOPPED_EVENT, (event) =>
299308
window.webContents.send(
300309
TIMER_STOPPED_CHANNEL,
301310
TimerStoppedEvent.create(event as TimerStoppedEvent),
302311
),
303312
);
304313
currentIntervalQueryHandler.addEventListener(
305-
IntervalElapsedEvent.TYPE,
314+
INTERVAL_ELAPSED_EVENT,
306315
(event) =>
307316
window.webContents.send(
308317
INTERVAL_ELAPSED_CHANNEL,

src/renderer/application/timer_service.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { type Dispatch, useEffect, useRef } from "react";
55

66
import { IntervalElapsedEvent } from "../../shared/domain/interval_elapsed_event";
77
import { TimerStartedEvent } from "../../shared/domain/timer_started_event";
8-
import { TimerStoppedEvent } from "../../shared/domain/timer_stopped_event";
98
import {
109
type Action,
1110
intervalElapsed,
@@ -40,12 +39,10 @@ export function useCurrentInterval(dispatch: Dispatch<Action>) {
4039
);
4140

4241
const offTimerStoppedEvent = window.activitySampling.onTimerStoppedEvent(
43-
(json) => {
42+
() => {
4443
clearInterval(timeoutId.current);
4544

46-
const dto = JSON.parse(json);
47-
const event = TimerStoppedEvent.create(dto);
48-
dispatch(timerStopped(event));
45+
dispatch(timerStopped());
4946
},
5047
);
5148

src/renderer/domain/log.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,10 @@ export function timerTicked(
8181

8282
const TIMER_STOPPED_ACTION = "timerStopped";
8383

84-
interface TimerStoppedPayload {
85-
timestamp: Temporal.Instant | string;
86-
}
87-
88-
export function timerStopped(
89-
payload: TimerStoppedPayload,
90-
): FluxStandardActionAuto<typeof TIMER_STOPPED_ACTION, TimerStoppedPayload> {
91-
return { type: TIMER_STOPPED_ACTION, payload };
84+
export function timerStopped(): FluxStandardActionAuto<
85+
typeof TIMER_STOPPED_ACTION
86+
> {
87+
return { type: TIMER_STOPPED_ACTION };
9288
}
9389

9490
const INTERVAL_ELAPSED_ACTION = "intervalElapsed";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright (c) 2026 Falko Schumann. All rights reserved. MIT license.
2+
3+
export const ACTIVITY_LOGGED_EVENT = "activityLogged";
4+
5+
export class ActivityLoggedEvent extends Event {
6+
static create() {
7+
return new ActivityLoggedEvent();
8+
}
9+
10+
static createTestInstance() {
11+
return ActivityLoggedEvent.create();
12+
}
13+
14+
private constructor() {
15+
super(ACTIVITY_LOGGED_EVENT);
16+
}
17+
}

src/shared/domain/burn_up_query.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class BurnUpQuery {
1313
to: Temporal.PlainDateLike | string;
1414
categories?: string[];
1515
timeZone?: Temporal.TimeZoneLike;
16-
}): BurnUpQuery {
16+
}) {
1717
return new BurnUpQuery(from, to, categories, timeZone);
1818
}
1919

@@ -27,7 +27,7 @@ export class BurnUpQuery {
2727
to?: Temporal.PlainDateLike | string;
2828
categories?: string[];
2929
timeZone?: Temporal.TimeZoneLike;
30-
} = {}): BurnUpQuery {
30+
} = {}) {
3131
return BurnUpQuery.create({ from, to, categories, timeZone });
3232
}
3333

@@ -58,7 +58,7 @@ export class BurnUpQueryResult {
5858
data?: BurnUpData[];
5959
totalThroughput?: number;
6060
categories?: string[];
61-
} = {}): BurnUpQueryResult {
61+
} = {}) {
6262
return new BurnUpQueryResult(data, totalThroughput, categories);
6363
}
6464

@@ -70,7 +70,7 @@ export class BurnUpQueryResult {
7070
data?: BurnUpData[];
7171
totalThroughput?: number;
7272
categories?: string[];
73-
} = {}): BurnUpQueryResult {
73+
} = {}) {
7474
return BurnUpQueryResult.create({ data, totalThroughput, categories });
7575
}
7676

@@ -98,7 +98,7 @@ export class BurnUpData {
9898
date: Temporal.PlainDate | string;
9999
throughput: number;
100100
cumulativeThroughput: number;
101-
}): BurnUpData {
101+
}) {
102102
return new BurnUpData(date, throughput, cumulativeThroughput);
103103
}
104104

@@ -110,7 +110,7 @@ export class BurnUpData {
110110
date?: Temporal.PlainDate | string;
111111
throughput?: number;
112112
cumulativeThroughput?: number;
113-
} = {}): BurnUpData {
113+
} = {}) {
114114
return BurnUpData.create({ date, throughput, cumulativeThroughput });
115115
}
116116

src/shared/domain/current_interval_query.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import { Temporal } from "@js-temporal/polyfill";
44

55
export class CurrentIntervalQuery {
6-
static create(_options?: never): CurrentIntervalQuery {
6+
static create(_options?: never) {
77
return new CurrentIntervalQuery();
88
}
99

10-
static createTestInstance(options?: never): CurrentIntervalQuery {
10+
static createTestInstance(options?: never) {
1111
return CurrentIntervalQuery.create(options);
1212
}
1313
}
@@ -19,7 +19,7 @@ export class CurrentIntervalQueryResult {
1919
}: {
2020
timestamp?: Temporal.Instant | string;
2121
duration?: Temporal.DurationLike | string;
22-
} = {}): CurrentIntervalQueryResult {
22+
} = {}) {
2323
return new CurrentIntervalQueryResult(timestamp, duration);
2424
}
2525

@@ -29,7 +29,7 @@ export class CurrentIntervalQueryResult {
2929
}: {
3030
timestamp?: Temporal.Instant | string;
3131
duration?: Temporal.DurationLike | string;
32-
} = {}): CurrentIntervalQueryResult {
32+
} = {}) {
3333
return CurrentIntervalQueryResult.create({ timestamp, duration });
3434
}
3535

src/shared/domain/estimate_query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class EstimateEntry {
8383
frequency: number;
8484
probability: number;
8585
cumulativeProbability: number;
86-
}): EstimateEntry {
86+
}) {
8787
return new EstimateEntry(
8888
cycleTime,
8989
frequency,
@@ -102,7 +102,7 @@ export class EstimateEntry {
102102
frequency?: number;
103103
probability?: number;
104104
cumulativeProbability?: number;
105-
} = {}): EstimateEntry {
105+
} = {}) {
106106
return EstimateEntry.create({
107107
cycleTime,
108108
frequency,

src/shared/domain/export_timesheet_command.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class ExportTimesheetCommand {
99
}: {
1010
timesheets: TimesheetEntry[];
1111
fileName: string;
12-
}): ExportTimesheetCommand {
12+
}) {
1313
return new ExportTimesheetCommand(timesheets, fileName);
1414
}
1515

@@ -19,7 +19,7 @@ export class ExportTimesheetCommand {
1919
}: {
2020
timesheets?: TimesheetEntry[];
2121
fileName?: string;
22-
} = {}): ExportTimesheetCommand {
22+
} = {}) {
2323
return ExportTimesheetCommand.create({ timesheets, fileName });
2424
}
2525

src/shared/domain/interval_elapsed_event.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22

33
import { Temporal } from "@js-temporal/polyfill";
44

5-
export interface IntervalElapsedEventInit {
6-
readonly timestamp: Temporal.Instant | string;
7-
readonly interval: Temporal.DurationLike | string;
8-
}
5+
export const INTERVAL_ELAPSED_EVENT = "intervalElapsed";
96

107
export class IntervalElapsedEvent extends Event {
11-
static create(eventInitDict: IntervalElapsedEventInit): IntervalElapsedEvent {
12-
return new IntervalElapsedEvent(IntervalElapsedEvent.TYPE, eventInitDict);
8+
static create({
9+
timestamp,
10+
interval,
11+
}: {
12+
timestamp: Temporal.Instant | string;
13+
interval: Temporal.DurationLike | string;
14+
}) {
15+
return new IntervalElapsedEvent(timestamp, interval);
1316
}
1417

1518
static createTestInstance({
@@ -18,18 +21,19 @@ export class IntervalElapsedEvent extends Event {
1821
}: {
1922
timestamp?: Temporal.Instant | string;
2023
interval?: Temporal.DurationLike | string;
21-
} = {}): IntervalElapsedEvent {
24+
} = {}) {
2225
return IntervalElapsedEvent.create({ timestamp, interval });
2326
}
2427

25-
static readonly TYPE = "intervalElapsed";
26-
2728
readonly timestamp: Temporal.Instant;
2829
readonly interval: Temporal.Duration;
2930

30-
private constructor(type: string, eventInitDict: IntervalElapsedEventInit) {
31-
super(type);
32-
this.timestamp = Temporal.Instant.from(eventInitDict.timestamp);
33-
this.interval = Temporal.Duration.from(eventInitDict.interval);
31+
private constructor(
32+
timestamp: Temporal.Instant | string,
33+
interval: Temporal.DurationLike | string,
34+
) {
35+
super(INTERVAL_ELAPSED_EVENT);
36+
this.timestamp = Temporal.Instant.from(timestamp);
37+
this.interval = Temporal.Duration.from(interval);
3438
}
3539
}

0 commit comments

Comments
 (0)