small fixes

This commit is contained in:
camh 2022-01-06 22:09:39 -08:00
parent 1e205315c8
commit 36d047d485
6 changed files with 205 additions and 38 deletions

View File

@ -4,7 +4,7 @@ const InMemoryCache = require('apollo-cache-inmemory').InMemoryCache;
const createHttpLink = require('apollo-link-http').createHttpLink; const createHttpLink = require('apollo-link-http').createHttpLink;
const gql = require('graphql-tag') const gql = require('graphql-tag')
// TEST_MODE can be turned on or off to prevent communications with the Apollo iMessage Server running on your moder Mac // TEST_MODE can be turned on or off to prevent communications with the Apollo iMessage Server running on your modern Mac
const TEST_MODE = false const TEST_MODE = false
const defaultOptions = { const defaultOptions = {
@ -151,7 +151,7 @@ const widthFor12ptFont = [
8 8
] ]
// this is tied to Sample.c's message window max width // this is tied to mac_main.c's message window max width
const MAX_WIDTH = 304 const MAX_WIDTH = 304
const SPACE_WIDTH = widthFor12ptFont[32] const SPACE_WIDTH = widthFor12ptFont[32]
@ -291,9 +291,6 @@ const parseChatsToFriendlyNameString = (chats) => {
friendlyNameStrings = friendlyNameStrings.substring(1, friendlyNameStrings.length) friendlyNameStrings = friendlyNameStrings.substring(1, friendlyNameStrings.length)
console.log(`chats`)
console.log(friendlyNameStrings)
return friendlyNameStrings return friendlyNameStrings
} }
@ -392,10 +389,6 @@ class iMessageClient {
return splitMessages(TEST_MESSAGES) return splitMessages(TEST_MESSAGES)
} }
console.log(`send message`)
console.log(chatId)
console.log(message)
let result let result
try { try {
@ -459,6 +452,61 @@ class iMessageClient {
return parseChatsToFriendlyNameString(chats) return parseChatsToFriendlyNameString(chats)
} }
async getChatCounts () {
if (TEST_MODE) {
return parseChatsToFriendlyNameString(TEST_CHATS)
}
let result
try {
result = await client.query({
query: gql`query getChatCounts {
getChatCounts {
friendlyName
count
}
}`
})
} catch (error) {
console.log(`error with apollo query`)
console.log(error)
result = {
data: {
}
}
}
let chats = result.data.getChatCounts
if (!chats) {
return ``
}
let friendlyNameStrings = ``
if (chats.length === 0) {
return ``
}
for (let chat of chats) {
friendlyNameStrings = `${friendlyNameStrings},${chat.friendlyName.replace(/,/g, '')}:::${chat.count}`
}
// remove trailing comma
friendlyNameStrings = friendlyNameStrings.substring(1, friendlyNameStrings.length)
return friendlyNameStrings
}
setIPAddress (IPAddress) { setIPAddress (IPAddress) {
console.log(`instantiate apolloclient with uri ${IPAddress}:4000/`) console.log(`instantiate apolloclient with uri ${IPAddress}:4000/`)

View File

@ -195,6 +195,8 @@ void wait(float timeInSeconds) {
// printf(log); // printf(log);
} }
const int MAX_RECIEVE_LOOP_ITERATIONS = 1000;
// void because this function re-assigns respo // void because this function re-assigns respo
void readSerialPort(char* output) { void readSerialPort(char* output) {
@ -210,9 +212,22 @@ void readSerialPort(char* output) {
char tempOutput[MAX_RECEIVE_SIZE]; char tempOutput[MAX_RECEIVE_SIZE];
long int totalByteCount = 0; long int totalByteCount = 0;
incomingSerialPortReference.ioReqCount = 0; incomingSerialPortReference.ioReqCount = 0;
int loopCounter = 0;
while (!done) { while (!done) {
if (loopCounter++ > MAX_RECIEVE_LOOP_ITERATIONS) {
char *errorMessage = "TIMEOUT_ERROR";
strncat(output, errorMessage, strlen(errorMessage));
// once we are done reading the buffer entirely, we need to clear it. i'm not sure if this is the best way or not but seems to work
memset(&GlobalSerialInputBuffer[0], 0, MAX_RECEIVE_SIZE);
return;
}
long int byteCount = 0; long int byteCount = 0;
long int lastByteCount = 0; long int lastByteCount = 0;
bool doByteCountsMatch = false; bool doByteCountsMatch = false;

View File

@ -178,7 +178,8 @@ void EventLoop(struct nk_context *ctx)
int lastMouseHPos = 0; int lastMouseHPos = 0;
int lastMouseVPos = 0; int lastMouseVPos = 0;
int lastUpdatedTickCount = 0; int lastUpdatedTickCountMessagesInChat = 0;
int lastUpdatedTickCountChatCounts = 0;
do { do {
@ -191,10 +192,10 @@ void EventLoop(struct nk_context *ctx)
// check for new stuff every 10 sec? // check for new stuff every 10 sec?
// note! this is used by some of the functionality in our nuklear_app to trigger // note! this is used by some of the functionality in our nuklear_app to trigger
// new chat lookups // new chat lookups
if (TickCount() - lastUpdatedTickCount > 600) { if (TickCount() - lastUpdatedTickCountMessagesInChat > 600) {
// writeSerialPortDebug(boutRefNum, "update by tick count"); // writeSerialPortDebug(boutRefNum, "update by tick count");
lastUpdatedTickCount = TickCount(); lastUpdatedTickCountMessagesInChat = TickCount();
if (strcmp(activeChat, "no active chat")) { if (strcmp(activeChat, "no active chat")) {
@ -203,6 +204,20 @@ void EventLoop(struct nk_context *ctx)
} }
} }
// this should be out of sync with the counter above it so that we dont end up making
// two coprocessor calls on one event loop iteration
if (TickCount() - lastUpdatedTickCountChatCounts > 300) {
// writeSerialPortDebug(boutRefNum, "update by tick count");
lastUpdatedTickCountChatCounts = TickCount();
if (chatFriendlyNamesCounter > 0) {
// writeSerialPortDebug(boutRefNum, "check chat counts");
getChatCounts(activeChat);
}
}
Boolean beganInput = false; Boolean beganInput = false;
GetGlobalMouse(&mouse); GetGlobalMouse(&mouse);
@ -239,7 +254,8 @@ void EventLoop(struct nk_context *ctx)
mouse_x = tempPoint.h; mouse_x = tempPoint.h;
mouse_y = tempPoint.v; mouse_y = tempPoint.v;
lastUpdatedTickCount = TickCount(); lastUpdatedTickCountChatCounts = TickCount();
lastUpdatedTickCountMessagesInChat = TickCount();
lastMouseHPos = mouse.h; lastMouseHPos = mouse.h;
lastMouseVPos = mouse.v; lastMouseVPos = mouse.v;
GetGlobalMouse(&mouse); GetGlobalMouse(&mouse);
@ -252,7 +268,8 @@ void EventLoop(struct nk_context *ctx)
// drain all events before rendering -- really this only applies to keyboard events and single mouse clicks now // drain all events before rendering -- really this only applies to keyboard events and single mouse clicks now
while (gotEvent) { while (gotEvent) {
lastUpdatedTickCount = TickCount(); lastUpdatedTickCountChatCounts = TickCount();
lastUpdatedTickCountMessagesInChat = TickCount();
#ifdef MAC_APP_DEBUGGING #ifdef MAC_APP_DEBUGGING
@ -305,7 +322,7 @@ void EventLoop(struct nk_context *ctx)
#ifdef MAC_APP_DEBUGGING #ifdef MAC_APP_DEBUGGING
writeSerialPortDebug(boutRefNum, "nk_quickdraw_render"); writeSerialPortDebug(boutRefNum, "nuklearApp");
#endif #endif
nuklearApp(ctx); nuklearApp(ctx);
@ -315,6 +332,11 @@ void EventLoop(struct nk_context *ctx)
PROFILE_START("nk_quickdraw_render"); PROFILE_START("nk_quickdraw_render");
#endif #endif
#ifdef MAC_APP_DEBUGGING
writeSerialPortDebug(boutRefNum, "nk_quickdraw_render");
#endif
nk_quickdraw_render(FrontWindow(), ctx); nk_quickdraw_render(FrontWindow(), ctx);
#ifdef PROFILING #ifdef PROFILING
@ -464,7 +486,7 @@ void DoEvent(EventRecord *event, struct nk_context *ctx) {
case osEvt: case osEvt:
#ifdef MAC_APP_DEBUGGING #ifdef MAC_APP_DEBUGGING
riteSerialPortDebug(boutRefNum, "os"); writeSerialPortDebug(boutRefNum, "os");
#endif #endif
// this should be trigger on mousemove but does not -- if we can figure that out, we should call through to // this should be trigger on mousemove but does not -- if we can figure that out, we should call through to

View File

@ -10504,8 +10504,12 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
// NK_ASSERT(ctx); // NK_ASSERT(ctx);
// NK_ASSERT(ctx->current); // NK_ASSERT(ctx->current);
// NK_ASSERT(ctx->current->layout); // NK_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout) return 0; if (!ctx || !ctx->current || !ctx->current->layout) {
return 0;
}
nk_zero(ctx->current->layout, sizeof(*ctx->current->layout)); nk_zero(ctx->current->layout, sizeof(*ctx->current->layout));
if ((ctx->current->flags & NK_WINDOW_HIDDEN) || (ctx->current->flags & NK_WINDOW_CLOSED)) { if ((ctx->current->flags & NK_WINDOW_HIDDEN) || (ctx->current->flags & NK_WINDOW_CLOSED)) {
nk_zero(ctx->current->layout, sizeof(struct nk_panel)); nk_zero(ctx->current->layout, sizeof(struct nk_panel));
ctx->current->layout->type = panel_type; ctx->current->layout->type = panel_type;
@ -10638,11 +10642,12 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
} }
/* window close button */ /* window close button */
{struct nk_rect button; {
button.y = header.y + style->window.header.padding.y;
button.h = header.h - 2 * style->window.header.padding.y;
button.w = button.h;
if (win->flags & NK_WINDOW_CLOSABLE) { if (win->flags & NK_WINDOW_CLOSABLE) {
struct nk_rect button;
button.y = header.y + style->window.header.padding.y;
button.h = header.h - 2 * style->window.header.padding.y;
button.w = button.h;
nk_flags ws = 0; nk_flags ws = 0;
if (style->window.header.align == NK_HEADER_RIGHT) { if (style->window.header.align == NK_HEADER_RIGHT) {
button.x = (header.w + header.x) - (button.w + style->window.header.padding.x); button.x = (header.w + header.x) - (button.w + style->window.header.padding.x);
@ -10663,6 +10668,10 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
/* window minimize button */ /* window minimize button */
if (win->flags & NK_WINDOW_MINIMIZABLE) { if (win->flags & NK_WINDOW_MINIMIZABLE) {
struct nk_rect button;
button.y = header.y + style->window.header.padding.y;
button.h = header.h - 2 * style->window.header.padding.y;
button.w = button.h;
nk_flags ws = 0; nk_flags ws = 0;
if (style->window.header.align == NK_HEADER_RIGHT) { if (style->window.header.align == NK_HEADER_RIGHT) {
button.x = (header.w + header.x) - button.w; button.x = (header.w + header.x) - button.w;
@ -10695,7 +10704,7 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
label.h = font->height + 2 * style->window.header.label_padding.y; label.h = font->height + 2 * style->window.header.label_padding.y;
label.w = t + 2 * style->window.header.spacing.x; label.w = t + 2 * style->window.header.spacing.x;
label.w = NK_CLAMP(0, label.w, header.x + header.w - label.x); label.w = NK_CLAMP(0, label.w, header.x + header.w - label.x);
nk_widget_text(out, label, (const char*)title, text_len, &text, NK_TEXT_LEFT, font, true);} nk_widget_text(out, label, (const char*)title, text_len, &text, NK_TEXT_ALIGN_MIDDLE, font, true);}
} }
/* draw window background */ /* draw window background */
@ -10722,8 +10731,7 @@ nk_panel_begin(struct nk_context *ctx, const char *title, enum nk_panel_type pan
/* set clipping rectangle */ /* set clipping rectangle */
{struct nk_rect clip; {struct nk_rect clip;
layout->clip = layout->bounds; layout->clip = layout->bounds;
nk_unify(&clip, &win->buffer.clip, layout->clip.x, layout->clip.y, nk_unify(&clip, &win->buffer.clip, layout->clip.x, layout->clip.y, layout->clip.x + layout->clip.w, layout->clip.y + layout->clip.h);
layout->clip.x + layout->clip.w, layout->clip.y + layout->clip.h);
nk_push_scissor(out, clip); nk_push_scissor(out, clip);
layout->clip = clip;} layout->clip = clip;}
return !(layout->flags & NK_WINDOW_HIDDEN) && !(layout->flags & NK_WINDOW_MINIMIZED); return !(layout->flags & NK_WINDOW_HIDDEN) && !(layout->flags & NK_WINDOW_MINIMIZED);
@ -11182,8 +11190,9 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
// NK_ASSERT(title); // NK_ASSERT(title);
// NK_ASSERT(ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font"); // NK_ASSERT(ctx->style.font && ctx->style.font->width && "if this triggers you forgot to add a font");
// NK_ASSERT(!ctx->current && "if this triggers you missed a `nk_end` call"); // NK_ASSERT(!ctx->current && "if this triggers you missed a `nk_end` call");
if (!ctx || ctx->current || !title || !name) if (!ctx || ctx->current || !title || !name) {
return 0; return 0;
}
/* find or create window */ /* find or create window */
style = &ctx->style; style = &ctx->style;
@ -11197,9 +11206,12 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
// NK_ASSERT(win); // NK_ASSERT(win);
if (!win) return 0; if (!win) return 0;
if (flags & NK_WINDOW_BACKGROUND) if (flags & NK_WINDOW_BACKGROUND) {
nk_insert_window(ctx, win, NK_INSERT_FRONT); nk_insert_window(ctx, win, NK_INSERT_FRONT);
else nk_insert_window(ctx, win, NK_INSERT_BACK); } else {
nk_insert_window(ctx, win, NK_INSERT_BACK);
}
nk_command_buffer_init(&win->buffer, &ctx->memory, NK_CLIPPING_ON); nk_command_buffer_init(&win->buffer, &ctx->memory, NK_CLIPPING_ON);
win->flags = flags; win->flags = flags;
@ -11209,14 +11221,16 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title,
NK_MEMCPY(win->name_string, name, name_length); NK_MEMCPY(win->name_string, name, name_length);
win->name_string[name_length] = 0; win->name_string[name_length] = 0;
win->popup.win = 0; win->popup.win = 0;
if (!ctx->active) if (!ctx->active) {
ctx->active = win; ctx->active = win;
}
} else { } else {
/* update window */ /* update window */
win->flags &= ~(nk_flags)(NK_WINDOW_PRIVATE-1); win->flags &= ~(nk_flags)(NK_WINDOW_PRIVATE-1);
win->flags |= flags; win->flags |= flags;
if (!(win->flags & (NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE))) if (!(win->flags & (NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE))) {
win->bounds = bounds; win->bounds = bounds;
}
/* If this assert triggers you either: /* If this assert triggers you either:
* *
* I.) Have more than one window with the same name or * I.) Have more than one window with the same name or
@ -18408,9 +18422,9 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
short l = nk_str_len_char(&edit->string); short l = nk_str_len_char(&edit->string);
const char *begin = nk_str_get_const(&edit->string); const char *begin = nk_str_get_const(&edit->string);
const struct nk_style_item *background; // const struct nk_style_item *background;
struct nk_color background_color; // struct nk_color background_color;
struct nk_color text_color; // struct nk_color text_color;
nk_push_scissor(out, clip); nk_push_scissor(out, clip);
// if (*state & NK_WIDGET_STATE_ACTIVED) { // if (*state & NK_WIDGET_STATE_ACTIVED) {
// background = &style->active; // background = &style->active;
@ -18434,7 +18448,7 @@ nk_do_edit(nk_flags *state, struct nk_command_buffer *out,
whiteTextarea.w = area.w; whiteTextarea.w = area.w;
nk_fill_rect(out, whiteTextarea, 0, nk_rgba(255,255,255,255), false); nk_fill_rect(out, whiteTextarea, 0, nk_rgba(255,255,255,255), false);
nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, area.y - edit->scrollbar.y, 0, begin, l, row_height, font, background->data.color, text_color, nk_false, false); nk_edit_draw_text(out, style, area.x - edit->scrollbar.x, area.y - edit->scrollbar.y, 0, begin, l, row_height, font, style->normal.data.color, style->text_normal, nk_false, true);
} }
nk_push_scissor(out, old_clip);} nk_push_scissor(out, old_clip);}

View File

@ -1,8 +1,7 @@
// TODO: // TODO:
// - IN PROGRESS new message window -- needs to blank out messages, then needs fixes on new mac end // - IN PROGRESS new message window -- needs to blank out messages, then needs fixes on new mac end -- this might work
// - get new messages in other chats and display some sort of alert // - IN PROGRESS get new messages in other chats and display some sort of alert
// - need timeout on serial messages in case the computer at the other end dies (prevent hard reset) -- probably possible in coprocessorjs library // - 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
// - delete doesnt work right (leaves characters at end of string)
#define WINDOW_WIDTH 510 #define WINDOW_WIDTH 510
#define WINDOW_HEIGHT 302 #define WINDOW_HEIGHT 302
@ -48,6 +47,8 @@ char box_input_buffer[2048];
char chatFriendlyNames[16][64]; char chatFriendlyNames[16][64];
char ip_input_buffer[255]; char ip_input_buffer[255];
char jsFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE char jsFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE
char chatCountFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE
char previousChatCountFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE
char new_message_input_buffer[255]; char new_message_input_buffer[255];
int activeMessageCounter = 0; int activeMessageCounter = 0;
int chatFriendlyNamesCounter = 0; int chatFriendlyNamesCounter = 0;
@ -149,6 +150,68 @@ void getMessages(char *thread, int page) {
return; return;
} }
void getChatCounts() {
char output[62];
sprintf(output, "");
// writeSerialPortDebug(boutRefNum, output);
callFunctionOnCoprocessor("getChatCounts", output, chatCountFunctionResponse);
// writeSerialPortDebug(boutRefNum, jsFunctionResponse);
if (!strcmp(chatCountFunctionResponse, previousChatCountFunctionResponse)) {
writeSerialPortDebug(boutRefNum, "update current chat count");
writeSerialPortDebug(boutRefNum, chatCountFunctionResponse);
SysBeep(1);
char *token = (char *)strtok(chatCountFunctionResponse, ",");
// loop through the string to extract all other tokens
while (token != NULL) {
writeSerialPortDebug(boutRefNum, "update current chat count loop");
writeSerialPortDebug(boutRefNum, token);
// should be in format NAME:::COUNT
char *name = strtok(token, ":::");
short count = atoi(strtok(NULL, " "));
if (count == 0) {
continue;
}
for (int i = 0; i < chatFriendlyNamesCounter; i++) {
if (strstr(chatFriendlyNames[i], " new) ")) {
char *tempChatFriendlyName;
strtok(chatFriendlyNames[i], " new) ");
tempChatFriendlyName = strtok(NULL, " ");
if (strcmp(tempChatFriendlyName, name)) {
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
break;
}
} else {
if (strcmp(chatFriendlyNames[i], name)) {
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
break;
}
}
}
token = (char *)strtokm(NULL, ",");
}
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
}
return;
}
void getHasNewMessagesInChat(char *thread) { void getHasNewMessagesInChat(char *thread) {
char output[62]; char output[62];
@ -163,8 +226,9 @@ void getHasNewMessagesInChat(char *thread) {
// writeSerialPortDebug(boutRefNum, "update current chat"); // writeSerialPortDebug(boutRefNum, "update current chat");
SysBeep(1); SysBeep(1);
getMessages(thread, 0); getMessages(thread, 0);
// force redraw // force redraw
firstOrMouseMove = true; forceRedraw = 3;
} }
return; return;
@ -174,6 +238,8 @@ void getHasNewMessagesInChat(char *thread) {
// run it on some interval? make sure user is not typing!!! // run it on some interval? make sure user is not typing!!!
void getChats() { void getChats() {
writeSerialPortDebug(boutRefNum, "getChats!");
if (haveRun) { if (haveRun) {
return; return;
@ -186,6 +252,7 @@ void getChats() {
char * token = (char *)strtokm(jsFunctionResponse, ","); char * token = (char *)strtokm(jsFunctionResponse, ",");
// 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, token);
sprintf(chatFriendlyNames[chatFriendlyNamesCounter++], "%s", token); sprintf(chatFriendlyNames[chatFriendlyNamesCounter++], "%s", token);
token = (char *)strtokm(NULL, ","); token = (char *)strtokm(NULL, ",");
} }

View File

@ -26,6 +26,7 @@
#define ENABLED_DOUBLE_BUFFERING #define ENABLED_DOUBLE_BUFFERING
#define COMMAND_CACHING #define COMMAND_CACHING
// #define NK_QUICKDRAW_GRAPHICS_DEBUGGING
Boolean lastInputWasBackspace; Boolean lastInputWasBackspace;