1
0
forked from iarv/contact

Compare commits

...

18 Commits

Author SHA1 Message Date
pdxlocations
08f19e653a add note in draw_node_list 2025-02-09 20:46:55 -08:00
pdxlocations
6e05446d6a Merge branch 'main' into fix-startup-error 2025-02-09 06:45:53 -08:00
pdxlocations
a0cb4f9480 sir locks a lilttle less 2025-02-08 21:07:54 -08:00
pdxlocations
89d5890338 sir locks a lot 2025-02-08 21:04:51 -08:00
pdxlocations
a645e41146 lock it down 2025-02-08 18:07:12 -08:00
pdxlocations
aa736472cc fix conflict 2025-02-08 18:02:49 -08:00
pdxlocations
4dc1b4b791 try a threading lock 2025-02-08 18:02:25 -08:00
pdxlocations
41050577aa Merge branch 'main' into fix-startup-error 2025-02-08 15:57:46 -08:00
pdxlocations
d9c249af56 db snapshot 2025-02-08 14:21:44 -08:00
pdxlocations
ad64004e79 back up 2025-02-08 13:25:27 -08:00
pdxlocations
d9a84c4b29 more global 2025-02-08 13:19:48 -08:00
pdxlocations
6cf46a202a grasping at straws 2025-02-08 11:48:07 -08:00
pdxlocations
351f4d7f8f less is more 2025-02-08 08:38:35 -08:00
pdxlocations
5f0277c460 refactor 2025-02-08 08:29:57 -08:00
pdxlocations
f34db01a78 typo 2025-02-08 08:04:52 -08:00
pdxlocations
463b655684 more checks 2025-02-08 08:03:59 -08:00
pdxlocations
14aa5c00a3 none isn't better than nothing 2025-02-08 08:00:20 -08:00
pdxlocations
a201bcccb2 more excuses 2025-02-08 07:57:09 -08:00
5 changed files with 94 additions and 84 deletions

View File

@@ -144,6 +144,7 @@ def load_messages_from_db():
def init_nodedb():
"""Initialize the node database and update it with nodes from the interface."""
try:
if not globals.interface.nodes:
return # No nodes to initialize

View File

@@ -9,4 +9,5 @@ myNodeNum = 0
selected_channel = 0
selected_message = 0
selected_node = 0
current_window = 0
current_window = 0
lock = None

22
main.py
View File

@@ -11,6 +11,7 @@ from pubsub import pub
import os
import logging
import traceback
import threading
from utilities.arg_parser import setup_parser
from utilities.interfaces import initialize_interface
@@ -38,6 +39,8 @@ logging.basicConfig(
format="%(asctime)s - %(levelname)s - %(message)s"
)
globals.lock = threading.Lock()
def main(stdscr):
try:
draw_splash(stdscr)
@@ -45,15 +48,16 @@ def main(stdscr):
args = parser.parse_args()
logging.info("Initializing interface %s", args)
globals.interface = initialize_interface(args)
logging.info("Interface initialized")
globals.myNodeNum = get_nodeNum()
globals.channel_list = get_channels()
globals.node_list = get_node_list()
pub.subscribe(on_receive, 'meshtastic.receive')
init_nodedb()
load_messages_from_db()
logging.info("Starting main UI")
with globals.lock:
globals.interface = initialize_interface(args)
logging.info("Interface initialized")
globals.myNodeNum = get_nodeNum()
globals.channel_list = get_channels()
globals.node_list = get_node_list()
pub.subscribe(on_receive, 'meshtastic.receive')
init_nodedb()
load_messages_from_db()
logging.info("Starting main UI")
main_ui(stdscr)
except Exception as e:
logging.error("An error occurred: %s", e)

View File

