mirror of
https://github.com/CamHenlin/MessagesForMacintosh.git
synced 2025-02-20 03:29:02 +00:00
get new message notifications working
This commit is contained in:
parent
1fd61a8e46
commit
db302f0b97
@ -457,6 +457,8 @@ class iMessageClient {
|
|||||||
|
|
||||||
async getChatCounts () {
|
async getChatCounts () {
|
||||||
|
|
||||||
|
console.log(`getChatCounts`)
|
||||||
|
|
||||||
if (TEST_MODE) {
|
if (TEST_MODE) {
|
||||||
|
|
||||||
return parseChatsToFriendlyNameString(TEST_CHATS)
|
return parseChatsToFriendlyNameString(TEST_CHATS)
|
||||||
@ -487,6 +489,8 @@ class iMessageClient {
|
|||||||
|
|
||||||
let chats = result.data.getChatCounts
|
let chats = result.data.getChatCounts
|
||||||
|
|
||||||
|
console.log(`got chat counts`)
|
||||||
|
|
||||||
if (!chats) {
|
if (!chats) {
|
||||||
|
|
||||||
return ``
|
return ``
|
||||||
@ -507,6 +511,7 @@ class iMessageClient {
|
|||||||
// remove trailing comma
|
// remove trailing comma
|
||||||
friendlyNameStrings = friendlyNameStrings.substring(1, friendlyNameStrings.length)
|
friendlyNameStrings = friendlyNameStrings.substring(1, friendlyNameStrings.length)
|
||||||
|
|
||||||
|
console.log(friendlyNameStrings)
|
||||||
return friendlyNameStrings
|
return friendlyNameStrings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ void EventLoop(struct nk_context *ctx)
|
|||||||
// PROFILE_START("eventloop");
|
// PROFILE_START("eventloop");
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
if (gotKeyboardEvent && TickCount() > gotKeyboardEventTime + 80) {
|
if (gotKeyboardEvent && TickCount() > gotKeyboardEventTime + 20) {
|
||||||
|
|
||||||
gotKeyboardEvent = false;
|
gotKeyboardEvent = false;
|
||||||
ShowCursor();
|
ShowCursor();
|
||||||
@ -224,7 +224,7 @@ void EventLoop(struct nk_context *ctx)
|
|||||||
if (chatFriendlyNamesCounter > 0) {
|
if (chatFriendlyNamesCounter > 0) {
|
||||||
|
|
||||||
// writeSerialPortDebug(boutRefNum, "check chat counts");
|
// writeSerialPortDebug(boutRefNum, "check chat counts");
|
||||||
getChatCounts(activeChat);
|
getChatCounts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ void EventLoop(struct nk_context *ctx)
|
|||||||
SystemTask();
|
SystemTask();
|
||||||
|
|
||||||
// only re-render if there is an event, prevents screen flickering, speeds up app
|
// only re-render if there is an event, prevents screen flickering, speeds up app
|
||||||
if (beganInput || firstOrMouseMove) {
|
if (beganInput || firstOrMouseMove || forceRedraw) { // forceRedraw is from nuklear_app
|
||||||
|
|
||||||
#ifdef PROFILING
|
#ifdef PROFILING
|
||||||
PROFILE_START("nk_input_end");
|
PROFILE_START("nk_input_end");
|
||||||
@ -454,9 +454,10 @@ void DoEvent(EventRecord *event, struct nk_context *ctx) {
|
|||||||
|
|
||||||
HideCursor();
|
HideCursor();
|
||||||
gotKeyboardEvent = true;
|
gotKeyboardEvent = true;
|
||||||
gotKeyboardEventTime = TickCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gotKeyboardEventTime = TickCount();
|
||||||
|
|
||||||
#ifdef MAC_APP_DEBUGGING
|
#ifdef MAC_APP_DEBUGGING
|
||||||
writeSerialPortDebug(boutRefNum, "key");
|
writeSerialPortDebug(boutRefNum, "key");
|
||||||
#endif
|
#endif
|
||||||
|
124
nuklear_app.c
124
nuklear_app.c
@ -1,6 +1,5 @@
|
|||||||
// TODO:
|
// TODO:
|
||||||
// - IN PROGRESS new message window -- needs to blank out messages, then needs fixes on new mac end -- this might work
|
// - IN PROGRESS new message window -- need to figure this out
|
||||||
// - IN PROGRESS get new messages in other chats and display some sort of alert
|
|
||||||
// - IN PROGRESS need timeout on serial messages in case the computer at the other end dies (prevent hard reset) -- probably possible in coprocessorjs library. made an attempt, needs tested
|
// - IN PROGRESS need timeout on serial messages in case the computer at the other end dies (prevent hard reset) -- probably possible in coprocessorjs library. made an attempt, needs tested
|
||||||
|
|
||||||
#define WINDOW_WIDTH 510
|
#define WINDOW_WIDTH 510
|
||||||
@ -17,6 +16,8 @@
|
|||||||
#define NK_MEMSET memset
|
#define NK_MEMSET memset
|
||||||
#define NK_MEMCPY memcpy
|
#define NK_MEMCPY memcpy
|
||||||
|
|
||||||
|
// #define MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
|
||||||
void aFailed(char *file, int line) {
|
void aFailed(char *file, int line) {
|
||||||
|
|
||||||
MoveTo(10, 10);
|
MoveTo(10, 10);
|
||||||
@ -53,7 +54,6 @@ char new_message_input_buffer[255];
|
|||||||
int activeMessageCounter = 0;
|
int activeMessageCounter = 0;
|
||||||
int chatFriendlyNamesCounter = 0;
|
int chatFriendlyNamesCounter = 0;
|
||||||
int coprocessorLoaded = 0;
|
int coprocessorLoaded = 0;
|
||||||
int drawChatsOneMoreTime = 2; // this is how many 'iterations' of the UI that we need to see every element for
|
|
||||||
int forceRedraw = 2; // this is how many 'iterations' of the UI that we need to see every element for
|
int forceRedraw = 2; // this is how many 'iterations' of the UI that we need to see every element for
|
||||||
int haveRun = 0;
|
int haveRun = 0;
|
||||||
int ipAddressSet = 0;
|
int ipAddressSet = 0;
|
||||||
@ -81,18 +81,12 @@ void getMessagesFromjsFunctionResponse() {
|
|||||||
|
|
||||||
activeMessageCounter = 0;
|
activeMessageCounter = 0;
|
||||||
|
|
||||||
// writeSerialPortDebug(boutRefNum, "BEGIN");
|
|
||||||
|
|
||||||
// writeSerialPortDebug(boutRefNum, jsFunctionResponse);
|
|
||||||
char *token = (char *)strtokm(jsFunctionResponse, "ENDLASTMESSAGE");
|
char *token = (char *)strtokm(jsFunctionResponse, "ENDLASTMESSAGE");
|
||||||
|
|
||||||
// loop through the string to extract all other tokens
|
// loop through the string to extract all other tokens
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
|
|
||||||
// writeSerialPortDebug(boutRefNum, "LOAD VALUE TO TOKEN");
|
|
||||||
// writeSerialPortDebug(boutRefNum, token);
|
|
||||||
sprintf(activeChatMessages[activeMessageCounter], "%s", token);
|
sprintf(activeChatMessages[activeMessageCounter], "%s", token);
|
||||||
// writeSerialPortDebug(boutRefNum, activeChatMessages[activeMessageCounter]);
|
|
||||||
// writeSerialPortDebug(boutRefNum, "DONE! LOAD VALUE TO TOKEN");
|
|
||||||
token = (char *)strtokm(NULL, "ENDLASTMESSAGE");
|
token = (char *)strtokm(NULL, "ENDLASTMESSAGE");
|
||||||
activeMessageCounter++;
|
activeMessageCounter++;
|
||||||
}
|
}
|
||||||
@ -150,6 +144,11 @@ void getMessages(char *thread, int page) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from https://stackoverflow.com/a/4770992
|
||||||
|
Boolean prefix(const char *pre, const char *str) {
|
||||||
|
return strncmp(pre, str, strlen(pre)) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
void getChatCounts() {
|
void getChatCounts() {
|
||||||
|
|
||||||
char output[62];
|
char output[62];
|
||||||
@ -157,45 +156,80 @@ void getChatCounts() {
|
|||||||
// writeSerialPortDebug(boutRefNum, output);
|
// writeSerialPortDebug(boutRefNum, output);
|
||||||
|
|
||||||
callFunctionOnCoprocessor("getChatCounts", output, chatCountFunctionResponse);
|
callFunctionOnCoprocessor("getChatCounts", output, chatCountFunctionResponse);
|
||||||
// writeSerialPortDebug(boutRefNum, jsFunctionResponse);
|
|
||||||
|
|
||||||
if (!strcmp(chatCountFunctionResponse, previousChatCountFunctionResponse)) {
|
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
writeSerialPortDebug(boutRefNum, "getChatCounts");
|
||||||
writeSerialPortDebug(boutRefNum, "update current chat count");
|
|
||||||
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
|
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (strcmp(chatCountFunctionResponse, previousChatCountFunctionResponse)) {
|
||||||
|
|
||||||
|
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
writeSerialPortDebug(boutRefNum, "update current chat count");
|
||||||
|
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
|
||||||
|
#endif
|
||||||
|
|
||||||
SysBeep(1);
|
SysBeep(1);
|
||||||
char *token = (char *)strtok(chatCountFunctionResponse, ",");
|
char **saveptr;
|
||||||
|
char *token = strtok_r(chatCountFunctionResponse, ",", saveptr);
|
||||||
|
|
||||||
// loop through the string to extract all other tokens
|
// loop through the string to extract all other tokens
|
||||||
while (token != NULL) {
|
while (token != NULL) {
|
||||||
writeSerialPortDebug(boutRefNum, "update current chat count loop");
|
|
||||||
writeSerialPortDebug(boutRefNum, token);
|
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
writeSerialPortDebug(boutRefNum, "update current chat count loop");
|
||||||
|
writeSerialPortDebug(boutRefNum, token);
|
||||||
|
#endif
|
||||||
// should be in format NAME:::COUNT
|
// should be in format NAME:::COUNT
|
||||||
|
|
||||||
char *name = strtok(token, ":::");
|
char **saveptr2;
|
||||||
short count = atoi(strtok(NULL, " "));
|
char *name = strtok_r(token, ":::", saveptr2);
|
||||||
|
char *countString = strtok_r(NULL, ":::", saveptr2);
|
||||||
|
short count = atoi(countString);
|
||||||
|
|
||||||
|
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
char x[255];
|
||||||
|
sprintf(x, "name: %s, countString: %s, count: %d", name, countString, count);
|
||||||
|
writeSerialPortDebug(boutRefNum, x);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
|
||||||
|
token = strtok_r(NULL, ",", saveptr);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < chatFriendlyNamesCounter; i++) {
|
for (int i = 0; i < chatFriendlyNamesCounter; i++) {
|
||||||
|
|
||||||
if (strstr(chatFriendlyNames[i], " new) ")) {
|
if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
|
||||||
|
|
||||||
char *tempChatFriendlyName;
|
char chatName[64];
|
||||||
strtok(chatFriendlyNames[i], " new) ");
|
sprintf(chatName, "%s", chatFriendlyNames[i]);
|
||||||
tempChatFriendlyName = strtok(NULL, " ");
|
|
||||||
|
|
||||||
if (strcmp(tempChatFriendlyName, name)) {
|
// we are throwing out the first token
|
||||||
|
strtok_r(chatName, " new) ", saveptr2);
|
||||||
|
|
||||||
|
char *tempChatFriendlyName = strtok_r(NULL, " new) ", saveptr2);
|
||||||
|
|
||||||
|
if (prefix(tempChatFriendlyName, name)) {
|
||||||
|
|
||||||
|
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
writeSerialPortDebug(boutRefNum, "match1");
|
||||||
|
writeSerialPortDebug(boutRefNum, name);
|
||||||
|
#endif
|
||||||
|
|
||||||
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
|
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (strcmp(chatFriendlyNames[i], name)) {
|
if (prefix(chatFriendlyNames[i], name)) {
|
||||||
|
|
||||||
|
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
|
||||||
|
writeSerialPortDebug(boutRefNum, "match2");
|
||||||
|
writeSerialPortDebug(boutRefNum, name);
|
||||||
|
#endif
|
||||||
|
|
||||||
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
|
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
|
||||||
break;
|
break;
|
||||||
@ -203,10 +237,14 @@ void getChatCounts() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
token = (char *)strtokm(NULL, ",");
|
token = strtok_r(NULL, ",", saveptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
|
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
|
||||||
|
forceRedraw = 3;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
writeSerialPortDebug(boutRefNum, "no need to update current chat count");
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -380,11 +418,11 @@ static void nuklearApp(struct nk_context *ctx) {
|
|||||||
|
|
||||||
chatWindowCollision = checkCollision(chats_window_size);
|
chatWindowCollision = checkCollision(chats_window_size);
|
||||||
|
|
||||||
if ((chatWindowCollision || forceRedraw || drawChatsOneMoreTime) && nk_begin(ctx, "Chats", chats_window_size, NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
|
if ((chatWindowCollision || forceRedraw) && nk_begin(ctx, "Chats", chats_window_size, NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
|
||||||
|
|
||||||
if (chatWindowCollision) {
|
if (chatWindowCollision) {
|
||||||
|
|
||||||
drawChatsOneMoreTime = 2;
|
forceRedraw = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
getChats();
|
getChats();
|
||||||
@ -403,7 +441,23 @@ static void nuklearApp(struct nk_context *ctx) {
|
|||||||
|
|
||||||
if (nk_button_label(ctx, chatFriendlyNames[i])) {
|
if (nk_button_label(ctx, chatFriendlyNames[i])) {
|
||||||
|
|
||||||
sprintf(activeChat, "%s", chatFriendlyNames[i]);
|
if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
|
||||||
|
|
||||||
|
char chatName[96];
|
||||||
|
sprintf(chatName, "%s", chatFriendlyNames[i]);
|
||||||
|
writeSerialPortDebug(boutRefNum, chatName);
|
||||||
|
|
||||||
|
// we are throwing out the first token
|
||||||
|
strtokm(chatName, " new) ");
|
||||||
|
char *name = strtokm(NULL, " new) ");
|
||||||
|
|
||||||
|
writeSerialPortDebug(boutRefNum, name);
|
||||||
|
sprintf(activeChat, "%s", name);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
sprintf(activeChat, "%s", chatFriendlyNames[i]);
|
||||||
|
}
|
||||||
|
|
||||||
getMessages(activeChat, 0);
|
getMessages(activeChat, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,7 +467,6 @@ static void nuklearApp(struct nk_context *ctx) {
|
|||||||
nk_end(ctx);
|
nk_end(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (nk_begin(ctx, "Message Input", message_input_window_size, NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
|
if (nk_begin(ctx, "Message Input", message_input_window_size, NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
|
||||||
|
|
||||||
// bottom text input
|
// bottom text input
|
||||||
@ -434,7 +487,7 @@ static void nuklearApp(struct nk_context *ctx) {
|
|||||||
nk_end(ctx);
|
nk_end(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((forceRedraw || drawChatsOneMoreTime) && nk_begin_titled(ctx, "Message", activeChat, messages_window_size, NK_WINDOW_BORDER|NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR)) {
|
if ((forceRedraw) && nk_begin_titled(ctx, "Message", activeChat, messages_window_size, NK_WINDOW_BORDER|NK_WINDOW_TITLE|NK_WINDOW_NO_SCROLLBAR)) {
|
||||||
|
|
||||||
nk_layout_row_begin(ctx, NK_STATIC, 12, 1);
|
nk_layout_row_begin(ctx, NK_STATIC, 12, 1);
|
||||||
{
|
{
|
||||||
@ -453,12 +506,7 @@ static void nuklearApp(struct nk_context *ctx) {
|
|||||||
|
|
||||||
if (forceRedraw) {
|
if (forceRedraw) {
|
||||||
|
|
||||||
forceRedraw = 0;
|
forceRedraw--;
|
||||||
}
|
|
||||||
|
|
||||||
if (drawChatsOneMoreTime) {
|
|
||||||
|
|
||||||
drawChatsOneMoreTime = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,6 +529,8 @@ void refreshNuklearApp(Boolean blankInput) {
|
|||||||
struct nk_context* initializeNuklearApp() {
|
struct nk_context* initializeNuklearApp() {
|
||||||
|
|
||||||
sprintf(activeChat, "no active chat");
|
sprintf(activeChat, "no active chat");
|
||||||
|
memset(&chatCountFunctionResponse, '\0', 102400);
|
||||||
|
memset(&previousChatCountFunctionResponse, '\0', 102400);
|
||||||
|
|
||||||
graphql_input_window_size = nk_rect(WINDOW_WIDTH / 2 - 118, 80, 234, 100);
|
graphql_input_window_size = nk_rect(WINDOW_WIDTH / 2 - 118, 80, 234, 100);
|
||||||
chats_window_size = nk_rect(0, 0, 180, WINDOW_HEIGHT);
|
chats_window_size = nk_rect(0, 0, 180, WINDOW_HEIGHT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user