fix demo mode, reduce optimization of build to see if we can fix address errors on physical mac

This commit is contained in:
camh 2022-02-08 00:00:52 -08:00
parent 4a457f94fb
commit 4e6a34a83f
5 changed files with 66 additions and 23 deletions

View File

@ -6,7 +6,7 @@
cmake_minimum_required(VERSION 2.8)
set (CMAKE_C_FLAGS "-Ofast -Wuninitialized -Wmaybe-uninitialized -mcpu=68000 -mtune=68000 -m68000 -Wall")
set (CMAKE_C_FLAGS "-O3 -Wuninitialized -Wmaybe-uninitialized -mcpu=68000 -mtune=68000 -m68000 -Wall")
add_application(MessagesForMacintosh
SerialHelper.c

View File

@ -7,6 +7,7 @@ const gql = require('graphql-tag')
// 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 DEBUG = false
let lastMessageFromSerialPortTime
const defaultOptions = {
watchQuery: {
@ -304,11 +305,8 @@ let TEST_MESSAGES = [
{chatter: `me`, text: `some cool old thing I said earlier`},
{chatter: `friend 2`, text: `this message is not relevant to the conversation! not at all :(`},
{chatter: `friend 1`, text: `i watch star wars in reverse order`},
{chatter: `me`, text: `https://github.com/CamHenlin/MessagesForMacintosh https://github.com/CamHenlin/MessagesForMacintosh`},
{chatter: `friend 3`, text: `i'm just catching up`},
{chatter: `friend 3`, text: `nobody chat for a minute`},
{chatter: `friend 2`, text: `hang on`},
{chatter: `friend 1`, text: `no`}
{chatter: `me`, text: `https://github.com/CamHenlin/MessagesForMacintosh`},
{chatter: `friend 3`, text: `old computers are fun`}
]
const TEST_CHATS = [
@ -317,15 +315,24 @@ const TEST_CHATS = [
{friendlyName: `friend 4`, name: `friend 4`},
{friendlyName: `boss`, name: `boss`},
{friendlyName: `friend 3`, name: `friend 3`},
{friendlyName: `restaurant`, name: `restaurant`}
{friendlyName: `restaurant`, name: `restaurant`},
{friendlyName: `work`, name: `work`}
]
if (TEST_MODE) {
setInterval(() => {
// setInterval(() => {
TEST_MESSAGES = TEST_MESSAGES.concat({chatter: `friend 1`, text: Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 64)})
}, 10000)
// let chatWords = Math.floor(Math.random() * 20) + 1
// let chatMessage = ``
// for (let chatWord = 0; chatWord < chatWords; chatWord++) {
// chatMessage = `${chatMessage} ${Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, Math.floor(Math.random() * 16) + 1)}`
// }
// TEST_MESSAGES = TEST_MESSAGES.concat({chatter: `friend 1`, text: chatMessage})
// }, 10000)
}
let storedArgsAndResults = {
@ -361,7 +368,16 @@ class iMessageGraphClientClass {
if (TEST_MODE) {
return splitMessages(TEST_MESSAGES)
let currentLastMessageOutput = `${lastMessageOutput}`
storedArgsAndResults.getMessages.output = splitMessages(TEST_MESSAGES)
if (!hasNewMessages && fromInterval) {
hasNewMessages = currentLastMessageOutput !== storedArgsAndResults.getMessages.output
}
return storedArgsAndResults.getMessages.output
}
if (DEBUG) {
@ -430,7 +446,9 @@ class iMessageGraphClientClass {
TEST_MESSAGES = TEST_MESSAGES.concat({chatter: `me`, text: message})
return splitMessages(TEST_MESSAGES)
storedArgsAndResults.getMessages.output = splitMessages(TEST_MESSAGES)
return storedArgsAndResults.getMessages.output
}
let result
@ -472,7 +490,9 @@ class iMessageGraphClientClass {
if (TEST_MODE) {
return parseChatsToFriendlyNameString(TEST_CHATS)
storedArgsAndResults.getChats.output = parseChatsToFriendlyNameString(TEST_CHATS)
return
}
let result
@ -517,7 +537,9 @@ class iMessageGraphClientClass {
if (TEST_MODE) {
return parseChatsToFriendlyNameString(TEST_CHATS)
storedArgsAndResults.getChatCounts.output = parseChatsToFriendlyNameString(TEST_CHATS)
return
}
let result
@ -617,7 +639,7 @@ class iMessageClient {
constructor () {
// kick off an update interval
setInterval(async () => {
const updateInterval = setInterval(async () => {
let intervalDate = new Date().toISOString()
@ -630,6 +652,15 @@ class iMessageClient {
return
}
if (new Date() - lastMessageFromSerialPortTime > 30000) {
console.log(`${intervalDate}: no serial comms for 30 seconds, unloading interval`)
clearInterval(updateInterval)
return
}
if (DEBUG) {
console.log(`${intervalDate}: running...`)
@ -662,6 +693,8 @@ class iMessageClient {
async getMessages (chatId, page) {
lastMessageFromSerialPortTime = new Date()
console.log(`iMessageClient.getMessages`)
if (storedArgsAndResults.getMessages.args.chatId !== chatId || storedArgsAndResults.getMessages.args.page !== page) {
@ -677,6 +710,8 @@ class iMessageClient {
async hasNewMessagesInChat (chatId) {
lastMessageFromSerialPortTime = new Date()
console.log(`iMessageClient.hasNewMessagesInChat`)
let returnValue = await iMessageGraphClient.hasNewMessagesInChat(chatId)
@ -689,6 +724,8 @@ class iMessageClient {
async sendMessage (chatId, message) {
lastMessageFromSerialPortTime = new Date()
console.log(`iMessageClient.sendMessage(${chatId}, ${message})`)
const messages = await iMessageGraphClient.sendMessage(chatId, message)
@ -698,6 +735,8 @@ class iMessageClient {
async getChats () {
lastMessageFromSerialPortTime = new Date()
console.log(`iMessageClient.getChats`)
if (Object.keys(storedArgsAndResults.getChats.output).length === 0) {
@ -713,6 +752,8 @@ class iMessageClient {
getChatCounts () {
lastMessageFromSerialPortTime = new Date()
console.log(`iMessageClient.getChatCounts, prestored return:`)
console.log(storedArgsAndResults.getChatCounts.output)

View File

@ -637,7 +637,7 @@ void DoMenuCommand(menuResult)
{
short menuID; /* the resource ID of the selected menu */
short menuItem; /* the item number of the selected menu */
// short itemHit;
//short itemHit;
// Str255 daName;
// short daRefNum;
// Boolean handledByDA;
@ -647,9 +647,10 @@ void DoMenuCommand(menuResult)
switch ( menuID ) {
case mApple:
switch ( menuItem ) {
// case iAbout: /* bring up alert for About */
case iAbout: /* bring up alert for About */
Alert(rAboutAlert, nil);
break;
default:
// itemHit = Alert(rAboutAlert, nil);
break;
/*

View File

@ -257,7 +257,7 @@ resource 'DITL' (rUserAlert, purgeable) {
resource 'WIND' (rWindow, preload, purgeable) {
{39, 1, 341, 511},
{42, 4, 336, 506},
zoomDocProc, visible, noGoAway, 0x0, "Messages",
centerMainScreen // Where to show the alert
};

View File

@ -1,8 +1,9 @@
// TODO:
// - test on physical, bug fixes, write blog posts
#define WINDOW_WIDTH 510
#define WINDOW_HEIGHT 302
// {42, 4, 336, 506}
#define WINDOW_WIDTH 502
#define WINDOW_HEIGHT 294
#define NK_ZERO_COMMAND_MEMORY
#define NK_INCLUDE_FIXED_TYPES
@ -605,7 +606,7 @@ static void nuklearApp(struct nk_context *ctx) {
// bottom text input
nk_layout_row_begin(ctx, NK_STATIC, 28, 1);
{
nk_layout_row_push(ctx, 320);
nk_layout_row_push(ctx, 312);
short edit_return_value = nk_edit_string(ctx, NK_EDIT_FIELD|NK_EDIT_SIG_ENTER, box_input_buffer, &box_input_len, 2048, nk_filter_default);
@ -622,7 +623,7 @@ static void nuklearApp(struct nk_context *ctx) {
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, 11, 1);
{
for (int i = 0; i < activeMessageCounter; i++) {