big update: fix final message update bugs, fix about screen. only small TODO items, code cleanup, and testing on physical mac (once i finish recapping the analog board on my mac classic) remaining!

This commit is contained in:
camh 2022-01-25 23:54:08 -08:00
parent f3755e40f9
commit 111e717b15
11 changed files with 412 additions and 1262 deletions

View File

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

View File

@ -6,6 +6,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
const defaultOptions = {
watchQuery: {
@ -155,6 +156,7 @@ const widthFor12ptFont = [
const MAX_WIDTH = 304
const SPACE_WIDTH = widthFor12ptFont[32]
let canStart = false
let hasNewMessages = false
const getNextWordLength = (word) => {
@ -350,7 +352,7 @@ let storedArgsAndResults = {
// classic Macintosh end
class iMessageGraphClientClass {
async getMessages (chatId, page) {
async getMessages (chatId, page, fromInterval) {
storedArgsAndResults.getMessages.args = {
chatId,
@ -362,7 +364,10 @@ class iMessageGraphClientClass {
return splitMessages(TEST_MESSAGES)
}
console.log(`get messages for chat ID: ${chatId}`)
if (DEBUG) {
console.log(`get messages for chat ID: ${chatId}`)
}
let result
@ -378,30 +383,45 @@ class iMessageGraphClientClass {
})
} catch (error) {
console.log(`error with apollo query`)
console.log(`getMessages: error with apollo query`)
console.log(error)
result = {
data: {
}
}
return
}
let messages = result.data.getMessages
let currentLastMessageOutput = `${lastMessageOutput}`
storedArgsAndResults.getMessages.output = splitMessages(messages)
}
async hasNewMessagesInChat (chatId) {
if (!hasNewMessages && fromInterval) {
storedArgsAndResults.hasNewMessagesInChat.args = {
chatId
hasNewMessages = currentLastMessageOutput !== storedArgsAndResults.getMessages.output
if (hasNewMessages) {
console.log(`got new message. previous message was:`)
console.log(currentLastMessageOutput)
console.log(`new message set is:`)
console.log(storedArgsAndResults.getMessages.output)
}
}
let currentLastMessageOutput = `${lastMessageOutput}`
let messageOutput = await this.getMessages(chatId, 0)
return
}
storedArgsAndResults.hasNewMessagesInChat.output = (currentLastMessageOutput !== messageOutput).toString()
async hasNewMessagesInChat () {
if (!hasNewMessages) {
return `false`
} else {
hasNewMessages = false
}
return `true`
}
async sendMessage (chatId, message) {
@ -416,7 +436,9 @@ class iMessageGraphClientClass {
let result
try {
message = message.replaceAll('"', '')
result = await client.query({
query: gql`query sendMessage {
sendMessage(chatId: "${chatId}", message: "${message}") {
@ -427,13 +449,10 @@ class iMessageGraphClientClass {
})
} catch (error) {
console.log(`error with apollo query`)
console.log(`sendMessage: error with apollo query`)
console.log(error)
result = {
data: {
}
}
return
}
let messages = result.data.sendMessage
@ -443,7 +462,11 @@ class iMessageGraphClientClass {
async getChats () {
console.log(`getChats`)
if (DEBUG) {
console.log(`getChats`)
}
if (TEST_MODE) {
@ -464,27 +487,31 @@ class iMessageGraphClientClass {
})
} catch (error) {
console.log(`error with apollo query`)
console.log(`getChats: error with apollo query`)
console.log(error)
result = {
data: {
}
}
return
}
let chats = result.data.getChats
console.log(`getChats complete`)
storedArgsAndResults.getChats.output = parseChatsToFriendlyNameString(chats)
console.log(storedArgsAndResults.getChats.output)
if (DEBUG) {
console.log(`getChats complete`)
console.log(storedArgsAndResults.getChats.output)
}
return
}
async getChatCounts () {
console.log(`getChatCounts`)
if (DEBUG) {
console.log(`getChatCounts`)
}
if (TEST_MODE) {
@ -505,29 +532,24 @@ class iMessageGraphClientClass {
})
} catch (error) {
console.log(`error with apollo query`)
console.log(`getChatCounts: error with apollo query`)
console.log(error)
result = {
data: {
}
}
return
}
let chats = result.data.getChatCounts
console.log(`got chat counts`)
if (!chats) {
return ``
return
}
let friendlyNameStrings = ``
if (chats.length === 0) {
return ``
return
}
for (let chat of chats) {
@ -537,9 +559,16 @@ class iMessageGraphClientClass {
// remove trailing comma
friendlyNameStrings = friendlyNameStrings.substring(1, friendlyNameStrings.length)
console.log(friendlyNameStrings)
storedArgsAndResults.getChatCounts.output = friendlyNameStrings
if (DEBUG) {
console.log(`got chat counts`)
console.log(friendlyNameStrings)
}
return
}
setIPAddress (IPAddress) {
@ -588,32 +617,45 @@ class iMessageClient {
// kick off an update interval
setInterval(async () => {
console.log(`run interval`)
let intervalDate = new Date().toISOString()
console.log(`${intervalDate}: run interval`)
if (!canStart) {
console.log(`can't start yet`)
console.log(`${intervalDate}: can't start yet`)
return
}
// if (DEBUG) {
console.log(`${intervalDate}: running...`)
// }
try {
console.log(`running...`)
if (Object.keys(storedArgsAndResults.getMessages.args).length > 0) {
await iMessageGraphClient.getMessages(storedArgsAndResults.getMessages.args.chatId, storedArgsAndResults.getMessages.args.page)
}
if (Object.keys(storedArgsAndResults.getMessages.args).length > 0) {
console.log(`${intervalDate}: interval: get messages for ${storedArgsAndResults.getMessages.args.chatId}`)
await iMessageGraphClient.getMessages(storedArgsAndResults.getMessages.args.chatId, storedArgsAndResults.getMessages.args.page, true)
}
if (Object.keys(storedArgsAndResults.hasNewMessagesInChat.args).length > 0) {
await iMessageGraphClient.hasNewMessagesInChat(storedArgsAndResults.hasNewMessagesInChat.chatId)
console.log(`${intervalDate}: interval: getchats`)
await iMessageGraphClient.getChats()
console.log(`${intervalDate}: interval: getchatcounts`)
await iMessageGraphClient.getChatCounts()
} catch (error) {
console.log(`${intervalDate}: caught error when running interval`)
console.log(error)
}
await iMessageGraphClient.getChats()
await iMessageGraphClient.getChatCounts()
console.log(`complete!`)
}, 2000)
// if (DEBUG) {
console.log(`${intervalDate}: complete!`)
// }
}, 3000)
}
async getMessages (chatId, page) {
@ -622,9 +664,12 @@ class iMessageClient {
if (storedArgsAndResults.getMessages.args.chatId !== chatId || storedArgsAndResults.getMessages.args.page !== page) {
await iMessageGraphClient.getMessages(chatId, page)
await iMessageGraphClient.getMessages(chatId, page, false)
}
console.log(`iMessageClient.getMessages, return:`)
console.log(storedArgsAndResults.getMessages.output)
return storedArgsAndResults.getMessages.output
}
@ -632,12 +677,12 @@ class iMessageClient {
console.log(`iMessageClient.hasNewMessagesInChat`)
if (storedArgsAndResults.hasNewMessagesInChat.args.chatId !== chatId) {
let returnValue = await iMessageGraphClient.hasNewMessagesInChat(chatId)
await iMessageGraphClient.hasNewMessagesInChat(chatId)
}
console.log(`iMessageClient.hasNewMessagesInChat, return:`)
console.log(returnValue)
return storedArgsAndResults.hasNewMessagesInChat.output
return returnValue
}
async sendMessage (chatId, message) {
@ -656,12 +701,16 @@ class iMessageClient {
await iMessageGraphClient.getChats()
}
console.log(`iMessageClient.getChats, return:`)
console.log(storedArgsAndResults.getChats.output)
return storedArgsAndResults.getChats.output
}
getChatCounts () {
console.log(`iMessageClient.getChatCounts`)
console.log(`iMessageClient.getChatCounts, prestored return:`)
console.log(storedArgsAndResults.getChatCounts.output)
return storedArgsAndResults.getChatCounts.output
}

View File

@ -1,55 +0,0 @@
# path to RETRO68
RETRO68=../../../Retro68-build/toolchain
PREFIX=$(RETRO68)/m68k-unknown-elf
CC=$(RETRO68)/bin/m68k-unknown-elf-gcc
CXX=$(RETRO68)/bin/m68k-unknown-elf-g++
REZ=$(RETRO68)/bin/Rez
BUILDFLAGS=-Ofast -ffloat-store -funsafe-math-optimizations -fsingle-precision-constant -mcpu=68000 -mtune=68000 -m68000 -msoft-float -malign-int
LDFLAGS=-lRetroConsole $(BUILDFLAGS)
RINCLUDES=$(PREFIX)/RIncludes
REZFLAGS=-I$(RINCLUDES)
# all resource file help is from https://github.com/clehner/Browsy/blob/master/Makefile
RSRC_HEX=$(wildcard rsrc/*/*.hex)
RSRC_TXT=$(wildcard rsrc/*/*.txt)
RSRC_JS=$(wildcard rsrc/*/*.js)
RSRC_JSON=$(wildcard rsrc/*/*.json)
RSRC_DAT=$(RSRC_HEX:.hex=.dat) $(RSRC_TXT:.txt=.dat) $(RSRC_JS:.js=.dat) $(RSRC_JSON:.json=.dat)
NuklearQuickDraw.bin NuklearQuickDraw.APPL NuklearQuickDraw.dsk: NuklearQuickDraw.flt rsrc-args compile_js
$(REZ) $(REZFLAGS) \
-DFLT_FILE_NAME="\"NuklearQuickDraw.flt\"" "$(RINCLUDES)/Retro68APPL.r" \
-t "APPL" \
$(BUILDFLAGS) -o NuklearQuickDraw.bin --cc NuklearQuickDraw.APPL --cc NuklearQuickDraw.dsk -C WWW6 $(shell cat rsrc-args)
NuklearQuickDraw.flt: hello.o
$(CXX) $< -o $@ $(LDFLAGS) # C++ used for linking because RetroConsole needs it
.PHONY: clean
clean:
rm -f NuklearQuickDraw.bin NuklearQuickDraw.APPL NuklearQuickDraw.dsk NuklearQuickDraw.flt NuklearQuickDraw.flt.gdb hello.o rsrc/*/*.dat rsrc-args
compile_js:
./compile_js.sh
rsrc: $(RSRC_DAT) rsrc-args
rsrc/%.dat: rsrc/%.hex
$(QUIET_RSRC)$(FROM_HEX) $< > $@
rsrc/TEXT/%.dat: rsrc/TEXT/%.txt
$(QUIET_RSRC)tr '\n' '\r' < $< > $@
rsrc/JS/%.dat: rsrc/TEXT/%.txt
$(QUIET_RSRC)tr '\n' '\r' < $< > $@
rsrc-args: $(RSRC_DAT)
@cd rsrc && for code in $$(ls); do \
echo -n "-t $$code "; \
cd "$$code" && for file in *.dat; do \
echo -n "-r $${file%.dat} rsrc/$$code/$$file "; \
done; \
cd ..; \
done > ../$@

View File

@ -1,349 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="NuklearQuickDraw" Version="10.0.0" InternalType="">
<Plugins>
<Plugin Name="qmake">
<![CDATA[00070001N0005Debug0000000000000001N0011pce-mac-5120000000000000001N0015pce-mac-classic0000000000000001N0019pce-mac-plus-sys6080000000000000001N0019pce-mac-plus-sys7010000000000000001N0017pce-mac-se-sys7550000000000000001N0010pce-mac128000000000000]]>
</Plugin>
</Plugins>
<VirtualDirectory Name="build">
<VirtualDirectory Name="CMakeFiles">
<VirtualDirectory Name="3.5.1">
<VirtualDirectory Name="CompilerIdC">
<File Name="build/CMakeFiles/3.5.1/CompilerIdC/CMakeCCompilerId.c"/>
</VirtualDirectory>
<VirtualDirectory Name="CompilerIdCXX">
<File Name="build/CMakeFiles/3.5.1/CompilerIdCXX/CMakeCXXCompilerId.cpp"/>
</VirtualDirectory>
</VirtualDirectory>
<File Name="build/CMakeFiles/feature_tests.cxx"/>
<File Name="build/CMakeFiles/feature_tests.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>
<Dependencies/>
<VirtualDirectory Name="NuklearQuickDraw">
<File Name="SerialHelper.h"/>
<File Name="SerialHelper.c"/>
<File Name="nuklear_quickdraw.h"/>
<File Name="nuklear.h"/>
<File Name="Sample.r"/>
<File Name="Sample.h"/>
<File Name="Sample.c"/>
<File Name="Makefile"/>
<File Name="CMakeLists.txt"/>
</VirtualDirectory>
<Settings Type="Executable">
<GlobalSettings>
<Compiler Options="" C_Options="" Assembler="">
<IncludePath Value="."/>
<IncludePath Value="/home/camh/Documents/Retro68/Retro68/CIncludes/"/>
<IncludePath Value="/home/camh/Documents/Retro68/Retro68/RIncludes/"/>
</Compiler>
<Linker Options="">
<LibraryPath Value="."/>
</Linker>
<ResourceCompiler Options=""/>
</GlobalSettings>
<Configuration Name="Basilisk II" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g -Wall" C_Options="" Assembler="" Required="no" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O0" Required="yes">
<LibraryPath Value="."/>
<LibraryPath Value="Debug"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./build_and_run.sh" CommandArguments="NuklearQuickDraw /b 0" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="/home/camh/Documents/Retro68kApps" PauseExecWhenProcTerminates="no" IsGUIProgram="yes" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>./clean.sh</CleanCommand>
<BuildCommand>./build.sh NuklearQuickDraw</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory>/home/camh/Documents/Retro68kApps</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="yes" EnableCpp14="yes">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths>/home/camh/Documents/Retro68/Retro68/CIncludes/
/home/camh/Documents/Retro68/Retro68/RIncludes/</SearchPaths>
</Completion>
</Configuration>
<Configuration Name="pce-mac-128" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g -Wall" C_Options="" Assembler="" Required="no" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O0" Required="yes">
<LibraryPath Value="."/>
<LibraryPath Value="Debug"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./build_and_run.sh" CommandArguments="NuklearQuickDraw pce-mac128 0" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="/home/camh/Documents/Retro68kApps" PauseExecWhenProcTerminates="no" IsGUIProgram="yes" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>./clean.sh</CleanCommand>
<BuildCommand>./build.sh NuklearQuickDraw</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory>/home/camh/Documents/Retro68kApps</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="yes" EnableCpp14="yes">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths>/home/camh/Documents/Retro68/Retro68/CIncludes/
/home/camh/Documents/Retro68/Retro68/RIncludes/</SearchPaths>
</Completion>
</Configuration>
<Configuration Name="pce-mac-512" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g -Wall" C_Options="" Assembler="" Required="no" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O0" Required="yes">
<LibraryPath Value="."/>
<LibraryPath Value="Debug"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./build_and_run.sh" CommandArguments="NuklearQuickDraw pce-mac512 0" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="/home/camh/Documents/Retro68kApps" PauseExecWhenProcTerminates="no" IsGUIProgram="yes" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>./clean.sh</CleanCommand>
<BuildCommand>./build.sh NuklearQuickDraw</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory>/home/camh/Documents/Retro68kApps</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="yes" EnableCpp14="yes">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths>/home/camh/Documents/Retro68/Retro68/CIncludes/
/home/camh/Documents/Retro68/Retro68/RIncludes/</SearchPaths>
</Completion>
</Configuration>
<Configuration Name="pce-mac-classic" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g -Wall" C_Options="" Assembler="" Required="no" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O0" Required="yes">
<LibraryPath Value="."/>
<LibraryPath Value="Debug"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./build_and_run.sh" CommandArguments="NuklearQuickDraw pce-mac-classic 0" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="/home/camh/Documents/Retro68kApps" PauseExecWhenProcTerminates="no" IsGUIProgram="yes" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>./clean.sh</CleanCommand>
<BuildCommand>./build.sh NuklearQuickDraw</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory>/home/camh/Documents/Retro68kApps/</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="yes" EnableCpp14="yes">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths>/home/camh/Documents/Retro68/Retro68/CIncludes/
/home/camh/Documents/Retro68/Retro68/RIncludes/</SearchPaths>
</Completion>
</Configuration>
<Configuration Name="pce-mac-plus-sys608" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g -Wall" C_Options="" Assembler="" Required="no" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O0" Required="yes">
<LibraryPath Value="."/>
<LibraryPath Value="Debug"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./build_and_run.sh" CommandArguments="NuklearQuickDraw pce-mac-plus-sys608 0" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="/home/camh/Documents/Retro68kApps" PauseExecWhenProcTerminates="no" IsGUIProgram="yes" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>./clean.sh</CleanCommand>
<BuildCommand>./build.sh NuklearQuickDraw</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory>/home/camh/Documents/Retro68kApps</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="yes" EnableCpp14="yes">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths>/home/camh/Documents/Retro68/Retro68/CIncludes/
/home/camh/Documents/Retro68/Retro68/RIncludes/</SearchPaths>
</Completion>
</Configuration>
<Configuration Name="pce-mac-plus-sys701" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g -Wall" C_Options="" Assembler="" Required="no" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O0" Required="yes">
<LibraryPath Value="."/>
<LibraryPath Value="Debug"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./build_and_run.sh" CommandArguments="NuklearQuickDraw pce-mac-plus-sys701 0" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="/home/camh/Documents/Retro68kApps" PauseExecWhenProcTerminates="no" IsGUIProgram="yes" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>./clean.sh</CleanCommand>
<BuildCommand>./build.sh NuklearQuickDraw</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory>/home/camh/Documents/Retro68kApps</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="yes" EnableCpp14="yes">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths>/home/camh/Documents/Retro68/Retro68/CIncludes/
/home/camh/Documents/Retro68/Retro68/RIncludes/</SearchPaths>
</Completion>
</Configuration>
<Configuration Name="pce-mac-se-sys755" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g -Wall" C_Options="" Assembler="" Required="no" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O0" Required="yes">
<LibraryPath Value="."/>
<LibraryPath Value="Debug"/>
</Linker>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName)" IntermediateDirectory="./Debug" Command="./build_and_run.sh" CommandArguments="NuklearQuickDraw pce-mac-se-sys755 0" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="/home/camh/Documents/Retro68kApps" PauseExecWhenProcTerminates="no" IsGUIProgram="yes" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>./clean.sh</CleanCommand>
<BuildCommand>./build.sh NuklearQuickDraw</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory>/home/camh/Documents/Retro68kApps</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="yes" EnableCpp14="yes">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths>/home/camh/Documents/Retro68/Retro68/CIncludes/
/home/camh/Documents/Retro68/Retro68/RIncludes/</SearchPaths>
</Completion>
</Configuration>
</Settings>
</CodeLite_Project>

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Workspace Name="NuklearQuickDraw" Database="" Version="10.0.0">
<Project Name="NuklearQuickDraw" Path="NuklearQuickDraw.project" Active="Yes"/>
<BuildMatrix>
<WorkspaceConfiguration Name="Default Config" Selected="yes">
<Environment/>
<Project Name="NuklearQuickDraw" ConfigName="pce-mac-classic"/>
<Project Name="NuklearQuickDraw" ConfigName="Basilisk II"/>
</WorkspaceConfiguration>
</BuildMatrix>
</CodeLite_Workspace>

View File

@ -12,9 +12,9 @@ IOParam outgoingSerialPortReference;
IOParam incomingSerialPortReference;
const bool PRINT_ERRORS = false;
const bool DEBUGGING = false;
const int RECEIVE_WINDOW_SIZE = 102400; // receive in up to 100kb chunks?
const int RECEIVE_WINDOW_SIZE = 32767; // receive in up to 100kb chunks?
const int MAX_RECEIVE_SIZE = RECEIVE_WINDOW_SIZE; // not sure if these ever need to be different
char GlobalSerialInputBuffer[102400]; // make this match MAX_RECEIVE_SIZE
char GlobalSerialInputBuffer[32767]; // make this match MAX_RECEIVE_SIZE
char application_id[255];
int call_counter = 0;

View File

@ -19,9 +19,11 @@
#include <Serial.h>
#include <Devices.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mac_main.h"
// #define MAC_APP_DEBUGGING
//#define PROFILING 1
#ifdef PROFILING
@ -107,7 +109,6 @@ Boolean gHasWaitNextEvent; /* set up by Initialize */
the program can check it to find out if it is currently in the background. */
Boolean gInBackground; /* maintained by Initialize and DoEvent */
// #define MAC_APP_DEBUGGING
/* The following globals are the state of the window. If we supported more than
one window, they would be attatched to each document, rather than globals. */
@ -142,9 +143,8 @@ void AlertUser( void );
// this function, EventLoop, and DoEvent contain all of the business logic necessary
// for our application to run
#pragma segment Main
void main()
{
int main()
{
Initialize(); /* initialize the program */
UnloadSeg((Ptr) Initialize); /* note that Initialize must not be in Main! */
@ -158,27 +158,24 @@ void main()
// we could build a nuklear window for selection
char programResult[MAX_RECEIVE_SIZE];
sendProgramToCoprocessor(OUTPUT_JS, programResult);
sendProgramToCoprocessor((char *)OUTPUT_JS, programResult);
writeSerialPortDebug(boutRefNum, "coprocessor loaded");
coprocessorLoaded = 1;
EventLoop(ctx); /* call the main event loop */
return 0;
}
Boolean gotKeyboardEvent = false;
int gotKeyboardEventTime = 0;
#pragma segment Main
void EventLoop(struct nk_context *ctx)
{
RgnHandle cursorRgn;
Boolean gotEvent;
Boolean hasNextEvent;
EventRecord event;
EventRecord nextEventRecord;
Point mouse;
cursorRgn = NewRgn();
int lastMouseHPos = 0;
int lastMouseVPos = 0;
@ -314,7 +311,7 @@ void EventLoop(struct nk_context *ctx)
SystemTask();
// only re-render if there is an event, prevents screen flickering, speeds up app
if (beganInput || firstOrMouseMove || forceRedraw) { // forceRedraw is from nuklear_app
if (beganInput || firstOrMouseMove || forceRedraw) {
#ifdef PROFILING
PROFILE_START("nk_input_end");
@ -344,6 +341,9 @@ void EventLoop(struct nk_context *ctx)
#ifdef MAC_APP_DEBUGGING
writeSerialPortDebug(boutRefNum, "nk_quickdraw_render");
char x[255];
sprintf(x, "why? beganInput: %d, firstOrMouseMove: %d, forceRedraw: %d", beganInput, firstOrMouseMove, forceRedraw);
writeSerialPortDebug(boutRefNum, x);
#endif
nk_quickdraw_render(FrontWindow(), ctx);
@ -377,11 +377,9 @@ void EventLoop(struct nk_context *ctx)
/* Do the right thing for an event. Determine what kind of event it is, and call
the appropriate routines. */
#pragma segment Main
void DoEvent(EventRecord *event, struct nk_context *ctx) {
short part;
short err;
WindowPtr window;
Boolean hit;
char key;
@ -495,7 +493,6 @@ void DoEvent(EventRecord *event, struct nk_context *ctx) {
#endif
if ( HiWord(event->message) != noErr ) {
SetPt(&aPoint, kDILeft, kDITop);
err = DIBadMount(aPoint, event->message);
}
break;
@ -527,7 +524,6 @@ void DoEvent(EventRecord *event, struct nk_context *ctx) {
coordinates is to call GetMouse and LocalToGlobal, but that requires
being sure that thePort is set to a valid port. */
#pragma segment Main
void GetGlobalMouse(mouse)
Point *mouse;
{
@ -545,7 +541,6 @@ void GetGlobalMouse(mouse)
will handle situations where calculations for drawing or drawing
itself is very time-consuming. */
#pragma segment Main
void DoUpdate(window)
WindowPtr window;
{
@ -561,7 +556,6 @@ void DoUpdate(window)
deactivate events is sufficient. Other applications may have
TextEdit records, controls, lists, etc., to activate/deactivate. */
#pragma segment Main
void DoActivate(window, becomingActive)
WindowPtr window;
Boolean becomingActive;
@ -579,8 +573,6 @@ void DoActivate(window, becomingActive)
machines, but color on color machines. At this point, the windowÕs visRgn
is set to allow drawing only where it needs to be done. */
static Rect okayButtonBounds;
/* Enable and disable menus based on the current state.
The user can only select enabled menu items. We set up all the menu items
before calling MenuSelect or MenuKey, since these are the only times that
@ -591,7 +583,6 @@ static Rect okayButtonBounds;
the application. Other application designs may take a different approach
that is just as valid. */
#pragma segment Main
void AdjustMenus()
{
WindowPtr window;
@ -636,16 +627,15 @@ void AdjustMenus()
It is good to have both the result of MenuSelect and MenuKey go to
one routine like this to keep everything organized. */
#pragma segment Main
void DoMenuCommand(menuResult)
long menuResult;
{
short menuID; /* the resource ID of the selected menu */
short menuItem; /* the item number of the selected menu */
short itemHit;
Str255 daName;
short daRefNum;
Boolean handledByDA;
// Str255 daName;
// short daRefNum;
// Boolean handledByDA;
menuID = HiWord(menuResult); /* use macros for efficiency to... */
menuItem = LoWord(menuResult); /* get menu item number and menu number */
@ -677,7 +667,7 @@ void DoMenuCommand(menuResult)
}
break;
case mEdit: /* call SystemEdit for DA editing & MultiFinder */
handledByDA = SystemEdit(menuItem-1); /* since we donÕt do any Editing */
// handledByDA = SystemEdit(menuItem-1); /* since we donÕt do any Editing */
break;
case mLight:
// note this was co-opted to send new chats instead of the demo functionality. do the
@ -691,9 +681,9 @@ void DoMenuCommand(menuResult)
break;
}
char x[255];
sprintf(x, "MENU %d", menuItem);
writeSerialPortDebug(boutRefNum, x);
// char x[255];
// sprintf(x, "MENU %d", menuItem);
// writeSerialPortDebug(boutRefNum, x);
break;
case mHelp:
@ -760,7 +750,6 @@ void DoMenuCommand(menuResult)
the user quits an application, but then cancels the save of a document
associated with a window. */
#pragma segment Main
Boolean DoCloseWindow(window)
WindowPtr window;
{
@ -778,7 +767,6 @@ Boolean DoCloseWindow(window)
/* 1.01 - If we find out that a cancel has occurred, we won't exit to the
shell, but will return instead. */
#pragma segment Main
void Terminate()
{
WindowPtr aWindow;
@ -799,13 +787,10 @@ void Terminate()
ExitToShell(); /* exit if no cancellation */
} /*Terminate*/
#pragma segment Initialize
void Initialize()
{
Handle menuBar;
WindowPtr window;
long total, contig;
EventRecord event;
short count;
@ -846,8 +831,6 @@ void Initialize()
} /*Initialize*/
#pragma segment Main
Boolean IsAppWindow(window)
WindowPtr window;
{
@ -865,7 +848,6 @@ Boolean IsAppWindow(window)
/* Check to see if a window belongs to a desk accessory. */
#pragma segment Main
Boolean IsDAWindow(window)
WindowPtr window;
{
@ -876,8 +858,6 @@ Boolean IsDAWindow(window)
return ((WindowPeek) window)->windowKind < 0;
} /*IsDAWindow*/
#pragma segment Initialize
Boolean TrapAvailable(tNumber,tType)
short tNumber;
TrapType tType;
@ -894,8 +874,6 @@ Boolean TrapAvailable(tNumber,tType)
return NGetTrapAddress(tNumber, tType) != GetTrapAddress(_Unimplemented);
} /*TrapAvailable*/
#pragma segment Main
void AlertUser() {
short itemHit;

View File

@ -162,7 +162,7 @@ resource 'MENU' (mHelp, preload) {
/* this ALRT and DITL are used as an About screen */
resource 'ALRT' (rAboutAlert, purgeable) {
{40, 20, 160, 412},
{40, 20, 194, 412},
rAboutAlert,
{ /* array: 4 elements */
/* [1] */
@ -180,31 +180,31 @@ resource 'ALRT' (rAboutAlert, purgeable) {
resource 'DITL' (rAboutAlert, purgeable) {
{ /* array DITLarray: 5 elements */
/* [1] */
{88, 380, 108, 260},
{119, 8, 138, 80},
Button {
enabled,
"OK"
},
/* [2] */
{8, 8, 24, 214},
{8, 8, 24, 264},
StaticText {
disabled,
"Messages for Macintosh"
},
/* [3] */
{32, 8, 48, 237},
{32, 8, 48, 267},
StaticText {
disabled,
"Copyright © 2021 Cameron Henlin"
"Copyright © 2021-22 Cameron Henlin"
},
/* [4] */
{56, 8, 72, 136},
{56, 8, 72, 166},
StaticText {
disabled,
"cam.henlin@gmail.com"
},
/* [5] */
{80, 24, 112, 167},
{80, 8, 112, 407},
StaticText {
disabled,
"https://github.com/CamHenlin/MessagesForMacintosh"

711
nuklear.h

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,7 @@
// TODO:
// - test, bug fixes, write blog posts
// - bug: messages start over-writing eachother in main chat -- need a way to force clear it
// - bug: delete key deletes infinitely
#define WINDOW_WIDTH 510
#define WINDOW_HEIGHT 302
@ -17,10 +19,71 @@
// #define MESSAGES_FOR_MACINTOSH_DEBUGGING
// based on https://github.com/jwerle/strsplit.c -- cleaned up and modified to use strtokm rather than strtok
int strsplit (const char *str, char *parts[], const char *delimiter) {
char *pch;
int i = 0;
char *copy = NULL;
char *tmp = NULL;
copy = strdup(str);
if (! copy) {
goto bad;
}
pch = strtokm(copy, delimiter);
tmp = strdup(pch);
if (!tmp) {
goto bad;
}
parts[i++] = tmp;
while (pch) {
pch = strtokm(NULL, delimiter);
if (NULL == pch) {
break;
}
tmp = strdup(pch);
if (! tmp) {
goto bad;
}
parts[i++] = tmp;
}
free(copy);
return i;
bad:
free(copy);
for (int j = 0; j < i; j++) {
free(parts[j]);
}
return -1;
}
void aFailed(char *file, int line) {
MoveTo(10, 10);
char *textoutput;
char textoutput[255];
sprintf(textoutput, "%s:%d", file, line);
writeSerialPortDebug(boutRefNum, "assertion failure");
writeSerialPortDebug(boutRefNum, textoutput);
@ -28,16 +91,7 @@ void aFailed(char *file, int line) {
while (true) {}
}
#define NK_ASSERT(e) \
if (!(e)) \
aFailed(__FILE__, __LINE__)
#include <Types.h>
#include "nuklear.h"
#include "nuklear_quickdraw.h"
#include "coprocessorjs.h"
#define MAX_CHAT_MESSAGES 16
#define MAX_CHAT_MESSAGES 17
Boolean firstOrMouseMove = true;
Boolean gotMouseEvent = false;
@ -46,10 +100,10 @@ char activeChatMessages[MAX_CHAT_MESSAGES][2048]; // this should match to MAX_RO
char box_input_buffer[2048];
char chatFriendlyNames[16][64];
char ip_input_buffer[255];
char jsFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE
char chatCountFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE
char tempChatCountFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE
char previousChatCountFunctionResponse[102400]; // Matches MAX_RECEIVE_SIZE
char jsFunctionResponse[32767]; // Matches MAX_RECEIVE_SIZE
char chatCountFunctionResponse[32767]; // Matches MAX_RECEIVE_SIZE
char tempChatCountFunctionResponse[32767]; // Matches MAX_RECEIVE_SIZE
char previousChatCountFunctionResponse[32767]; // Matches MAX_RECEIVE_SIZE
char new_message_input_buffer[255];
int activeMessageCounter = 0;
int chatFriendlyNamesCounter = 0;
@ -69,6 +123,15 @@ struct nk_rect message_input_window_size;
struct nk_rect messages_window_size;
struct nk_context *ctx;
#define NK_ASSERT(e) \
if (!(e)) \
aFailed(__FILE__, __LINE__)
#include <Types.h>
#include "nuklear.h"
#include "nuklear_quickdraw.h"
#include "coprocessorjs.h"
void refreshNuklearApp(Boolean blankInput);
void getMessagesFromjsFunctionResponse() {
@ -85,7 +148,7 @@ void getMessagesFromjsFunctionResponse() {
// loop through the string to extract all other tokens
while (token != NULL) {
sprintf(activeChatMessages[activeMessageCounter], "%s", token);
sprintf(activeChatMessages[activeMessageCounter], "%s", token);
token = (char *)strtokm(NULL, "ENDLASTMESSAGE");
activeMessageCounter++;
}
@ -96,11 +159,12 @@ void getMessagesFromjsFunctionResponse() {
// function to send messages in chat
void sendMessage() {
writeSerialPortDebug(boutRefNum, "sendMessage!");
char output[2048];
sprintf(output, "%s&&&%.*s", activeChat, box_input_len, box_input_buffer);
memset(&box_input_buffer, '\0', 2048);
sprintf(box_input_buffer, "");
box_input_len = 0;
refreshNuklearApp(1);
@ -135,6 +199,8 @@ void getChats() {
void sendIPAddressToCoprocessor() {
writeSerialPortDebug(boutRefNum, "sendIPAddressToCoprocessor!");
char output[2048];
sprintf(output, "%.*s", ip_input_buffer_len, ip_input_buffer);
@ -152,7 +218,9 @@ void sendIPAddressToCoprocessor() {
// figure out pagination?? button on the top that says "get previous chats"?
void getMessages(char *thread, int page) {
char output[62];
writeSerialPortDebug(boutRefNum, "getMessages!");
char output[68];
sprintf(output, "%s&&&%d", thread, page);
// writeSerialPortDebug(boutRefNum, output);
@ -172,11 +240,9 @@ Boolean prefix(const char *pre, const char *str) {
void getChatCounts() {
char output[62];
sprintf(output, "");
// writeSerialPortDebug(boutRefNum, output);
writeSerialPortDebug(boutRefNum, "getChatCounts!");
callFunctionOnCoprocessor("getChatCounts", output, chatCountFunctionResponse);
callFunctionOnCoprocessor("getChatCounts", "", chatCountFunctionResponse);
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "getChatCounts");
@ -191,27 +257,62 @@ void getChatCounts() {
#endif
SysBeep(1);
char *saveptr;
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
char *token = strtok_r(tempChatCountFunctionResponse, ",", &saveptr);
int chatCount = 0;
char *(*chats[16])[64];
chatCount = strsplit(tempChatCountFunctionResponse, chats, ",");
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "DUMMY DELETE: update current chat count loop");
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
#endif
}
// loop through the string to extract all other tokens
while (token != NULL) {
for (int chatLoopCounter = 0; chatLoopCounter < chatCount; chatLoopCounter++) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "update current chat count loop");
writeSerialPortDebug(boutRefNum, token);
writeSerialPortDebug(boutRefNum, chats[chatLoopCounter]);
#endif
// should be in format NAME:::COUNT
char *saveptr2;
char *name = strtok_r(token, ":::", &saveptr2);
char *countString = strtok_r(NULL, ":::", &saveptr2);
short count = atoi(countString);
// chats[chatLoopCounter] should be in format NAME:::COUNT
strcpy(tempChatCountFunctionResponse, chatCountFunctionResponse);
int results = 0;
char *(*chatUpdate[2])[64];
results = strsplit(chats[chatLoopCounter], chatUpdate, ":::");
if (results != 2) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "ERROR: chat update mismatch splitting on ':::', expected 2 results, got: %d: %s -- bailing out", results, chats[chatLoopCounter]);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < results; errorResultCounter++) {
writeSerialPortDebug(boutRefNum, chatUpdate[errorResultCounter]);
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, results, chatUpdate[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
short count = atoi(chatUpdate[1]);
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "name: %s, countString: %s, count: %d", name, countString, count);
sprintf(x, "name: %s, countString: %s, count: %d", chatUpdate[0], chatUpdate[1], count);
writeSerialPortDebug(boutRefNum, x);
#endif
@ -220,51 +321,64 @@ void getChatCounts() {
if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
char chatName[64];
sprintf(chatName, "%s", chatFriendlyNames[i]);
sprintf(chatName, "%.63s", chatFriendlyNames[i]);
// we are throwing out the first token
strtok_r(chatName, " new) ", &saveptr2);
int updateResults = 0;
char *(*updatePieces[2])[64];
char *tempChatFriendlyName = strtok_r(NULL, " new) ", &saveptr2);
updateResults = strsplit(chatName, updatePieces, " new) ");
if (prefix(tempChatFriendlyName, name)) {
if (updateResults != 2) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
char x[255];
sprintf(x, "ERROR: individual chat update mismatch splitting on ' new) ', expected 2 results, got: %d: %s -- bailing out", updateResults, chatName);
writeSerialPortDebug(boutRefNum, x);
for (int errorResultCounter = 0; errorResultCounter < updateResults; errorResultCounter++) {
char y[255];
sprintf(y, "%d/%d: '%s'", errorResultCounter, updateResults, updatePieces[errorResultCounter]);
writeSerialPortDebug(boutRefNum, y);
}
#endif
continue;
}
if (prefix(updatePieces[1], chatUpdate[0])) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match1");
writeSerialPortDebug(boutRefNum, name);
writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif
if (count == 0) {
if (count == 0 || !strcmp(activeChat, chatUpdate[0])) {
sprintf(chatFriendlyNames[i], "%s", name);
sprintf(chatFriendlyNames[i], "%s", chatUpdate[0]);
} else {
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
sprintf(chatFriendlyNames[i], "(%d new) %s", count, chatUpdate[0]);
}
break;
}
} else {
} else if (prefix(chatFriendlyNames[i], chatUpdate[0])) {
if (prefix(chatFriendlyNames[i], name)) {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match2");
writeSerialPortDebug(boutRefNum, chatUpdate[0]);
#endif
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "match2");
writeSerialPortDebug(boutRefNum, name);
#endif
if (count == 0 || !strcmp(activeChat, chatUpdate[0])) {
if (count == 0) {
sprintf(chatFriendlyNames[i], "%s", chatUpdate[0]);
} else {
sprintf(chatFriendlyNames[i], "%s", name);
} else {
sprintf(chatFriendlyNames[i], "(%d new) %s", count, name);
}
break;
sprintf(chatFriendlyNames[i], "(%d new) %s", count, chatUpdate[0]);
}
break;
}
}
token = strtok_r(NULL, ",", &saveptr);
}
strcpy(previousChatCountFunctionResponse, chatCountFunctionResponse);
@ -279,7 +393,9 @@ void getChatCounts() {
void getHasNewMessagesInChat(char *thread) {
char output[62];
writeSerialPortDebug(boutRefNum, "getHasNewMessagesInChat!");
char output[68];
sprintf(output, "%s", thread);
// writeSerialPortDebug(boutRefNum, output);
@ -288,12 +404,15 @@ void getHasNewMessagesInChat(char *thread) {
if (!strcmp(jsFunctionResponse, "true")) {
// writeSerialPortDebug(boutRefNum, "update current chat");
writeSerialPortDebug(boutRefNum, "update current chat");
SysBeep(1);
getMessages(thread, 0);
// force redraw
forceRedraw = 3;
} else {
writeSerialPortDebug(boutRefNum, "do not update current chat");
}
return;
@ -376,7 +495,7 @@ static void nuklearApp(struct nk_context *ctx) {
return;
}
// prompt the user for new chat
// prompt the user for new chat
if (sendNewChat) {
if (nk_begin_titled(ctx, "Enter New Message Recipient", "Enter New Message Recipient", nk_rect(50, WINDOW_HEIGHT / 4, WINDOW_WIDTH - 100, 140), NK_WINDOW_TITLE|NK_WINDOW_BORDER)) {
@ -423,11 +542,6 @@ static void nuklearApp(struct nk_context *ctx) {
if ((chatWindowCollision || forceRedraw) && nk_begin(ctx, "Chats", chats_window_size, NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) {
if (chatWindowCollision) {
forceRedraw = 2;
}
nk_layout_row_begin(ctx, NK_STATIC, 25, 1);
{
for (int i = 0; i < chatFriendlyNamesCounter; i++) {
@ -445,7 +559,7 @@ static void nuklearApp(struct nk_context *ctx) {
if (strstr(chatFriendlyNames[i], " new) ") != NULL) {
char chatName[96];
sprintf(chatName, "%s", chatFriendlyNames[i]);
sprintf(chatName, "%.63s", chatFriendlyNames[i]);
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
writeSerialPortDebug(boutRefNum, "clicked1 chatName");
@ -467,8 +581,8 @@ static void nuklearApp(struct nk_context *ctx) {
writeSerialPortDebug(boutRefNum, name);
#endif
sprintf(activeChat, "%s", name);
sprintf(chatFriendlyNames[i], "%s", name);
sprintf(activeChat, "%.63s", name);
sprintf(chatFriendlyNames[i], "%.63s", name);
} else {
#ifdef MESSAGES_FOR_MACINTOSH_DEBUGGING
@ -476,7 +590,7 @@ static void nuklearApp(struct nk_context *ctx) {
writeSerialPortDebug(boutRefNum, chatFriendlyNames[i]);
#endif
sprintf(activeChat, "%s", chatFriendlyNames[i]);
sprintf(activeChat, "%.63s", chatFriendlyNames[i]);
}
getMessages(activeChat, 0);
@ -517,6 +631,8 @@ static void nuklearApp(struct nk_context *ctx) {
nk_layout_row_push(ctx, 305);
// writeSerialPortDebug(boutRefNum, "activeChatMessages[i]");
// writeSerialPortDebug(boutRefNum, activeChatMessages[i]);
nk_label(ctx, activeChatMessages[i], NK_TEXT_ALIGN_LEFT);
}
}
@ -550,8 +666,8 @@ void refreshNuklearApp(Boolean blankInput) {
struct nk_context* initializeNuklearApp() {
sprintf(activeChat, "no active chat");
memset(&chatCountFunctionResponse, '\0', 102400);
memset(&previousChatCountFunctionResponse, '\0', 102400);
memset(&chatCountFunctionResponse, '\0', 32767);
memset(&previousChatCountFunctionResponse, '\0', 32767);
graphql_input_window_size = nk_rect(WINDOW_WIDTH / 2 - 118, 80, 234, 100);
chats_window_size = nk_rect(0, 0, 180, WINDOW_HEIGHT);
@ -562,6 +678,7 @@ struct nk_context* initializeNuklearApp() {
refreshNuklearApp(false);
sprintf(ip_input_buffer, "http://"); // doesn't work due to bug, see variable definition
ip_input_buffer_len = 7;
return ctx;
}

View File

@ -49,7 +49,7 @@ NK_API NkQuickDrawFont* nk_quickdraw_font_create_from_file();
*
* ===============================================================
*/
#define MAX_MEMORY_IN_KB 4
#define MAX_MEMORY_IN_KB 6
#ifdef NK_QUICKDRAW_IMPLEMENTATION
#ifndef NK_QUICKDRAW_TEXT_MAX
#define NK_QUICKDRAW_TEXT_MAX 256
@ -476,8 +476,6 @@ void updateBounds(int top, int bottom, int left, int right) {
void runDrawCommand(const struct nk_command *cmd) {
#endif
int color;
switch (cmd->type) {
case NK_COMMAND_NOP:
@ -541,7 +539,7 @@ void updateBounds(int top, int bottom, int left, int right) {
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_rect");
@ -594,7 +592,7 @@ void updateBounds(int top, int bottom, int left, int right) {
}
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect_filled)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(r, lastCmd, sizeof(struct nk_command_rect_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_rect_filled");
@ -631,7 +629,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_text *t = (const struct nk_command_text*)cmd;
#ifdef COMMAND_CACHING
if (t->allowCache && cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_text)) == 0) {
if (!forceRedraw && t->allowCache && cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_text)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
char log[255];
@ -685,7 +683,7 @@ void updateBounds(int top, int bottom, int left, int right) {
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(l, lastCmd, sizeof(struct nk_command_line)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(l, lastCmd, sizeof(struct nk_command_line)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_line");
@ -713,7 +711,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_circle *c = (const struct nk_command_circle *)cmd;
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(c, lastCmd, sizeof(struct nk_command_circle)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(c, lastCmd, sizeof(struct nk_command_circle)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_circle");
@ -748,7 +746,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd;
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(c, lastCmd, sizeof(struct nk_command_circle_filled)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(c, lastCmd, sizeof(struct nk_command_circle_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_circle_filled");
@ -787,7 +785,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_triangle *t = (const struct nk_command_triangle*)cmd;
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_triangle)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_triangle)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_triangle");
@ -817,7 +815,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled *)cmd;
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_triangle_filled)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(t, lastCmd, sizeof(struct nk_command_triangle_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_triangle_filled");
@ -853,7 +851,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_polygon *p = (const struct nk_command_polygon*)cmd;
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_polygon");
@ -893,7 +891,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled*)cmd;
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon_filled)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon_filled)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_polygon_filled");
@ -942,7 +940,7 @@ void updateBounds(int top, int bottom, int left, int right) {
const struct nk_command_polygon *p = (const struct nk_command_polygon*)cmd;
#ifdef COMMAND_CACHING
if (cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon)) == 0) {
if (!forceRedraw && cmd->type == lastCmd->type && memcmp(p, lastCmd, sizeof(struct nk_command_polygon)) == 0) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "ALREADY DREW CMD nk_command_polygon");
@ -1016,7 +1014,7 @@ void updateBounds(int top, int bottom, int left, int right) {
writeSerialPortDebug(boutRefNum, "NK_COMMAND_IMAGE");
#endif
const struct nk_command_image *i = (const struct nk_command_image *)cmd;
// const struct nk_command_image *i = (const struct nk_command_image *)cmd;
// al_draw_bitmap_region(i->img.handle.ptr, 0, 0, i->w, i->h, i->x, i->y, 0); // TODO: look up and convert al_draw_bitmap_region
// TODO: consider implementing a bitmap drawing routine. we could iterate pixel by pixel and draw
// here is some super naive code that could work, used for another project that i was working on with a custom format but would be
@ -1082,7 +1080,7 @@ NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) {
#ifdef NK_QUICKDRAW_GRAPHICS_DEBUGGING
writeSerialPortDebug(boutRefNum, "NK_COMMAND_NOP");
writeSerialPortDebug(boutRefNum, "NO RENDER BUFFER CHANGE, ABORT");
#endif
return;
@ -1106,7 +1104,6 @@ NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) {
#ifdef COMMAND_CACHING
const struct nk_command *lastCmd;
nk_byte *buffer;
lastCmd = nk_ptr_add_const(struct nk_command, last, 0);
#endif
@ -1325,9 +1322,10 @@ NK_API int nk_quickdraw_handle_event(EventRecord *event, struct nk_context *nukl
} else if (key == eitherShiftKey) {
nk_input_key(nuklear_context, NK_KEY_SHIFT, isKeyDown);
} else if (key == deleteKey) {
} else if (key == deleteKey && isKeyDown) {
nk_input_key(nuklear_context, NK_KEY_DEL, isKeyDown);
nk_input_key(nuklear_context, NK_KEY_DEL, 1);
nk_input_key(nuklear_context, NK_KEY_DEL, 0);
} else if (key == enterKey) {
nk_input_key(nuklear_context, NK_KEY_ENTER, isKeyDown);
@ -1398,6 +1396,8 @@ NK_API int nk_quickdraw_handle_event(EventRecord *event, struct nk_context *nukl
break;
}
}
return 1;
}
// i think these functions are close to correct, but throw an error around invalid storage class