|
| 1 | +var _a, _b, _c; |
| 2 | +import { PomodoroTimer, PomodoroMode } from './timers/PomodoroTimer.js'; |
| 3 | +import { PomodoroUIManager } from './ui/UiManager.js'; |
| 4 | +const UI = new PomodoroUIManager(); |
| 5 | +UI.loadSettings(); |
| 6 | +let focusDuration = 22; |
| 7 | +let breakDuration = 5; |
| 8 | +if (localStorage) { |
| 9 | + const storedFocusDuration = localStorage.getItem('focusDuration'); |
| 10 | + const storedBreakDuration = localStorage.getItem('breakDuration'); |
| 11 | + if (storedFocusDuration && storedBreakDuration) { |
| 12 | + focusDuration = parseInt(storedFocusDuration); |
| 13 | + breakDuration = parseInt(storedBreakDuration); |
| 14 | + } |
| 15 | +} |
| 16 | +const pomodoro = new PomodoroTimer(focusDuration, breakDuration, (mode) => { |
| 17 | + UI.handleModeChange(mode); |
| 18 | +}); |
| 19 | +pomodoro.updateTimerDisplay(); |
| 20 | +console.log(pomodoro.modeNotifications); |
| 21 | +function updateDuration() { |
| 22 | + if (!pomodoro.isTimerActive) { |
| 23 | + const newWorkDuration = parseInt(UI.prop.focusNumber_I.value, 10); |
| 24 | + const newBreakDuration = parseInt(UI.prop.breakNumber_I.value, 10); |
| 25 | + if (!isNaN(newWorkDuration) && !isNaN(newBreakDuration)) { |
| 26 | + pomodoro.updateDuration(newWorkDuration, newBreakDuration); |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | +if (UI.prop.updateDurationButton) { |
| 31 | + UI.prop.updateDurationButton.addEventListener('click', updateDuration); |
| 32 | +} |
| 33 | +if (UI.prop.timerDisplay) { |
| 34 | + (_a = UI.prop.timerDisplay) === null || _a === void 0 ? void 0 : _a.addEventListener('click', () => { |
| 35 | + if (pomodoro.isTimerActive) { |
| 36 | + pomodoro.Pause(); |
| 37 | + UI.handleModeChange(PomodoroMode.None); |
| 38 | + UI.prop.start_B ? UI.prop.start_B.disabled = false : null; |
| 39 | + UI.prop.stop_B ? UI.prop.stop_B.disabled = true : null; |
| 40 | + UI.prop.stop_B ? UI.prop.stop_B.classList.remove('hover') : null; |
| 41 | + } |
| 42 | + else if (!pomodoro.isTimerActive) { |
| 43 | + pomodoro.startTick(); |
| 44 | + UI.prop.start_B ? UI.prop.start_B.classList.remove('hover') : null; |
| 45 | + UI.handleModeChange(pomodoro.actualMode); |
| 46 | + UI.prop.start_B ? UI.prop.start_B.disabled = true : null; |
| 47 | + UI.prop.stop_B ? UI.prop.stop_B.disabled = false : null; |
| 48 | + UI.prop.reset_B ? UI.prop.reset_B.disabled = false : null; |
| 49 | + } |
| 50 | + }); |
| 51 | + (_b = UI.prop.timerDisplay) === null || _b === void 0 ? void 0 : _b.addEventListener('mouseover', () => { |
| 52 | + if (pomodoro.isTimerActive) { |
| 53 | + UI.prop.stop_B ? UI.prop.stop_B.classList.add('hover') : null; |
| 54 | + } |
| 55 | + else if (!pomodoro.isTimerActive) { |
| 56 | + UI.prop.start_B ? UI.prop.start_B.classList.add('hover') : null; |
| 57 | + } |
| 58 | + }); |
| 59 | + (_c = UI.prop.timerDisplay) === null || _c === void 0 ? void 0 : _c.addEventListener('mouseleave', () => { |
| 60 | + UI.prop.stop_B ? UI.prop.stop_B.classList.remove('hover') : null; |
| 61 | + UI.prop.start_B ? UI.prop.start_B.classList.remove('hover') : null; |
| 62 | + }); |
| 63 | +} |
| 64 | +if (UI.prop.start_B) { |
| 65 | + UI.prop.start_B.addEventListener('click', () => { |
| 66 | + pomodoro.startTick(); |
| 67 | + UI.handleModeChange(pomodoro.actualMode); |
| 68 | + }); |
| 69 | +} |
| 70 | +if (UI.prop.stop_B) { |
| 71 | + UI.prop.stop_B.addEventListener('click', () => { |
| 72 | + pomodoro.Pause(); |
| 73 | + UI.handleModeChange(PomodoroMode.None); |
| 74 | + }); |
| 75 | +} |
| 76 | +if (UI.prop.reset_B) { |
| 77 | + UI.prop.reset_B.addEventListener('click', () => { |
| 78 | + pomodoro.ResetAndPause(); |
| 79 | + UI.handleModeChange(PomodoroMode.None); |
| 80 | + }); |
| 81 | +} |
| 82 | +if (UI.prop.settingsGear) { |
| 83 | + UI.prop.settingsGear.addEventListener('click', () => { |
| 84 | + var _a, _b; |
| 85 | + if ((_a = UI.prop.settingsBg) === null || _a === void 0 ? void 0 : _a.classList.contains('open')) { |
| 86 | + UI.prop.settingsBg ? UI.prop.settingsBg.classList.remove('open') : null; |
| 87 | + if (pomodoro.isTimerActive) { |
| 88 | + pomodoro.startTick(); |
| 89 | + } |
| 90 | + } |
| 91 | + else if (!((_b = UI.prop.settingsBg) === null || _b === void 0 ? void 0 : _b.classList.contains('open'))) { |
| 92 | + UI.prop.settingsBg ? UI.prop.settingsBg.classList.add('open') : null; |
| 93 | + UI.handleModeChange(PomodoroMode.None); |
| 94 | + pomodoro.Pause(); |
| 95 | + } |
| 96 | + }); |
| 97 | + if (UI.prop.settingsExit) { |
| 98 | + UI.prop.settingsExit.addEventListener('click', () => { |
| 99 | + console.log('iu'); |
| 100 | + UI.prop.settingsBg ? UI.prop.settingsBg.classList.remove('open') : null; |
| 101 | + if (pomodoro.isTimerActive) { |
| 102 | + pomodoro.startTick(); |
| 103 | + } |
| 104 | + }); |
| 105 | + } |
| 106 | + if (UI.prop.updateDurationButton) { |
| 107 | + UI.prop.updateDurationButton.addEventListener('click', () => { |
| 108 | + UI.prop.settingsBg ? UI.prop.settingsBg.classList.remove('open') : null; |
| 109 | + pomodoro.ResetAndPause(); |
| 110 | + UI.saveSettings(); |
| 111 | + }); |
| 112 | + } |
| 113 | +} |
| 114 | +if (UI.prop.focusNumber_I && UI.prop.focusRange_I) { |
| 115 | + UI.prop.focusNumber_I.value = UI.prop.focusRange_I.value; |
| 116 | +} |
| 117 | +if (UI.prop.focusRange_I) { |
| 118 | + UI.prop.focusRange_I.addEventListener("input", (event) => { |
| 119 | + UI.prop.focusNumber_I.value = event.target.value; |
| 120 | + }); |
| 121 | +} |
| 122 | +if (UI.prop.breakNumber_I && UI.prop.breakRange_I) { |
| 123 | + UI.prop.breakNumber_I.value = UI.prop.breakRange_I.value; |
| 124 | +} |
| 125 | +if (UI.prop.breakRange_I) { |
| 126 | + UI.prop.breakRange_I.addEventListener("input", (event) => { |
| 127 | + UI.prop.breakNumber_I.value = event.target.value; |
| 128 | + }); |
| 129 | +} |
| 130 | +if (UI.prop.modeNotificationsSwitch) { |
| 131 | + addEventListener('click', () => { |
| 132 | + var _a, _b; |
| 133 | + if ((_a = UI.prop.modeNotificationsSwitch) === null || _a === void 0 ? void 0 : _a.checked) { |
| 134 | + pomodoro.modeNotifications = true; |
| 135 | + } |
| 136 | + else if (!((_b = UI.prop.modeNotificationsSwitch) === null || _b === void 0 ? void 0 : _b.checked)) { |
| 137 | + pomodoro.modeNotifications = false; |
| 138 | + } |
| 139 | + }); |
| 140 | +} |
| 141 | +if (UI.prop.tabTitleSwitch) { |
| 142 | + addEventListener('click', () => { |
| 143 | + var _a, _b; |
| 144 | + if ((_a = UI.prop.tabTitleSwitch) === null || _a === void 0 ? void 0 : _a.checked) { |
| 145 | + pomodoro.tabTitleTimer = true; |
| 146 | + } |
| 147 | + else if (!((_b = UI.prop.tabTitleSwitch) === null || _b === void 0 ? void 0 : _b.checked)) { |
| 148 | + pomodoro.tabTitleTimer = false; |
| 149 | + } |
| 150 | + }); |
| 151 | +} |
0 commit comments