palm-client: check for messages while closed (alarm every 5-60 min, Preferences > Check when closed)
The alarm launch sublaunches the app with globals to connect without the channel/contact refresh, sync queued messages and play the sound; new messages keep the alarm for display, which shows an alert with Open. Untested on the device.
This commit is contained in:
1 parent
2eda7e1212
commit
531697479c
10 files changed
+289
-12
No files matched your search
@@ -10,7 +10,7 @@ APP = visormesh
|
||||
NAME = VisorMesh
|
||||
CREATOR = VMsh
|
||||
|
||||
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c
|
||||
SRCS = src/main.c src/app.c src/home_form.c src/convo_form.c src/node_form.c src/channel_form.c src/convos.c src/protocol.c src/sha256.c src/transport_srm.c src/transport_sb.c src/sb_spi.c src/session.c src/settings.c src/presets.c src/contacts.c src/contacts_form.c src/contact_form.c src/heard.c src/remote_fmt.c src/remote.c src/remote_form.c src/messages.c src/channels.c src/preview_form.c src/ui/draw.c src/ui/text.c src/ui/rowlist.c src/ui/fontmetrics.c src/ports.c src/sounds.c src/mutes.c src/scopes.c src/scope_proto.c src/map_geo.c src/map_form.c src/ui/emoji.c src/bgcheck.c
|
||||
OBJS = $(SRCS:src/%.c=build/%.o)
|
||||
|
||||
CC = m68k-palmos-gcc
|
||||
|
||||
@@ -277,16 +277,20 @@ BEGIN
|
||||
LABEL "Text size:" AUTOID AT (5 18) FONT 1
|
||||
PUSHBUTTON "Small" ID SoundsSmallPush AT (60 17 36 12) GROUP SoundsTextGroup
|
||||
PUSHBUTTON "Large" ID SoundsLargePush AT (PREVRIGHT+1 PREVTOP 36 12) GROUP SoundsTextGroup
|
||||
CHECKBOX "Direct messages" ID 2201 AT (5 35 AUTO 12)
|
||||
CHECKBOX "Mentions of me" ID 2202 AT (5 PREVBOTTOM AUTO 12)
|
||||
CHECKBOX "Room posts" ID 2203 AT (5 PREVBOTTOM AUTO 12)
|
||||
CHECKBOX "Private channels" ID 2204 AT (5 PREVBOTTOM AUTO 12)
|
||||
CHECKBOX "Hashtag channels" ID 2205 AT (5 PREVBOTTOM AUTO 12)
|
||||
CHECKBOX "Public channel" ID 2206 AT (5 PREVBOTTOM AUTO 12)
|
||||
CHECKBOX "New contacts" ID 2207 AT (5 PREVBOTTOM AUTO 12)
|
||||
LABEL "Turning a sound on plays it." AUTOID AT (5 PREVBOTTOM+2)
|
||||
CHECKBOX "Direct messages" ID 2201 AT (5 30 AUTO 11)
|
||||
CHECKBOX "Mentions of me" ID 2202 AT (5 PREVBOTTOM AUTO 11)
|
||||
CHECKBOX "Room posts" ID 2203 AT (5 PREVBOTTOM AUTO 11)
|
||||
CHECKBOX "Private channels" ID 2204 AT (5 PREVBOTTOM AUTO 11)
|
||||
CHECKBOX "Hashtag channels" ID 2205 AT (5 PREVBOTTOM AUTO 11)
|
||||
CHECKBOX "Public channel" ID 2206 AT (5 PREVBOTTOM AUTO 11)
|
||||
CHECKBOX "New contacts" ID 2207 AT (5 PREVBOTTOM AUTO 11)
|
||||
LABEL "Turning a sound on plays it." AUTOID AT (5 PREVBOTTOM+1)
|
||||
LABEL "Volume: Prefs, General, Alarm" AUTOID AT (5 PREVBOTTOM)
|
||||
BUTTON "Done" ID SoundsDoneButton AT (CENTER 145 AUTO AUTO)
|
||||
LABEL "Check when closed:" AUTOID AT (5 132) FONT 1
|
||||
POPUPTRIGGER "Off" ID SoundsCheckTrigger AT (95 131 AUTO AUTO) LEFTANCHOR
|
||||
LIST "Off" "Every 5 min" "Every 15 min" "Every 30 min" "Every hour" ID SoundsCheckList AT (90 90 66 AUTO) NONUSABLE VISIBLEITEMS 5
|
||||
POPUPLIST ID SoundsCheckTrigger SoundsCheckList
|
||||
BUTTON "Done" ID SoundsDoneButton AT (CENTER 147 AUTO AUTO)
|
||||
END
|
||||
|
||||
/* Flood scopes: the list, and the radio's default */
|
||||
@@ -349,6 +353,14 @@ BEGIN
|
||||
BUTTONS "OK"
|
||||
END
|
||||
|
||||
ALERT ID BgNewAlert
|
||||
INFORMATION
|
||||
BEGIN
|
||||
TITLE "New on the Mesh"
|
||||
MESSAGE "^1"
|
||||
BUTTONS "Open" "Later"
|
||||
END
|
||||
|
||||
ALERT ID MuteAlert
|
||||
INFORMATION
|
||||
BEGIN
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
#include <PalmOS.h>
|
||||
#include "app.h"
|
||||
#include "session.h"
|
||||
#include "sounds.h"
|
||||
#include "contacts.h"
|
||||
#include "channels.h"
|
||||
#include "messages.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_BG_SYNC_ROUNDS 4 /* SessionSyncMessages takes up to VM_SYNC_MAX per round */
|
||||
|
||||
typedef struct {
|
||||
UInt16 version;
|
||||
UInt16 minutes;
|
||||
} BgPrefs;
|
||||
|
||||
/* Everything up to BgCheckRun runs in launches without globals: no globals, no extra segments. */
|
||||
|
||||
UInt16 BgInterval(void)
|
||||
{
|
||||
BgPrefs prefs;
|
||||
UInt16 size = sizeof(prefs);
|
||||
|
||||
if (PrefGetAppPreferences(VM_CREATOR, VM_BG_PREFS_ID, &prefs, &size, true) != noPreferenceFound &&
|
||||
size == sizeof(prefs) && prefs.version == VM_BG_PREFS_VERSION)
|
||||
return prefs.minutes;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BgSetInterval(UInt16 minutes)
|
||||
{
|
||||
BgPrefs prefs;
|
||||
|
||||
prefs.version = VM_BG_PREFS_VERSION;
|
||||
prefs.minutes = minutes;
|
||||
PrefSetAppPreferences(VM_CREATOR, VM_BG_PREFS_ID, VM_BG_PREFS_VERSION, &prefs, sizeof(prefs), true);
|
||||
}
|
||||
|
||||
/* The app's own database: SysCurAppDatabase is whichever app is in front. */
|
||||
static Boolean FindSelf(UInt16 *card, LocalID *id)
|
||||
{
|
||||
DmSearchStateType state;
|
||||
|
||||
return DmGetNextDatabaseByTypeCreator(true, &state, sysFileTApplication, VM_CREATOR,
|
||||
true, card, id) == errNone;
|
||||
}
|
||||
|
||||
static void SetAlarm(UInt32 when)
|
||||
{
|
||||
UInt16 card;
|
||||
LocalID id;
|
||||
|
||||
if (FindSelf(&card, &id))
|
||||
AlmSetAlarm(card, id, 0, when, true);
|
||||
}
|
||||
|
||||
void BgSchedule(void)
|
||||
{
|
||||
UInt16 minutes = BgInterval();
|
||||
|
||||
SetAlarm(minutes ? TimGetSeconds() + (UInt32)minutes * 60 : 0);
|
||||
}
|
||||
|
||||
void BgCancel(void)
|
||||
{
|
||||
SetAlarm(0);
|
||||
}
|
||||
|
||||
void BgAlarmTriggered(SysAlarmTriggeredParamType *p)
|
||||
{
|
||||
UInt16 card, curCard;
|
||||
LocalID id, curId;
|
||||
UInt32 creator = 0, shown = 0, result;
|
||||
UInt16 kinds = 0;
|
||||
|
||||
p->purgeAlarm = true;
|
||||
if (!FindSelf(&card, &id))
|
||||
return;
|
||||
if (SysCurAppDatabase(&curCard, &curId) == errNone) {
|
||||
if (curId == id)
|
||||
return; /* the app is open; it sets the alarm again when it exits */
|
||||
DmDatabaseInfo(curCard, curId, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, &creator);
|
||||
}
|
||||
BgSchedule(); /* first, so a failed check doesn't end the chain */
|
||||
if (creator == sysFileCSync)
|
||||
return; /* HotSync has the USB port */
|
||||
if (SysAppLaunch(card, id, sysAppLaunchFlagNewGlobals, VM_LAUNCH_BGCHECK, &kinds, &result) != 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;
|
||||
LocalID id;
|
||||
UInt8 kind;
|
||||
Char text[VM_SND_COUNT * 17];
|
||||
|
||||
if (FtrGet(VM_CREATOR, VM_FTR_BG_KINDS, &kinds) != errNone || !kinds)
|
||||
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);
|
||||
if (FrmCustomAlert(BgNewAlert, text, "", "") == 0 && FindSelf(&card, &id))
|
||||
SysUIAppSwitch(card, id, sysAppLaunchCmdNormalLaunch, NULL);
|
||||
}
|
||||
|
||||
UInt16 BgCheckRun(void)
|
||||
{
|
||||
UInt16 kinds, n;
|
||||
|
||||
AppLoadPrefs();
|
||||
if (SessionConnectLight() == errNone) {
|
||||
for (n = 0; n < VM_BG_SYNC_ROUNDS && SessionMessageWaiting(); n++)
|
||||
SessionSyncMessages();
|
||||
SessionDisconnect();
|
||||
}
|
||||
kinds = SessionTakeSounds() & SoundsEnabledKinds();
|
||||
SoundsNotify(kinds, NULL);
|
||||
ContactsClose();
|
||||
ChannelsClose();
|
||||
MessagesClose();
|
||||
return kinds;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Checking for messages while the app is closed (Preferences > Check when
|
||||
* closed). The Alarm Manager launches the app every few minutes. That launch
|
||||
* has no globals (the app's other code segments aren't loaded either), so
|
||||
* 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.
|
||||
*
|
||||
* While the app is open it checks for itself: the alarm is cleared at launch
|
||||
* and set again at exit.
|
||||
*/
|
||||
#ifndef VM_BGCHECK_H
|
||||
#define VM_BGCHECK_H
|
||||
|
||||
#include <PalmOS.h>
|
||||
#include "sections.h"
|
||||
|
||||
#define VM_LAUNCH_BGCHECK sysAppLaunchCmdCustomBase /* cmdPBP: UInt16 *, gets the sound kinds */
|
||||
|
||||
/* Minutes between checks; 0 = off. */
|
||||
UInt16 BgInterval(void);
|
||||
void BgSetInterval(UInt16 minutes);
|
||||
|
||||
/* Sets the next alarm from the interval (clears it when off). */
|
||||
void BgSchedule(void);
|
||||
void BgCancel(void);
|
||||
|
||||
/* Launch codes; no globals needed. */
|
||||
void BgAlarmTriggered(SysAlarmTriggeredParamType *p);
|
||||
void BgDisplayAlarm(void);
|
||||
|
||||
/* The VM_LAUNCH_BGCHECK work, with globals: returns the enabled sound kinds (1 << VM_SND_*) found. */
|
||||
UInt16 BgCheckRun(void) VM_SECT4;
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "ports.h"
|
||||
#include "preview_form.h"
|
||||
#include "channel_form.h"
|
||||
#include "bgcheck.h"
|
||||
#include "ui/draw.h"
|
||||
|
||||
#define VM_MIN_ROM_VERSION sysMakeROMVersion(3, 5, 0, sysROMStageRelease, 0)
|
||||
@@ -170,7 +171,26 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
|
||||
|
||||
if (err != errNone)
|
||||
return err;
|
||||
switch (cmd) {
|
||||
case sysAppLaunchCmdAlarmTriggered:
|
||||
BgAlarmTriggered((SysAlarmTriggeredParamType *)cmdPBP);
|
||||
return errNone;
|
||||
case sysAppLaunchCmdDisplayAlarm:
|
||||
BgDisplayAlarm();
|
||||
return errNone;
|
||||
case VM_LAUNCH_BGCHECK:
|
||||
/* only with the globals BgAlarmTriggered launches it with */
|
||||
if (launchFlags & sysAppLaunchFlagNewGlobals)
|
||||
*(UInt16 *)cmdPBP = BgCheckRun();
|
||||
return errNone;
|
||||
case sysAppLaunchCmdSystemReset:
|
||||
case sysAppLaunchCmdSyncNotify: /* installed, which drops the alarm */
|
||||
case sysAppLaunchCmdTimeChange:
|
||||
BgSchedule();
|
||||
return errNone;
|
||||
}
|
||||
if (cmd == sysAppLaunchCmdNormalLaunch) {
|
||||
BgCancel();
|
||||
AppLoadPrefs();
|
||||
UiFontInit(SoundsLargeText());
|
||||
HeardLoad();
|
||||
@@ -183,6 +203,7 @@ UInt32 PilotMain(UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
|
||||
ChannelsClose();
|
||||
MessagesClose();
|
||||
UiFontRelease();
|
||||
BgSchedule();
|
||||
}
|
||||
return errNone;
|
||||
}
|
||||
@@ -130,6 +130,9 @@
|
||||
#define SoundsSmallPush 2212
|
||||
#define SoundsLargePush 2213
|
||||
#define SoundsTextGroup 5
|
||||
#define SoundsCheckTrigger 2214
|
||||
#define SoundsCheckList 2215 /* items: kCheckMinutes (sounds.c) */
|
||||
#define BgNewAlert 2216
|
||||
|
||||
#define ScopesForm 2300
|
||||
#define ScopesDefaultLabel 2301
|
||||
|
||||
@@ -253,7 +253,8 @@ UInt32 SessionRadioTime(void)
|
||||
return gRadioTime ? gRadioTime + (TimGetSeconds() - gRadioTimeAt) : 0;
|
||||
}
|
||||
|
||||
Err SessionConnect(void)
|
||||
/* Opens the link and runs DEVICE_QUERY + APP_START; on error the link is closed. */
|
||||
static Err OpenAndQuery(void)
|
||||
{
|
||||
Err err;
|
||||
|
||||
@@ -276,7 +277,15 @@ Err SessionConnect(void)
|
||||
}
|
||||
gConnected = true;
|
||||
gScopeMode = VM_SCOPE_UNKNOWN;
|
||||
return errNone;
|
||||
}
|
||||
|
||||
Err SessionConnect(void)
|
||||
{
|
||||
Err err = OpenAndQuery();
|
||||
|
||||
if (err != errNone)
|
||||
return err;
|
||||
/* Best effort: the connection stands even if one of these fails; the stored copies stay. */
|
||||
SessionSyncClock();
|
||||
if (ChannelsRefresh(gDevice.maxChannels) == errNone)
|
||||
@@ -287,6 +296,15 @@ Err SessionConnect(void)
|
||||
return errNone;
|
||||
}
|
||||
|
||||
Err SessionConnectLight(void)
|
||||
{
|
||||
Err err = OpenAndQuery();
|
||||
|
||||
if (err == errNone)
|
||||
SessionSyncMessages();
|
||||
return err;
|
||||
}
|
||||
|
||||
Err SessionRefresh(void)
|
||||
{
|
||||
if (!gConnected)
|
||||
|
||||
@@ -25,6 +25,11 @@
|
||||
|
||||
/* Opens the link and runs DEVICE_QUERY + APP_START. On error the link is closed. */
|
||||
Err SessionConnect(void);
|
||||
/*
|
||||
* Like SessionConnect without refreshing the channels and contacts (the stored
|
||||
* copies are used): for the check while the app is closed.
|
||||
*/
|
||||
Err SessionConnectLight(void);
|
||||
void SessionDisconnect(void);
|
||||
Boolean SessionIsConnected(void);
|
||||
Boolean SessionMessageWaiting(void);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "app.h"
|
||||
#include "session.h"
|
||||
#include "sounds.h"
|
||||
#include "bgcheck.h"
|
||||
#include "ui/draw.h"
|
||||
|
||||
static void SavePrefs(void) VM_SECT3;
|
||||
@@ -40,6 +41,10 @@ static const UInt16 kTunes[VM_SND_COUNT][6] = {
|
||||
{ 2637, 60, 1976, 60, 1568, 80 }, /* new contact: falling three */
|
||||
};
|
||||
|
||||
/* The Check when closed list, in minutes (0 = off). */
|
||||
#define VM_CHECK_CHOICES 5
|
||||
static const UInt16 kCheckMinutes[VM_CHECK_CHOICES] = { 0, 5, 15, 30, 60 };
|
||||
|
||||
void SoundsLoad(void)
|
||||
{
|
||||
SoundsPrefs prefs;
|
||||
@@ -55,6 +60,11 @@ void SoundsLoad(void)
|
||||
gLargeText = text.large;
|
||||
}
|
||||
|
||||
UInt16 SoundsEnabledKinds(void)
|
||||
{
|
||||
return gEnabled;
|
||||
}
|
||||
|
||||
Boolean SoundsLargeText(void)
|
||||
{
|
||||
return gLargeText;
|
||||
@@ -117,7 +127,8 @@ void SoundsFormOpen(UInt16 returnForm)
|
||||
Boolean SoundsFormHandleEvent(EventType *event)
|
||||
{
|
||||
FormType *form = FrmGetActiveForm();
|
||||
UInt16 id;
|
||||
ListType *list;
|
||||
UInt16 id, i, minutes;
|
||||
UInt8 kind;
|
||||
|
||||
switch (event->eType) {
|
||||
@@ -126,8 +137,21 @@ Boolean SoundsFormHandleEvent(EventType *event)
|
||||
FrmSetControlValue(form, FrmGetObjectIndex(form, SoundsFirstCheck + kind),
|
||||
(gEnabled & (1 << kind)) != 0);
|
||||
FrmSetControlGroupSelection(form, SoundsTextGroup, gLargeText ? SoundsLargePush : SoundsSmallPush);
|
||||
list = FrmGetObjectPtr(form, FrmGetObjectIndex(form, SoundsCheckList));
|
||||
minutes = BgInterval();
|
||||
for (i = 0; i < VM_CHECK_CHOICES - 1 && kCheckMinutes[i] != minutes; i++)
|
||||
;
|
||||
LstSetSelection(list, i);
|
||||
CtlSetLabel(FrmGetObjectPtr(form, FrmGetObjectIndex(form, SoundsCheckTrigger)),
|
||||
LstGetSelectionText(list, i));
|
||||
FrmDrawForm(form);
|
||||
return true;
|
||||
case popSelectEvent:
|
||||
/* the alarm is set when the app exits; the trigger's label is set by the form */
|
||||
if (event->data.popSelect.controlID == SoundsCheckTrigger &&
|
||||
event->data.popSelect.selection < VM_CHECK_CHOICES)
|
||||
BgSetInterval(kCheckMinutes[event->data.popSelect.selection]);
|
||||
break;
|
||||
case ctlSelectEvent:
|
||||
id = event->data.ctlSelect.controlID;
|
||||
if (id == SoundsDoneButton) {
|
||||
|
||||
@@ -31,6 +31,9 @@ void SoundsPlay(UInt8 kind) VM_SECT3;
|
||||
*/
|
||||
void SoundsNotify(UInt16 kinds, const VmConv *onScreen) VM_SECT3;
|
||||
|
||||
/* The kinds turned on (1 << VM_SND_*). */
|
||||
UInt16 SoundsEnabledKinds(void) VM_SECT3;
|
||||
|
||||
/* Text size: the larger UI font (ui/draw.h). */
|
||||
Boolean SoundsLargeText(void) VM_SECT3;
|
||||
|
||||
|
||||
Reference in new issue
Block a user