Add daily notification wakeups and a make watchapp packaging target
build / build (push) Successful in 20s
build / build (push) Successful in 20s
Schedules a one-shot Pebble wakeup for the configured notification time, re-arming it on every launch and config change, and vibrates/ refreshes the report when it fires (foreground or fresh launch). Also adds a `make watchapp` target that builds the watchapp via the Pebble SDK and copies a versioned .pbw to dist/, matching `make package`'s version resolution — deliberately not wired into CI, which has no Pebble SDK installed.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -4,6 +4,7 @@
|
||||
#include "app_message.h"
|
||||
#include "config.h"
|
||||
#include "i18n_tables.h"
|
||||
#include "notify.h"
|
||||
#include "reading_state.h"
|
||||
#include "ui_report_window.h"
|
||||
#include "ui_text_window.h"
|
||||
@@ -26,6 +27,7 @@ static void on_config_updated(const WatchConfig *cfg) {
|
||||
|
||||
config_log(&s_config); /* the values this newly-recomputed reading is based on */
|
||||
reading_state_recompute(&s_config.birth, s_config.gender);
|
||||
notify_reschedule(&s_config); /* settings may have changed notify_enabled/hour/minute */
|
||||
if (was_configured) {
|
||||
report_window_reload();
|
||||
} else {
|
||||
@@ -33,16 +35,36 @@ static void on_config_updated(const WatchConfig *cfg) {
|
||||
}
|
||||
}
|
||||
|
||||
/* Fires only if the scheduled wakeup goes off while this app is already
|
||||
* open (notify_was_wakeup_launch() below covers the far more common
|
||||
* case: the wakeup launching the app fresh). Refreshes the same way a
|
||||
* new day's config submission would, since the report window is already
|
||||
* on screen and the reading may now be for a new day. */
|
||||
static void on_wakeup(WakeupId wakeup_id, int32_t cookie) {
|
||||
(void)wakeup_id;
|
||||
(void)cookie;
|
||||
vibes_double_pulse();
|
||||
if (!s_config.configured) return;
|
||||
reading_state_recompute(&s_config.birth, s_config.gender);
|
||||
report_window_reload();
|
||||
notify_reschedule(&s_config); /* wakeup_schedule() is one-shot - re-arm for tomorrow */
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
config_load(&s_config);
|
||||
watch_i18n_load(s_config.lang);
|
||||
app_message_init(on_config_updated);
|
||||
notify_subscribe(on_wakeup);
|
||||
|
||||
config_log(&s_config); /* the values this session's reading (if any) is based on */
|
||||
|
||||
if (s_config.configured) {
|
||||
reading_state_recompute(&s_config.birth, s_config.gender);
|
||||
report_window_push();
|
||||
notify_reschedule(&s_config); /* wakeup_schedule() is one-shot - re-arm on every launch */
|
||||
if (notify_was_wakeup_launch()) {
|
||||
vibes_double_pulse();
|
||||
}
|
||||
} else {
|
||||
show_setup_required();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#include "notify.h"
|
||||
|
||||
/* Only one kind of wakeup event exists in this app, so the cookie value
|
||||
* itself carries no information - it exists only because
|
||||
* wakeup_schedule()/wakeup_get_launch_event() require one. */
|
||||
#define NOTIFY_WAKEUP_COOKIE 0
|
||||
|
||||
void notify_reschedule(const WatchConfig *cfg) {
|
||||
wakeup_cancel_all();
|
||||
if (!cfg->notify_enabled) return;
|
||||
|
||||
time_t now = time(NULL);
|
||||
struct tm target_tm = *localtime(&now);
|
||||
target_tm.tm_hour = cfg->notify_hour;
|
||||
target_tm.tm_min = cfg->notify_minute;
|
||||
target_tm.tm_sec = 0;
|
||||
|
||||
time_t target = mktime(&target_tm);
|
||||
if (target <= now) target += SECONDS_PER_DAY; /* today's time already passed */
|
||||
|
||||
WakeupId id = wakeup_schedule(target, NOTIFY_WAKEUP_COOKIE, true);
|
||||
if (id < 0) {
|
||||
APP_LOG(APP_LOG_LEVEL_ERROR, "notify: wakeup_schedule failed: %d", (int)id);
|
||||
}
|
||||
}
|
||||
|
||||
bool notify_was_wakeup_launch(void) {
|
||||
return launch_reason() == APP_LAUNCH_WAKEUP;
|
||||
}
|
||||
|
||||
void notify_subscribe(WakeupHandler handler) {
|
||||
wakeup_service_subscribe(handler);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef WATCH_NOTIFY_H
|
||||
#define WATCH_NOTIFY_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
/* (Re)schedules the daily notification wakeup from `cfg`'s notify_*
|
||||
* fields: cancels any wakeup this app previously scheduled, then - if
|
||||
* cfg->notify_enabled - schedules a new one-shot wakeup_schedule() for
|
||||
* the next occurrence of notify_hour:notify_minute in the watch's own
|
||||
* local time (today if that time hasn't passed yet, tomorrow otherwise).
|
||||
* If !cfg->notify_enabled, this only cancels - no new wakeup is
|
||||
* scheduled.
|
||||
*
|
||||
* Safe to call any time, and needs to be: once per app launch (Pebble's
|
||||
* wakeup_schedule() is one-shot - each firing consumes itself, so the
|
||||
* next day's has to be scheduled again after it fires or after a wakeup
|
||||
* that arrives while the app happens to already be open - see
|
||||
* notify_subscribe()) and on every config submission (settings may have
|
||||
* changed notify_enabled/notify_hour/notify_minute). */
|
||||
void notify_reschedule(const WatchConfig *cfg);
|
||||
|
||||
/* True if this app launch was triggered by the daily notification wakeup
|
||||
* firing rather than the user/phone opening it normally - main.c uses
|
||||
* this to vibrate on launch, since the report window it pushes either
|
||||
* way already leads with day significance and the top transit (the
|
||||
* "quick digest" this notification promises), so no separate screen is
|
||||
* needed for it. */
|
||||
bool notify_was_wakeup_launch(void);
|
||||
|
||||
/* Subscribes `handler` to fire if the scheduled wakeup goes off while
|
||||
* this app is already running in the foreground - the only case
|
||||
* notify_was_wakeup_launch() can't see, since no fresh launch happens
|
||||
* then (see wakeup_service_subscribe()'s own doc comment in pebble.h).
|
||||
* Call once, early in main(). */
|
||||
void notify_subscribe(WakeupHandler handler);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user