personal memory agent
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

todos: migrate badge and nudge background fetches

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

+52 -43
+52 -43
apps/todos/background.html
··· 2 2 _nudgeTimers: [], 3 3 4 4 initialize() { 5 - this.updateBadge(); 6 - this.checkNudges(); 7 - }, 5 + AppServices.registerTask('todos', 'update-badge', { 6 + intervalMs: 5 * 60 * 1000, 7 + run: async ({ apiJson }) => { 8 + const data = await apiJson('/app/todos/api/badge-count'); 9 + if (!data || !Number.isFinite(data.count)) { 10 + return undefined; 11 + } 12 + return data.count; 13 + }, 14 + onSuccess: (count) => { 15 + if (count === undefined) { 16 + return; 17 + } 18 + this.updateBadge(count); 19 + } 20 + }); 8 21 9 - async updateBadge() { 10 - try { 11 - const response = await fetch('/app/todos/api/badge-count'); 12 - if (response.ok) { 13 - const data = await response.json(); 14 - if (data.count > 0) { 15 - AppServices.badges.app.set('todos', data.count); 16 - } else { 17 - AppServices.badges.app.clear('todos'); 22 + AppServices.registerTask('todos', 'check-nudges', { 23 + run: async ({ apiJson }) => { 24 + const data = await apiJson('/app/todos/api/nudges'); 25 + if (!data || !Array.isArray(data.nudges)) { 26 + return undefined; 18 27 } 28 + this.checkNudges(data.nudges); 29 + return data.nudges.length; 19 30 } 20 - } catch (err) { 21 - console.error('[Todos] Failed to fetch badge count:', err); 31 + }); 32 + }, 33 + 34 + updateBadge(count) { 35 + if (count > 0) { 36 + AppServices.badges.app.set('todos', count); 37 + } else { 38 + AppServices.badges.app.clear('todos'); 22 39 } 23 40 }, 24 41 25 - async checkNudges() { 26 - try { 27 - const response = await fetch('/app/todos/api/nudges'); 28 - if (!response.ok) return; 29 - const data = await response.json(); 42 + checkNudges(nudges) { 43 + // Clear existing timers 44 + this._nudgeTimers.forEach(t => clearTimeout(t)); 45 + this._nudgeTimers = []; 30 46 31 - // Clear existing timers 32 - this._nudgeTimers.forEach(t => clearTimeout(t)); 33 - this._nudgeTimers = []; 47 + const now = Date.now(); 48 + for (const nudge of nudges) { 49 + const nudgeTime = this._parseNudge(nudge.nudge); 50 + const delay = nudgeTime - now; 34 51 35 - const now = Date.now(); 36 - for (const nudge of data.nudges) { 37 - const nudgeTime = this._parseNudge(nudge.nudge); 38 - const delay = nudgeTime - now; 39 - 40 - if (delay > 0 && delay < 24 * 60 * 60 * 1000) { 41 - const timer = setTimeout(() => { 42 - AppServices.notifications.show({ 43 - app: 'todos', 44 - icon: '✅', 45 - title: 'Todo Reminder', 46 - message: nudge.text, 47 - action: `/app/todos/${nudge.day}`, 48 - facet: nudge.facet, 49 - autoDismiss: 30000, 50 - }); 51 - }, delay); 52 - this._nudgeTimers.push(timer); 53 - } 52 + if (delay > 0 && delay < 24 * 60 * 60 * 1000) { 53 + const timer = setTimeout(() => { 54 + AppServices.notifications.show({ 55 + app: 'todos', 56 + icon: '✅', 57 + title: 'Todo Reminder', 58 + message: nudge.text, 59 + action: `/app/todos/${nudge.day}`, 60 + facet: nudge.facet, 61 + autoDismiss: 30000, 62 + }); 63 + }, delay); 64 + this._nudgeTimers.push(timer); 54 65 } 55 - } catch (err) { 56 - console.error('[Todos] Failed to check nudges:', err); 57 66 } 58 67 }, 59 68