Skip to content

Commit e6b9d49

Browse files
committed
feat(startup-settings): Pomodoro clock added
1 parent 2b5251f commit e6b9d49

File tree

8 files changed

+43
-9
lines changed

8 files changed

+43
-9
lines changed

resource/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
#define CLOCK_IDC_START_NO_DISPLAY 174 /**< Start with no display */
182182
#define CLOCK_IDC_START_COUNT_UP 175 /**< Start in count-up mode */
183183
#define CLOCK_IDC_START_SHOW_TIME 176 /**< Start showing current time */
184+
#define CLOCK_IDC_START_POMODORO 177 /**< Start in pomodoro mode */
184185

185186
/** @brief Quick time menu base identifier */
186187
#define CLOCK_IDM_QUICK_TIME_BASE 800 /**< Base ID for dynamic quick time menus */

src/config/config_recovery.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ BOOL ValidateTimerConfig(ConfigSnapshot* snapshot) {
130130
if (strcmp(snapshot->startupMode, "COUNTDOWN") != 0 &&
131131
strcmp(snapshot->startupMode, "COUNT_UP") != 0 &&
132132
strcmp(snapshot->startupMode, "SHOW_TIME") != 0 &&
133-
strcmp(snapshot->startupMode, "NO_DISPLAY") != 0) {
133+
strcmp(snapshot->startupMode, "NO_DISPLAY") != 0 &&
134+
strcmp(snapshot->startupMode, "POMODORO") != 0) {
134135
LOG_WARNING("Invalid startup mode '%s', resetting to COUNTDOWN",
135136
snapshot->startupMode);
136137
strncpy(snapshot->startupMode, "COUNTDOWN",

src/drawing/drawing_render.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "drawing/drawing_image.h"
2424
#include "markdown/markdown_parser.h"
2525
#include "markdown/markdown_image.h"
26-
#include "color/gradient.h"
2726
#include "color/color_parser.h"
2827
#include "../resource/resource.h"
2928

src/main/main_initialization.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "plugin/plugin_manager.h"
2626
#include "drawing/drawing_image.h"
2727
#include "markdown/markdown_interactive.h"
28+
#include "../resource/resource.h"
2829
#include <tlhelp32.h>
2930

3031
/* Helper to check if process is elevated */
@@ -136,7 +137,8 @@ typedef enum {
136137
STARTUP_MODE_DEFAULT,
137138
STARTUP_MODE_COUNT_UP,
138139
STARTUP_MODE_NO_DISPLAY,
139-
STARTUP_MODE_SHOW_TIME
140+
STARTUP_MODE_SHOW_TIME,
141+
STARTUP_MODE_POMODORO
140142
} StartupMode;
141143

142144
static StartupMode ParseStartupMode(const char* modeStr) {
@@ -145,6 +147,7 @@ static StartupMode ParseStartupMode(const char* modeStr) {
145147
if (strcmp(modeStr, "COUNT_UP") == 0) return STARTUP_MODE_COUNT_UP;
146148
if (strcmp(modeStr, "NO_DISPLAY") == 0) return STARTUP_MODE_NO_DISPLAY;
147149
if (strcmp(modeStr, "SHOW_TIME") == 0) return STARTUP_MODE_SHOW_TIME;
150+
if (strcmp(modeStr, "POMODORO") == 0) return STARTUP_MODE_POMODORO;
148151

149152
return STARTUP_MODE_DEFAULT;
150153
}
@@ -181,6 +184,11 @@ static void HandleStartupMode(HWND hwnd) {
181184
CLOCK_LAST_TIME_UPDATE = 0;
182185
break;
183186

187+
case STARTUP_MODE_POMODORO:
188+
LOG_INFO("Setting to pomodoro mode");
189+
PostMessage(hwnd, WM_COMMAND, CLOCK_IDM_POMODORO_START, 0);
190+
break;
191+
184192
case STARTUP_MODE_DEFAULT:
185193
default:
186194
LOG_INFO("Using default countdown mode");
@@ -278,6 +286,10 @@ void InitializeDialogLanguages(void) {
278286
BOOL SetupMainWindow(HINSTANCE hInstance, HWND hwnd, int nCmdShow) {
279287
(void)nCmdShow; // Unused parameter
280288

289+
// Initialize Plugin Data subsystem early - needed by CLI handlers and startup mode
290+
PluginData_Init(hwnd);
291+
PluginManager_SetNotifyWindow(hwnd);
292+
281293
LPWSTR lpCmdLineW = GetCommandLineW();
282294
while (*lpCmdLineW && *lpCmdLineW != L' ') lpCmdLineW++;
283295
while (*lpCmdLineW == L' ') lpCmdLineW++;
@@ -346,12 +358,6 @@ BOOL SetupMainWindow(HINSTANCE hInstance, HWND hwnd, int nCmdShow) {
346358
SetTimer(hwnd, TIMER_ID_VISIBILITY_RETRY, 2000, NULL);
347359
}
348360
}
349-
350-
// Initialize Plugin Data subsystem (File Watcher)
351-
PluginData_Init(hwnd);
352-
353-
// Set notify window for plugin manager hot-reload
354-
PluginManager_SetNotifyWindow(hwnd);
355361

356362
return TRUE;
357363
}

src/plugin/plugin_data.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ BOOL g_hasPluginData = FALSE;
2727
static BOOL g_pluginModeActive = FALSE;
2828
static volatile BOOL g_forceNextUpdate = FALSE;
2929
static CRITICAL_SECTION g_dataCS;
30+
static BOOL g_pluginDataInitialized = FALSE;
3031

3132
/* Watcher thread */
3233
static HANDLE g_hWatchThread = NULL;
@@ -303,6 +304,7 @@ static DWORD WINAPI FileWatcherThread(LPVOID lpParam) {
303304

304305
void PluginData_Init(HWND hwnd) {
305306
InitializeCriticalSection(&g_dataCS);
307+
g_pluginDataInitialized = TRUE;
306308
g_hNotifyWnd = hwnd;
307309
g_hasPluginData = FALSE;
308310
g_pluginDisplayText = NULL;
@@ -329,6 +331,8 @@ void PluginData_Init(HWND hwnd) {
329331
}
330332

331333
void PluginData_Shutdown(void) {
334+
if (!g_pluginDataInitialized) return;
335+
332336
/* Stop watcher thread */
333337
if (g_hWatchThread) {
334338
g_isRunning = FALSE;
@@ -360,6 +364,7 @@ void PluginData_Shutdown(void) {
360364

361365
BOOL PluginData_GetText(wchar_t* buffer, size_t maxLen) {
362366
if (!buffer || maxLen == 0) return FALSE;
367+
if (!g_pluginDataInitialized) return FALSE;
363368

364369
BOOL hasData = FALSE;
365370
EnterCriticalSection(&g_dataCS);
@@ -389,6 +394,7 @@ void PluginData_Clear(void) {
389394
/* Reset poll interval to default */
390395
g_pollIntervalMs = DEFAULT_POLL_INTERVAL_MS;
391396

397+
if (!g_pluginDataInitialized) return;
392398
EnterCriticalSection(&g_dataCS);
393399
g_pluginModeActive = FALSE; // Deactivate plugin mode
394400
g_hasPluginData = FALSE;
@@ -400,6 +406,7 @@ void PluginData_Clear(void) {
400406

401407
void PluginData_SetText(const wchar_t* text) {
402408
if (!text) return;
409+
if (!g_pluginDataInitialized) return;
403410

404411
EnterCriticalSection(&g_dataCS);
405412

@@ -436,6 +443,7 @@ void PluginData_SetText(const wchar_t* text) {
436443
}
437444

438445
void PluginData_SetActive(BOOL active) {
446+
if (!g_pluginDataInitialized) return;
439447
EnterCriticalSection(&g_dataCS);
440448
g_pluginModeActive = active;
441449
if (active) {
@@ -481,6 +489,7 @@ void PluginData_SetActive(BOOL active) {
481489
}
482490

483491
BOOL PluginData_IsActive(void) {
492+
if (!g_pluginDataInitialized) return FALSE;
484493
BOOL active;
485494
EnterCriticalSection(&g_dataCS);
486495
active = g_pluginModeActive;
@@ -489,6 +498,7 @@ BOOL PluginData_IsActive(void) {
489498
}
490499

491500
BOOL PluginData_HasCatimeTag(void) {
501+
if (!g_pluginDataInitialized) return FALSE;
492502
BOOL hasTag = FALSE;
493503
EnterCriticalSection(&g_dataCS);
494504
if (g_pluginModeActive && g_hasPluginData && g_pluginDisplayText) {

src/plugin/plugin_manager.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
static PluginInfo g_plugins[MAX_PLUGINS];
2121
static int g_pluginCount = 0;
2222
static CRITICAL_SECTION g_pluginCS;
23+
static BOOL g_pluginManagerInitialized = FALSE;
2324

2425
/* Hot-reload monitoring */
2526
static HANDLE g_hHotReloadThread = NULL;
@@ -113,6 +114,7 @@ static void ExtractDisplayName(const wchar_t* filename, wchar_t* displayName, si
113114

114115
void PluginManager_Init(void) {
115116
InitializeCriticalSection(&g_pluginCS);
117+
g_pluginManagerInitialized = TRUE;
116118
memset(g_plugins, 0, sizeof(g_plugins));
117119
g_pluginCount = 0;
118120

@@ -130,6 +132,8 @@ void PluginManager_Init(void) {
130132
}
131133

132134
void PluginManager_Shutdown(void) {
135+
if (!g_pluginManagerInitialized) return;
136+
133137
/* Stop hot-reload thread */
134138
if (g_hHotReloadThread) {
135139
g_hotReloadRunning = FALSE;
@@ -188,6 +192,7 @@ int PluginManager_ScanPlugins(void) {
188192

189193
LOG_INFO("Scanning plugin directory: %s", pluginDirA);
190194

195+
if (!g_pluginManagerInitialized) return 0;
191196
EnterCriticalSection(&g_pluginCS);
192197

193198
// Scan into temporary list to preserve state
@@ -334,6 +339,7 @@ void PluginManager_RequestScanAsync(void) {
334339
}
335340

336341
int PluginManager_GetPluginCount(void) {
342+
if (!g_pluginManagerInitialized) return 0;
337343
int count;
338344
EnterCriticalSection(&g_pluginCS);
339345
count = g_pluginCount;
@@ -379,6 +385,7 @@ static void StopPluginInternal(int index) {
379385
}
380386

381387
BOOL PluginManager_StartPlugin(int index) {
388+
if (!g_pluginManagerInitialized) return FALSE;
382389
if (index < 0 || index >= g_pluginCount) {
383390
return FALSE;
384391
}
@@ -501,6 +508,7 @@ static BOOL RestartPluginInternal(int index) {
501508
}
502509

503510
BOOL PluginManager_StopPlugin(int index) {
511+
if (!g_pluginManagerInitialized) return FALSE;
504512
if (index < 0 || index >= g_pluginCount) {
505513
return FALSE;
506514
}
@@ -529,6 +537,7 @@ BOOL PluginManager_StopPlugin(int index) {
529537
}
530538

531539
BOOL PluginManager_TogglePlugin(int index) {
540+
if (!g_pluginManagerInitialized) return FALSE;
532541
if (index < 0 || index >= g_pluginCount) {
533542
return FALSE;
534543
}
@@ -541,6 +550,7 @@ BOOL PluginManager_TogglePlugin(int index) {
541550
}
542551

543552
BOOL PluginManager_IsPluginRunning(int index) {
553+
if (!g_pluginManagerInitialized) return FALSE;
544554
if (index < 0 || index >= g_pluginCount) {
545555
return FALSE;
546556
}
@@ -562,6 +572,7 @@ BOOL PluginManager_IsPluginRunning(int index) {
562572
}
563573

564574
void PluginManager_StopAllPlugins(void) {
575+
if (!g_pluginManagerInitialized) return;
565576
EnterCriticalSection(&g_pluginCS);
566577
for (int i = 0; i < g_pluginCount; i++) {
567578
if (g_plugins[i].isRunning) {

src/tray/tray_menu_submenus.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ void BuildPresetManagementSubmenu(HMENU hMenu) {
183183
CLOCK_IDC_START_COUNT_UP,
184184
GetLocalizedString(NULL, L"Stopwatch"));
185185

186+
AppendMenuW(hStartupSettingsMenu, MF_STRING |
187+
(strcmp(currentStartupMode, "POMODORO") == 0 ? MF_CHECKED : 0),
188+
CLOCK_IDC_START_POMODORO,
189+
GetLocalizedString(NULL, L"Pomodoro"));
190+
186191
AppendMenuW(hStartupSettingsMenu, MF_STRING |
187192
(strcmp(currentStartupMode, "SHOW_TIME") == 0 ? MF_CHECKED : 0),
188193
CLOCK_IDC_START_SHOW_TIME,

src/window_procedure/window_commands.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ BOOL DispatchRangeCommand(HWND hwnd, UINT cmd, WPARAM wp, LPARAM lp) {
665665
if (cmd == CLOCK_IDC_START_SHOW_TIME) { CmdSetStartupMode(hwnd, "SHOW_TIME"); return TRUE; }
666666
if (cmd == CLOCK_IDC_START_COUNT_UP) { CmdSetStartupMode(hwnd, "COUNT_UP"); return TRUE; }
667667
if (cmd == CLOCK_IDC_START_NO_DISPLAY) { CmdSetStartupMode(hwnd, "NO_DISPLAY"); return TRUE; }
668+
if (cmd == CLOCK_IDC_START_POMODORO) { CmdSetStartupMode(hwnd, "POMODORO"); return TRUE; }
668669

669670
/* Plugin commands */
670671
if (HandlePluginCommand(hwnd, cmd)) return TRUE;

0 commit comments

Comments
 (0)