diff --git a/palm-client/resources/icon/large1.bmp b/palm-client/resources/icon/large1.bmp index 6d00430..110c1dc 100644 Binary files a/palm-client/resources/icon/large1.bmp and b/palm-client/resources/icon/large1.bmp differ diff --git a/palm-client/resources/icon/large4.bmp b/palm-client/resources/icon/large4.bmp index 394af78..da9988b 100644 Binary files a/palm-client/resources/icon/large4.bmp and b/palm-client/resources/icon/large4.bmp differ diff --git a/palm-client/resources/icon/large8.bmp b/palm-client/resources/icon/large8.bmp index 1940e1c..57b84df 100644 Binary files a/palm-client/resources/icon/large8.bmp and b/palm-client/resources/icon/large8.bmp differ diff --git a/palm-client/resources/icon/small1.bmp b/palm-client/resources/icon/small1.bmp index b592db9..e415f95 100644 Binary files a/palm-client/resources/icon/small1.bmp and b/palm-client/resources/icon/small1.bmp differ diff --git a/palm-client/resources/icon/small4.bmp b/palm-client/resources/icon/small4.bmp index 7448bc0..4d9f193 100644 Binary files a/palm-client/resources/icon/small4.bmp and b/palm-client/resources/icon/small4.bmp differ diff --git a/palm-client/resources/icon/small8.bmp b/palm-client/resources/icon/small8.bmp index eef5ab5..aa6187d 100644 Binary files a/palm-client/resources/icon/small8.bmp and b/palm-client/resources/icon/small8.bmp differ diff --git a/palm-client/src/bgcheck.c b/palm-client/src/bgcheck.c index 9689100..e9d2f27 100644 --- a/palm-client/src/bgcheck.c +++ b/palm-client/src/bgcheck.c @@ -5,12 +5,13 @@ #include "contacts.h" #include "channels.h" #include "messages.h" +#include "mutes.h" +#include "convos.h" #include "resources.h" #include "bgcheck.h" #define VM_BG_PREFS_ID 6 #define VM_BG_PREFS_VERSION 1 -#define VM_FTR_BG_KINDS 0 /* feature: sound kinds found by checks, until shown */ #define VM_FTR_APP_OPEN 1 /* feature: set while the app runs normally */ #define VM_BG_SYNC_ROUNDS 4 /* SessionSyncMessages takes up to VM_SYNC_MAX per round */ @@ -35,6 +36,33 @@ typedef struct { UInt16 kinds; } BgStatus; +/* + * New messages found by checks, per conversation, until the alert shows them + * (unsaved prefs: the display launch has no globals). Names are looked up + * while the check has globals. + */ +#define VM_BG_PENDING_ID 7 +#define VM_BG_PENDING_VERSION 1 +#define VM_BG_PENDING_MAX 5 /* conversations listed; the rest count in 'more' */ +#define VM_BG_NAME_LEN 20 + +typedef struct { + VmConv conv; + UInt16 count; + Char name[VM_BG_NAME_LEN + 2]; /* even, to keep the entries aligned */ +} BgPendingConv; + +typedef struct { + UInt16 version; + UInt16 total; + UInt16 more; /* messages in conversations past VM_BG_PENDING_MAX */ + UInt16 n; + BgPendingConv convs[VM_BG_PENDING_MAX]; +} BgPending; + +static void CountConv(BgPending *pend, const VmConv *conv) VM_SECT4; +static void AddPending(UInt32 since) VM_SECT4; + /* Everything up to BgCheckRun runs in launches without globals: no globals, no extra segments. */ UInt16 BgInterval(void) @@ -87,6 +115,28 @@ static void WriteStatus(UInt16 stage, Err err, UInt16 kinds) PrefSetAppPreferences(VM_CREATOR, VM_BG_STATUS_ID, VM_BG_STATUS_VERSION, &st, sizeof(st), false); } +static Boolean LoadPending(BgPending *pend) +{ + UInt16 size = sizeof(*pend); + + return PrefGetAppPreferences(VM_CREATOR, VM_BG_PENDING_ID, pend, &size, false) != noPreferenceFound && + size == sizeof(*pend) && pend->version == VM_BG_PENDING_VERSION; +} + +static void SavePending(BgPending *pend) +{ + pend->version = VM_BG_PENDING_VERSION; + PrefSetAppPreferences(VM_CREATOR, VM_BG_PENDING_ID, VM_BG_PENDING_VERSION, pend, sizeof(*pend), false); +} + +static void ClearPending(void) +{ + BgPending pend; + + MemSet(&pend, sizeof(pend), 0); + SavePending(&pend); +} + void BgSchedule(void) { UInt16 minutes = BgInterval(); @@ -120,7 +170,7 @@ void BgAlarmTriggered(SysAlarmTriggeredParamType *p) { UInt16 card; LocalID id; - UInt32 open, shown = 0, result; + UInt32 open, result; UInt16 kinds = 0; Err err; @@ -136,57 +186,92 @@ void BgAlarmTriggered(SysAlarmTriggeredParamType *p) WriteStatus(VM_BG_LAUNCH_ERR, err, 0); if (err != errNone || !kinds) return; - FtrGet(VM_CREATOR, VM_FTR_BG_KINDS, &shown); - FtrSet(VM_CREATOR, VM_FTR_BG_KINDS, shown | kinds); p->purgeAlarm = false; /* the system sends sysAppLaunchCmdDisplayAlarm next */ } -/* One line per kind, in priority order. A switch, not a table: a pointer table needs globals. */ -static void AppendKind(Char *text, UInt8 kind) -{ - const Char *name; - - switch (kind) { - case VM_SND_DIRECT: name = "Direct message"; break; - case VM_SND_MENTION: name = "Mention of you"; break; - case VM_SND_ROOM: name = "Room post"; break; - case VM_SND_PRIVATE: name = "Private channel"; break; - case VM_SND_HASHTAG: name = "Hashtag channel"; break; - case VM_SND_PUBLIC: name = "Public channel"; break; - case VM_SND_CONTACT: name = "New contact"; break; - default: return; - } - if (text[0]) - StrCat(text, "\n"); - StrCat(text, name); -} - void BgDisplayAlarm(void) { - UInt32 kinds = 0; - UInt16 card; + BgPending pend; + UInt16 card, i; LocalID id; - UInt8 kind; - Char text[VM_SND_COUNT * 17]; + Char text[24 + VM_BG_PENDING_MAX * (VM_BG_NAME_LEN + 9) + 24]; - if (FtrGet(VM_CREATOR, VM_FTR_BG_KINDS, &kinds) != errNone || !kinds) + if (!LoadPending(&pend) || !pend.total) return; - FtrUnregister(VM_CREATOR, VM_FTR_BG_KINDS); - text[0] = 0; - for (kind = 0; kind < VM_SND_COUNT; kind++) - if (kinds & (1 << kind)) - AppendKind(text, kind); + ClearPending(); + StrIToA(text, pend.total); + StrCat(text, pend.total == 1 ? " new message" : " new messages"); + for (i = 0; i < pend.n; i++) { + StrCat(text, "\n"); + StrCat(text, pend.convs[i].name); + StrCat(text, ": "); + StrIToA(text + StrLen(text), pend.convs[i].count); + } + if (pend.more) { + StrCat(text, "\n"); + StrIToA(text + StrLen(text), pend.more); + StrCat(text, " more elsewhere"); + } if (FrmCustomAlert(BgNewAlert, text, "", "") == 0 && FindSelf(&card, &id)) SysUIAppSwitch(card, id, sysAppLaunchCmdNormalLaunch, NULL); } +/* ---- with globals (VM_LAUNCH_BGCHECK) ---- */ + +static void CountConv(BgPending *pend, const VmConv *conv) +{ + UInt16 i; + + pend->total++; + for (i = 0; i < pend->n; i++) + if (ConvEqual(&pend->convs[i].conv, conv)) { + pend->convs[i].count++; + return; + } + if (pend->n == VM_BG_PENDING_MAX) { + pend->more++; + return; + } + pend->convs[i].conv = *conv; + pend->convs[i].count = 1; + ConvName(conv, pend->convs[i].name, sizeof(pend->convs[i].name)); + pend->n++; +} + +/* Adds the messages received since 'since' (outside muted channels) to what the alert will list. */ +static void AddPending(UInt32 since) +{ + BgPending pend; + const VmMsgHeader *h; + VmChannel ch; + UInt16 i; + Boolean newer; + + if (!LoadPending(&pend)) + MemSet(&pend, sizeof(pend), 0); + for (i = MessagesCount(); i-- > 0; ) { + h = MessagesLock(i); + if (!h) + continue; + newer = h->received >= since; + if (newer && h->dir == VM_DIR_IN && + !(h->conv.type == VM_CONV_CHANNEL && ChannelsFindSlot(h->conv.channel, &ch) && ChannelMuted(&ch))) + CountConv(&pend, &h->conv); + MessagesRelease(i); + if (!newer) + break; /* records are in arrival order */ + } + SavePending(&pend); +} + UInt16 BgCheckRun(void) { UInt16 kinds, n; - + UInt32 start; Err err; AppLoadPrefs(); + start = SessionNow(); err = SessionConnectLight(); if (err == errNone) { for (n = 0; n < VM_BG_SYNC_ROUNDS && SessionMessageWaiting(); n++) @@ -195,6 +280,8 @@ UInt16 BgCheckRun(void) } kinds = SessionTakeSounds() & SoundsEnabledKinds(); SoundsNotify(kinds, NULL); + if (kinds) + AddPending(start); WriteStatus(err == errNone ? VM_BG_DONE : VM_BG_NO_RADIO, err, kinds); ContactsClose(); ChannelsClose(); diff --git a/palm-client/src/bgcheck.h b/palm-client/src/bgcheck.h index 2a9f7ea..f383e75 100644 --- a/palm-client/src/bgcheck.h +++ b/palm-client/src/bgcheck.h @@ -5,7 +5,8 @@ * BgAlarmTriggered sublaunches the app again with new globals * (VM_LAUNCH_BGCHECK). That launch connects, pulls what the radio queued, * and plays the notification sound. If anything new arrived, the alarm stays - * for display, and BgDisplayAlarm shows an alert with an Open button. + * for display, and BgDisplayAlarm shows an alert with the count per + * conversation and an Open button. * * While the app is open it checks for itself: the alarm keeps coming and is * skipped. diff --git a/palm-client/tools/make_icon.sh b/palm-client/tools/make_icon.sh index fd6ff85..2adff48 100755 --- a/palm-client/tools/make_icon.sh +++ b/palm-client/tools/make_icon.sh @@ -1,22 +1,25 @@ #!/bin/sh -# Renders the app icon BMPs in resources/icon/ from the SVG (needs rsvg-convert -# and ImageMagick: brew install librsvg imagemagick). The BMPs are committed, so +# Renders the app icon BMPs in resources/icon/ from an SVG or PNG (needs +# ImageMagick, and rsvg-convert for SVG: brew install librsvg imagemagick). The BMPs are committed, so # the build itself doesn't need these tools. # -# tools/make_icon.sh [icon.svg] +# tools/make_icon.sh [icon.svg|icon.png] # -# Large icon 32x22 and small (list view) 15x9, each at 1 bit (ordered dither), +# Large icon 32x22 and small (list view) 15x9, each at 1 bit (threshold 85%: keeps line art's thin strokes), # 4 bits (16 grays: the Visor Neo) and 8 bits (colour; pilrc maps it to the # Palm palette). White is transparent. set -e cd "$(dirname "$0")/.." -SVG="${1:-../meshcore-visor-hair.svg}" +SRC="${1:-../meshcore-visor-hair-1.png}" OUT=resources/icon TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT mkdir -p "$OUT" -rsvg-convert -w 512 -h 512 "$SVG" -o "$TMP/full.png" +case "$SRC" in +*.svg) rsvg-convert -w 512 -h 512 "$SRC" -o "$TMP/full.png" ;; +*) magick "$SRC" -background white -alpha remove "$TMP/full.png" ;; +esac magick "$TMP/full.png" -trim +repage "$TMP/trim.png" for spec in large:32x22 small:15x9; do @@ -24,7 +27,7 @@ for spec in large:32x22 small:15x9; do size=${spec#*:} magick "$TMP/trim.png" -resize "$size" -background white -gravity center -extent "$size" \ -alpha remove "$TMP/$name.png" - magick "$TMP/$name.png" -colorspace Gray -ordered-dither o2x2 -threshold 50% -type Bilevel -compress None "BMP3:$OUT/${name}1.bmp" + magick "$TMP/$name.png" -colorspace Gray -threshold 85% -type Bilevel -compress None "BMP3:$OUT/${name}1.bmp" magick "$TMP/$name.png" -colorspace Gray -dither None -colors 16 -type Palette -compress None "BMP3:$OUT/${name}4.bmp" magick "$TMP/$name.png" -dither None -colors 64 -type Palette -compress None "BMP3:$OUT/${name}8.bmp" done