// Name: Pomodoro Timer // Description: A simple pomodoro timer widget. // Author: Strajk import '@johnlindquist/kit' interface WidgetState { time: string goal: string } // Prompt the user for the duration in minutes const durationMinutes = await arg( { placeholder: 'Enter duration in minutes', options: ['30', '45', '60', '90'], }, ) // Prompt the user for the goal const goal = await arg('Enter your goal', 'Focus') // Calculate the end time based on the selected duration const endTime = new Date(Date.now() + parseInt(durationMinutes) * 60 * 1000) let intervalId: NodeJS.Timeout // Function to update the widget with the remaining time const updateWidget = async () => { const remaining = Math.max(0, endTime.getTime() - Date.now()) const minutes = Math.floor((remaining / (1000 * 60)) % 60) const seconds = Math.floor((remaining / 1000) % 60) if (remaining <= 0) { clearInterval(intervalId) await notify('Pomodoro Timer Finished!') await focusAppWindow('Paper') // Assuming "Paper" is the app name widgetInstance.close() return } widgetInstance.setState({ time: `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`, } as WidgetState) } // Create the widget with initial state and position const widgetInstance = await widget( ` <div class="fixed bottom-0 right-0 p-4 bg-gray-200 rounded-lg shadow-md"> <h2 class="text-lg font-bold">{{time}}</h2> <p class="text-sm">{{goal}}</p> </div> `, { x: screen.width - 200, y: screen.height - 100, width: 200, height: 100, state: { time: `${durationMinutes}:00`, goal: goal, } as WidgetState, }, ) // Set interval to update the widget every second intervalId = setInterval(updateWidget, 1000) // Hide the main script window hide()