@@ -12,93 +12,94 @@ from datetime import datetime
def on_receive(packet, interface):
# Update packet log
globals.packet_buffer.append(packet)
if len(globals.packet_buffer) > 20:
# Trim buffer to 20 packets
globals.packet_buffer = globals.packet_buffer[-20:]
if globals.display_log:
draw_packetlog_win()
try:
if 'decoded' not in packet:
return
with globals.lock:
# Update packet log
globals.packet_buffer.append(packet)
if len(globals.packet_buffer) > 20:
# Trim buffer to 20 packets
globals.packet_buffer = globals.packet_buffer[-20:]
if globals.display_log:
draw_packetlog_win()
try:
if 'decoded' not in packet:
return
# Assume any incoming packet could update the last seen time for a node
changed = refresh_node_list()
if(changed):
draw_node_list()
# Assume any incoming packet could update the last seen time for a node
changed = refresh_node_list()
if(changed):
draw_node_list()
if packet['decoded']['portnum'] == 'NODEINFO_APP':
if "user" in packet['decoded'] and "longName" in packet['decoded']["user"]:
maybe_store_nodeinfo_in_db(packet)
if packet['decoded']['portnum'] == 'NODEINFO_APP':
if "user" in packet['decoded'] and "longName" in packet['decoded']["user"]:
maybe_store_nodeinfo_in_db(packet)
elif packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
message_bytes = packet['decoded']['payload']
message_string = message_bytes.decode('utf-8')
elif packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
message_bytes = packet['decoded']['payload']
message_string = message_bytes.decode('utf-8')
refresh_channels = False
refresh_messages = False
refresh_channels = False
refresh_messages = False
if packet.get('channel'):
channel_number = packet['channel']
else:
channel_number = 0
if packet['to'] == globals.myNodeNum:
if packet['from'] in globals.channel_list:
pass
if packet.get('channel'):
channel_number = packet['channel']
else:
globals.channel_list.append(packet['from'])
if(packet['from'] not in globals.all_messages):
globals.all_messages[packet['from']] = []
update_node_info_in_db(packet['from'], chat_archived=False)
channel_number = 0
if packet['to'] == globals.myNodeNum:
if packet['from'] in globals.channel_list:
pass
else:
globals.channel_list.append(packet['from'])
if(packet['from'] not in globals.all_messages):
globals.all_messages[packet['from']] = []
update_node_info_in_db(packet['from'], chat_archived=False)
refresh_channels = True
channel_number = globals.channel_list.index(packet['from'])
if globals.channel_list[channel_number] != globals.channel_list[globals.selected_channel]:
add_notification(channel_number)
refresh_channels = True
else:
refresh_messages = True
channel_number = globals.channel_list.index(packet['from'])
# Add received message to the messages list
message_from_id = packet['from']
message_from_string = get_name_from_database(message_from_id, type='short') + ":"
if globals.channel_list[channel_number] != globals.channel_list[globals.selected_channel]:
add_notification(channel_number)
refresh_channels = True
else:
refresh_messages = True
if globals.channel_list[channel_number] not in globals.all_messages:
globals.all_messages[globals.channel_list[channel_number]] = []
# Add received message to the messages list
message_from_id = packet['from']
message_from_string = get_name_from_database(message_from_id, type='short') + ":"
# Timestamp handling
current_timestamp = time.time()
current_hour = datetime.fromtimestamp(current_timestamp).strftime('%Y-%m-%d %H:00')
if globals.channel_list[channel_number] not in globals.all_messages:
globals.all_messages[globals.channel_list[channel_number]] = []
# Timestamp handling
current_timestamp = time.time()
current_hour = datetime.fromtimestamp(current_timestamp).strftime('%Y-%m-%d %H:00')
# Retrieve the last timestamp if available
channel_messages = globals.all_messages[globals.channel_list[channel_number]]
if channel_messages:
# Check the last entry for a timestamp
for entry in reversed(channel_messages):
if entry[0].startswith("--"):
last_hour = entry[0].strip("- ").strip()
break
# Retrieve the last timestamp if available
channel_messages = globals.all_messages[globals.channel_list[channel_number]]
if channel_messages:
# Check the last entry for a timestamp
for entry in reversed(channel_messages):
if entry[0].startswith("--"):
last_hour = entry[0].strip("- ").strip()
break
else:
last_hour = None
else:
last_hour = None
else:
last_hour = None
# Add a new timestamp if it's a new hour
if last_hour != current_hour:
globals.all_messages[globals.channel_list[channel_number]].append((f"-- {current_hour} --", ""))
# Add a new timestamp if it's a new hour
if last_hour != current_hour:
globals.all_messages[globals.channel_list[channel_number]].append((f"-- {current_hour} --", ""))
globals.all_messages[globals.channel_list[channel_number]].append((f"{config.message_prefix} {message_from_string} ", message_string))
globals.all_messages[globals.channel_list[channel_number]].append((f"{config.message_prefix} {message_from_string} ", message_string))
if refresh_channels:
draw_channel_list()
if refresh_messages:
draw_messages_window(True)
if refresh_channels:
draw_channel_list()
if refresh_messages:
draw_messages_window(True)
save_message_to_db(globals.channel_list[channel_number], message_from_id, message_string)
save_message_to_db(globals.channel_list[channel_number], message_from_id, message_string)
except KeyError as e:
logging.error(f"Error processing packet: {e}")
except KeyError as e:
logging.error(f"Error processing packet: {e}")

View File

@@ -417,9 +417,12 @@ def draw_messages_window(scroll_to_bottom = False):
def draw_node_list():
global nodes_pad
if nodes_pad is None:
nodes_pad = curses.newpad(1, 1)
# This didn't work, for some reason an error is thown on startup, so we just create the pad every time
# if nodes_pad is None:
# nodes_pad = curses.newpad(1, 1)
nodes_pad = curses.newpad(1, 1)
try:
nodes_pad.erase()
box_width = nodes_win.getmaxyx()[1]