forked from FroglyStudios/YourFocus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
301 lines (272 loc) · 11.8 KB
/
Copy pathApp.tsx
File metadata and controls
301 lines (272 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import React, { useState, useEffect, useCallback } from 'react';
import { Play, Pause, Square, Settings as SettingsIcon, Eye, Activity, Clock, Trophy } from 'lucide-react';
import Timer from './components/Timer';
import Settings from './components/Settings';
import ExerciseModal from './components/ExerciseModal';
import Statistics from './components/Statistics';
import { useTimer } from './hooks/useTimer';
import { useNotifications } from './hooks/useNotifications';
import { useStats } from './hooks/useStats';
import { useTranslation } from './hooks/useTranslation';
import { dataService } from './services/dataService';
import { discordService } from './services/discordService';
import { themeService } from './services/themeService';
function App() {
const { t, isLoaded } = useTranslation();
const [showSettings, setShowSettings] = useState(false);
const [showExercises, setShowExercises] = useState(false);
const [showStats, setShowStats] = useState(false);
// Initialize theme service side effects if needed (already handles DOM in constructor)
useEffect(() => {
// Just touching themeService to ensure it's bundled and runs its constructor early
themeService.getDarkMode();
}, []);
// Load settings from data service
const [settings, setSettings] = useState(dataService.getSettings());
const { sessionDuration, breakDuration, soundEnabled } = settings;
const {
timeLeft,
isRunning,
isBreak,
currentSession,
startTimer,
pauseTimer,
resetTimer,
skipToBreak,
skipToSession
} = useTimer(sessionDuration, breakDuration);
const { requestPermission, showNotification } = useNotifications();
const { stats, addSession, addBreak } = useStats();
// Request notification permission on first load
useEffect(() => {
requestPermission();
// Initialize Discord Rich Presence
discordService.setActivity({
details: t('app.title'),
state: 'Ready to focus',
largeImageKey: 'yourfocus_logo',
largeImageText: t('app.subtitle')
});
}, [requestPermission]);
// Update Discord activity when timer state changes
useEffect(() => {
if (isRunning) {
if (isBreak) {
discordService.startBreak(breakDuration);
} else {
discordService.startSession(sessionDuration, currentSession);
}
} else {
discordService.pauseSession();
}
}, [isRunning, isBreak, sessionDuration, breakDuration, currentSession]);
// Update Discord activity with real-time countdown
useEffect(() => {
if (isRunning) {
discordService.updateSessionActivity(isBreak, timeLeft, currentSession);
}
}, [isRunning, isBreak, timeLeft, currentSession]);
// Sync state to Mini-Overlay
useEffect(() => {
const win = window as any;
if (win.electronAPI && win.electronAPI.mini) {
win.electronAPI.mini.updateTimer({ timeLeft, isBreak, isRunning });
}
}, [timeLeft, isBreak, isRunning]);
// Handle timer completion
useEffect(() => {
if (timeLeft === 0 && isRunning) {
if (isBreak) {
showNotification(
t('notifications.breakComplete'),
t('notifications.breakCompleteBody'),
'session'
);
addSession(sessionDuration);
if (soundEnabled) {
playSound('session');
}
} else {
showNotification(
t('notifications.sessionComplete'),
t('notifications.sessionCompleteBody'),
'break'
);
addBreak(breakDuration);
setShowExercises(true);
if (soundEnabled) {
playSound('break');
}
}
}
}, [timeLeft, isRunning, isBreak, showNotification, sessionDuration, breakDuration, soundEnabled, addSession, addBreak, t]);
const playSound = (type: 'session' | 'break') => {
const audio = new Audio();
if (type === 'break') {
// Gentle chime for break time, or custom sound
audio.src = settings.customBreakSound || 'data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBg==';
} else {
// Subtle bell for session time, or custom sound
audio.src = settings.customSessionSound || 'data:audio/wav;base64,UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBjiN2/LNeSsFJHfE8N2QQAoUXrTp66hVFApGn+DyvmgbBg==';
}
audio.play().catch(() => {
// Ignore errors if audio can't play
});
};
const handleSettingsSave = useCallback((settings: { sessionDuration: number; breakDuration: number; soundEnabled: boolean }) => {
dataService.updateSettings(settings);
setSettings(dataService.getSettings());
setShowSettings(false);
}, []);
// Load settings from data service on mount
useEffect(() => {
setSettings(dataService.getSettings());
}, []);
// Don't render until translations are loaded
if (!isLoaded) {
return (
<div className="min-h-screen bg-theme-bg flex items-center justify-center">
<div className="text-center">
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-theme-primary mx-auto mb-4"></div>
<p className="text-theme-muted">Loading...</p>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-theme-bg">
<div className="container mx-auto px-4 py-8">
{/* Header */}
<div className="text-center mb-12">
<div className="flex items-center justify-center gap-3 mb-4">
<div className="bg-theme-primary p-3 rounded-2xl shadow-lg shadow-theme-primary/20">
<Clock className="w-8 h-8 text-white" />
</div>
<h1 className="text-4xl font-bold text-theme-text">{t('app.title')}</h1>
</div>
<p className="text-theme-muted text-lg max-w-md mx-auto">
{t('app.subtitle')}
</p>
</div>
{/* Main Timer Card */}
<div className="max-w-2xl mx-auto">
<div className="glass-panel rounded-3xl p-8 mb-8">
<Timer
timeLeft={timeLeft}
isBreak={isBreak}
isRunning={isRunning}
currentSession={currentSession}
sessionDuration={sessionDuration}
breakDuration={breakDuration}
/>
{/* Controls */}
<div className="flex items-center justify-center gap-4 mt-8">
{!isRunning ? (
<button
onClick={startTimer}
className="bg-theme-primary hover:bg-theme-primaryHover text-white px-8 py-4 rounded-2xl font-semibold transition-all duration-200 shadow-lg shadow-theme-primary/20 flex items-center gap-3 text-lg"
>
<Play className="w-5 h-5" />
{t('controls.startFocus')}
</button>
) : (
<button
onClick={pauseTimer}
className="bg-orange-500 hover:bg-orange-600 text-white px-8 py-4 rounded-2xl font-semibold transition-all duration-200 shadow-lg hover:shadow-xl flex items-center gap-3 text-lg"
>
<Pause className="w-5 h-5" />
{t('controls.pause')}
</button>
)}
<button
onClick={resetTimer}
className="bg-theme-bg border border-theme-border text-theme-text hover:bg-theme-border px-6 py-4 rounded-2xl font-semibold transition-all duration-200 shadow-lg flex items-center gap-3"
>
<Square className="w-5 h-5" />
{t('controls.reset')}
</button>
</div>
{/* Quick Actions */}
{isRunning && (
<div className="flex items-center justify-center gap-3 mt-6">
{!isBreak ? (
<button
onClick={skipToBreak}
className="text-theme-primary hover:text-theme-primaryHover font-medium transition-colors duration-200 flex items-center gap-2"
>
<Activity className="w-4 h-4" />
{t('controls.takeBreakNow')}
</button>
) : (
<button
onClick={skipToSession}
className="text-theme-primary hover:text-theme-primaryHover font-medium transition-colors duration-200 flex items-center gap-2"
>
<Play className="w-4 h-4" />
{t('controls.backToGaming')}
</button>
)}
</div>
)}
</div>
{/* Action Buttons */}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
<button
onClick={() => setShowSettings(true)}
className="glass-panel hover:bg-theme-bg text-theme-text p-4 rounded-2xl transition-all duration-200 flex items-center justify-center gap-3 font-medium"
>
<SettingsIcon className="w-5 h-5" />
{t('buttons.settings')}
</button>
<button
onClick={() => setShowExercises(true)}
className="glass-panel hover:bg-theme-bg text-theme-text p-4 rounded-2xl transition-all duration-200 flex items-center justify-center gap-3 font-medium"
>
<Eye className="w-5 h-5" />
{t('buttons.exercises')}
</button>
<button
onClick={() => setShowStats(true)}
className="glass-panel hover:bg-theme-bg text-theme-text p-4 rounded-2xl transition-all duration-200 flex items-center justify-center gap-3 font-medium"
>
<Trophy className="w-5 h-5" />
{t('buttons.statistics')}
</button>
<button
onClick={() => {
const win = window as any;
if (win.electronAPI && win.electronAPI.mini) {
win.electronAPI.mini.toggle();
}
}}
className="glass-panel hover:bg-theme-bg text-theme-primary p-4 rounded-2xl transition-all duration-200 flex items-center justify-center gap-3 font-medium border border-theme-primary/20"
>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><rect width="9" height="7" x="12" y="12" rx="1"/></svg>
Mini Mode
</button>
</div>
</div>
</div>
{/* Modals */}
{showSettings && (
<Settings
sessionDuration={sessionDuration}
breakDuration={breakDuration}
soundEnabled={soundEnabled}
onSave={handleSettingsSave}
onClose={() => setShowSettings(false)}
/>
)}
{showExercises && (
<ExerciseModal onClose={() => setShowExercises(false)} />
)}
{showStats && (
<Statistics
stats={stats}
onClose={() => setShowStats(false)}
/>
)}
</div>
);
}
export default App;