mirror of
https://github.com/pdxlocations/contact.git
synced 2026-03-28 17:12:35 +01:00
Compare commits
18 Commits
client-dev
...
fix-startu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08f19e653a | ||
|
|
6e05446d6a | ||
|
|
a0cb4f9480 | ||
|
|
89d5890338 | ||
|
|
a645e41146 | ||
|
|
aa736472cc | ||
|
|
4dc1b4b791 | ||
|
|
41050577aa | ||
|
|
d9c249af56 | ||
|
|
ad64004e79 | ||
|
|
d9a84c4b29 | ||
|
|
6cf46a202a | ||
|
|
351f4d7f8f | ||
|
|
5f0277c460 | ||
|
|
f34db01a78 | ||
|
|
463b655684 | ||
|
|
14aa5c00a3 | ||
|
|
a201bcccb2 |
@@ -144,6 +144,7 @@ def load_messages_from_db():
|
|||||||
|
|
||||||
def init_nodedb():
|
def init_nodedb():
|
||||||
"""Initialize the node database and update it with nodes from the interface."""
|
"""Initialize the node database and update it with nodes from the interface."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not globals.interface.nodes:
|
if not globals.interface.nodes:
|
||||||
return # No nodes to initialize
|
return # No nodes to initialize
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ selected_channel = 0
|
|||||||
selected_message = 0
|
selected_message = 0
|
||||||
selected_node = 0
|
selected_node = 0
|
||||||
current_window = 0
|
current_window = 0
|
||||||
|
lock = None
|
||||||
22
main.py
22
main.py
@@ -11,6 +11,7 @@ from pubsub import pub
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
import threading
|
||||||
|
|
||||||
from utilities.arg_parser import setup_parser
|
from utilities.arg_parser import setup_parser
|
||||||
from utilities.interfaces import initialize_interface
|
from utilities.interfaces import initialize_interface
|
||||||
@@ -38,6 +39,8 @@ logging.basicConfig(
|
|||||||
format="%(asctime)s - %(levelname)s - %(message)s"
|
format="%(asctime)s - %(levelname)s - %(message)s"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
globals.lock = threading.Lock()
|
||||||
|
|
||||||
def main(stdscr):
|
def main(stdscr):
|
||||||
try:
|
try:
|
||||||
draw_splash(stdscr)
|
draw_splash(stdscr)
|
||||||
@@ -45,15 +48,16 @@ def main(stdscr):
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
logging.info("Initializing interface %s", args)
|
logging.info("Initializing interface %s", args)
|
||||||
globals.interface = initialize_interface(args)
|
with globals.lock:
|
||||||
logging.info("Interface initialized")
|
globals.interface = initialize_interface(args)
|
||||||
globals.myNodeNum = get_nodeNum()
|
logging.info("Interface initialized")
|
||||||
globals.channel_list = get_channels()
|
globals.myNodeNum = get_nodeNum()
|
||||||
globals.node_list = get_node_list()
|
globals.channel_list = get_channels()
|
||||||
pub.subscribe(on_receive, 'meshtastic.receive')
|
globals.node_list = get_node_list()
|
||||||
init_nodedb()
|
pub.subscribe(on_receive, 'meshtastic.receive')
|
||||||
load_messages_from_db()
|
init_nodedb()
|
||||||
logging.info("Starting main UI")
|
load_messages_from_db()
|
||||||
|
logging.info("Starting main UI")
|
||||||
main_ui(stdscr)
|
main_ui(stdscr)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("An error occurred: %s", e)
|
logging.error("An error occurred: %s", e)
|
||||||
|
|||||||
@@ -12,93 +12,94 @@ from datetime import datetime
|
|||||||
|
|
||||||
def on_receive(packet, interface):
|
def on_receive(packet, interface):
|
||||||
|
|
||||||
# Update packet log
|
with globals.lock:
|
||||||
globals.packet_buffer.append(packet)
|
# Update packet log
|
||||||
if len(globals.packet_buffer) > 20:
|
globals.packet_buffer.append(packet)
|
||||||
# Trim buffer to 20 packets
|
if len(globals.packet_buffer) > 20:
|
||||||
globals.packet_buffer = globals.packet_buffer[-20:]
|
# Trim buffer to 20 packets
|
||||||
|
globals.packet_buffer = globals.packet_buffer[-20:]
|
||||||
|
|
||||||
if globals.display_log:
|
if globals.display_log:
|
||||||
draw_packetlog_win()
|
draw_packetlog_win()
|
||||||
try:
|
try:
|
||||||
if 'decoded' not in packet:
|
if 'decoded' not in packet:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Assume any incoming packet could update the last seen time for a node
|
# Assume any incoming packet could update the last seen time for a node
|
||||||
changed = refresh_node_list()
|
changed = refresh_node_list()
|
||||||
if(changed):
|
if(changed):
|
||||||
draw_node_list()
|
draw_node_list()
|
||||||
|
|
||||||
if packet['decoded']['portnum'] == 'NODEINFO_APP':
|
if packet['decoded']['portnum'] == 'NODEINFO_APP':
|
||||||
if "user" in packet['decoded'] and "longName" in packet['decoded']["user"]:
|
if "user" in packet['decoded'] and "longName" in packet['decoded']["user"]:
|
||||||
maybe_store_nodeinfo_in_db(packet)
|
maybe_store_nodeinfo_in_db(packet)
|
||||||
|
|
||||||
elif packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
|
elif packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
|
||||||
message_bytes = packet['decoded']['payload']
|
message_bytes = packet['decoded']['payload']
|
||||||
message_string = message_bytes.decode('utf-8')
|
message_string = message_bytes.decode('utf-8')
|
||||||
|
|
||||||
refresh_channels = False
|
refresh_channels = False
|
||||||
refresh_messages = False
|
refresh_messages = False
|
||||||
|
|
||||||
if packet.get('channel'):
|
if packet.get('channel'):
|
||||||
channel_number = packet['channel']
|
channel_number = packet['channel']
|
||||||
else:
|
|
||||||
channel_number = 0
|
|
||||||
|
|
||||||
if packet['to'] == globals.myNodeNum:
|
|
||||||
if packet['from'] in globals.channel_list:
|
|
||||||
pass
|
|
||||||
else:
|
else:
|
||||||
globals.channel_list.append(packet['from'])
|
channel_number = 0
|
||||||
if(packet['from'] not in globals.all_messages):
|
|
||||||
globals.all_messages[packet['from']] = []
|
if packet['to'] == globals.myNodeNum:
|
||||||
update_node_info_in_db(packet['from'], chat_archived=False)
|
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
|
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]:
|
if globals.channel_list[channel_number] not in globals.all_messages:
|
||||||
add_notification(channel_number)
|
globals.all_messages[globals.channel_list[channel_number]] = []
|
||||||
refresh_channels = True
|
|
||||||
else:
|
|
||||||
refresh_messages = True
|
|
||||||
|
|
||||||
# Add received message to the messages list
|
# Timestamp handling
|
||||||
message_from_id = packet['from']
|
current_timestamp = time.time()
|
||||||
message_from_string = get_name_from_database(message_from_id, type='short') + ":"
|
current_hour = datetime.fromtimestamp(current_timestamp).strftime('%Y-%m-%d %H:00')
|
||||||
|
|
||||||
if globals.channel_list[channel_number] not in globals.all_messages:
|
# Retrieve the last timestamp if available
|
||||||
globals.all_messages[globals.channel_list[channel_number]] = []
|
channel_messages = globals.all_messages[globals.channel_list[channel_number]]
|
||||||
|
if channel_messages:
|
||||||
# Timestamp handling
|
# Check the last entry for a timestamp
|
||||||
current_timestamp = time.time()
|
for entry in reversed(channel_messages):
|
||||||
current_hour = datetime.fromtimestamp(current_timestamp).strftime('%Y-%m-%d %H:00')
|
if entry[0].startswith("--"):
|
||||||
|
last_hour = entry[0].strip("- ").strip()
|
||||||
# Retrieve the last timestamp if available
|
break
|
||||||
channel_messages = globals.all_messages[globals.channel_list[channel_number]]
|
else:
|
||||||
if channel_messages:
|
last_hour = None
|
||||||
# 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:
|
else:
|
||||||
last_hour = None
|
last_hour = None
|
||||||
else:
|
|
||||||
last_hour = None
|
|
||||||
|
|
||||||
# Add a new timestamp if it's a new hour
|
# Add a new timestamp if it's a new hour
|
||||||
if last_hour != current_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"-- {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:
|
if refresh_channels:
|
||||||
draw_channel_list()
|
draw_channel_list()
|
||||||
if refresh_messages:
|
if refresh_messages:
|
||||||
draw_messages_window(True)
|
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:
|
except KeyError as e:
|
||||||
logging.error(f"Error processing packet: {e}")
|
logging.error(f"Error processing packet: {e}")
|
||||||
|
|||||||
@@ -417,8 +417,11 @@ def draw_messages_window(scroll_to_bottom = False):
|
|||||||
def draw_node_list():
|
def draw_node_list():
|
||||||
global nodes_pad
|
global nodes_pad
|
||||||
|
|
||||||
if nodes_pad is None:
|
# This didn't work, for some reason an error is thown on startup, so we just create the pad every time
|
||||||
nodes_pad = curses.newpad(1, 1)
|
# if nodes_pad is None:
|
||||||
|
# nodes_pad = curses.newpad(1, 1)
|
||||||
|
nodes_pad = curses.newpad(1, 1)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nodes_pad.erase()
|
nodes_pad.erase()
|
||||||
|
|||||||
Reference in New Issue
Block a user