Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 66 additions & 42 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ tauri-plugin-store = "2"
tokio-serial = "5.4.4"
tauri-plugin-log = { features = ["colored"] , version = "2" }
chrono = { version = "0.4.34", features = ["serde"] }
meshtastic = { git = "https://github.com/meshtastic/rust.git", rev = "6057294aa6cfa979033299f7f02cfe6ceafddeda", features = ["ts-gen", "bluetooth-le"] }
specta = { git = "https://github.com/ajmcquilkin/specta.git", rev = "6a8731d168376e28e163dd9cd328055b11d1af82", version = "1.0.3", features = ["chrono"] }
tauri-plugin-dialog = "2"
tauri-plugin-shell = "2"
Expand All @@ -48,6 +47,7 @@ tauri-plugin-http = "2"
tauri-plugin-cli = "2"
btleplug = "0.11.8"
uuid = "1.17.0"
meshtastic = { version = "0.1.7", features = ["bluetooth-le", "gen", "ts-gen"] }

[features]
# by default Tauri runs in production mode
Expand Down
3 changes: 0 additions & 3 deletions src-tauri/src/api/primitives/radio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
use serde::{Deserialize, Serialize};
use specta::Type;

// Re-export types from meshtastic protobufs
pub use meshtastic::protobufs::{Config, User};
20 changes: 0 additions & 20 deletions src-tauri/src/device/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use rand::{distributions::Standard, prelude::Distribution, Rng};
use std::time::UNIX_EPOCH;

use super::MeshDevice;

pub fn get_current_time_u32() -> u32 {
std::time::SystemTime::now()
.duration_since(UNIX_EPOCH)
Expand All @@ -20,24 +18,6 @@ where
rng.gen::<T>()
}

pub fn get_node_user_name(device: &mut MeshDevice, node_id: &u32) -> Option<String> {
let db_node = device.nodes.get(node_id)?;
let db_user = db_node.user.as_ref()?;

Some(db_user.long_name.clone())
}

pub fn get_channel_name(device: &mut MeshDevice, channel_id: &u32) -> Option<String> {
let db_channel = device.channels.get(channel_id)?;
let db_channel_settings = db_channel.config.settings.as_ref()?;

if db_channel_settings.name.is_empty() {
return format!("Channel {}", db_channel.config.index).into();
}

Some(db_channel_settings.name.clone())
}

/// Converts a mesh location field (e.g., latitude) from
/// its mesh integer representation to a float.
///
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ impl From<protobufs::Position> for NormalizedPosition {
longitude: normalize_location_field(position.longitude_i.unwrap_or_default()),
altitude: position.altitude.unwrap_or_default(),
time: position.time,
location_source: protobufs::position::LocSource::from_i32(position.location_source)
location_source: protobufs::position::LocSource::try_from(position.location_source)
.expect("Could not convert i32 to LocSource"),
altitude_source: protobufs::position::AltSource::from_i32(position.altitude_source)
altitude_source: protobufs::position::AltSource::try_from(position.altitude_source)
.expect("Could not convert i32 to AltSource"),
timestamp: position.timestamp,
timestamp_millis_adjust: position.timestamp_millis_adjust,
Expand Down
5 changes: 2 additions & 3 deletions src-tauri/src/domains/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ use crate::api::contracts::mesh::SendTextResponse;
use crate::api::contracts::mesh::SendWaypointRequest;
use crate::api::contracts::mesh::SendWaypointResponse;
use crate::device::helpers::convert_location_field_to_protos;
use crate::device::NormalizedWaypoint;
use crate::ipc::events;
use crate::ipc::CommandError;
use crate::state::{self, DeviceKey};
use crate::state;

use log::{debug, trace};
use log::trace;
use meshtastic::packet::PacketDestination;
use meshtastic::protobufs;
use meshtastic::types::MeshChannel;
Expand Down
2 changes: 0 additions & 2 deletions src-tauri/src/ipc/commands/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ use crate::domains::radio::{
handle_commit_configuration_transaction, handle_start_configuration_transaction,
handle_update_device_config, handle_update_device_config_bulk, handle_update_device_user,
};
use crate::ipc::events;
use crate::ipc::CommandError;
use crate::state;

use log::debug;
use log::trace;

#[tauri::command]
pub async fn update_device_config(
Expand Down
14 changes: 1 addition & 13 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,10 @@ mod ipc;
mod packet_api;
mod state;

use log::{info, LevelFilter};
use specta::{
export::ts_with_cfg,
ts::{BigIntExportBehavior, ExportConfiguration, ModuleExportBehavior, TsExportError},
};
use log::LevelFilter;
use tauri::Manager;
use tauri_plugin_log::{fern::colors::ColoredLevelConfig, Target, TargetKind};

fn export_ts_types(file_path: &str) -> Result<(), TsExportError> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did your PR #533 fix #505? I left this here with the intention of re-enabling later, but I'm fine with removing this.

let ts_export_config = ExportConfiguration::default()
.bigint(BigIntExportBehavior::String)
.modules(ModuleExportBehavior::Enabled);

ts_with_cfg(file_path, &ts_export_config)
}

const LOG_LEVEL: LevelFilter = LevelFilter::Debug;

#[cfg_attr(mobile, tauri::mobile_entry_point)]
Expand Down
18 changes: 2 additions & 16 deletions src-tauri/src/packet_api/handlers/mesh_packet/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use log::debug;
use meshtastic::protobufs;
use tauri_plugin_notification::Notification;

use crate::{
device::{
helpers::{get_channel_name, get_node_user_name},
ChannelMessageState, NeighborInfoPacket, NormalizedWaypoint, PositionPacket,
TelemetryPacket, TextPacket, UserPacket, WaypointPacket,
},
Expand Down Expand Up @@ -39,7 +37,7 @@ pub fn handle_position_mesh_packet<R: tauri::Runtime>(

packet_api.device.add_position(PositionPacket {
packet: packet.clone(),
data: data.clone(),
data, // Implements `Copy`
});

let mut graph = packet_api
Expand Down Expand Up @@ -68,7 +66,7 @@ pub fn handle_routing_mesh_packet<R: tauri::Runtime>(
if let Some(variant) = routing_data.variant {
match variant {
protobufs::routing::Variant::ErrorReason(e) => {
if let Some(r) = protobufs::routing::Error::from_i32(e) {
if let Ok(r) = protobufs::routing::Error::try_from(e) {
match r {
protobufs::routing::Error::None => {
packet_api.device.set_message_state(
Expand Down Expand Up @@ -161,12 +159,6 @@ pub fn handle_text_message_mesh_packet<R: tauri::Runtime>(
data: data.clone(),
});

let from_user_name = get_node_user_name(&mut packet_api.device, &packet.from)
.unwrap_or_else(|| packet.from.to_string());

let channel_name = get_channel_name(&mut packet_api.device, &packet.channel)
.unwrap_or_else(|| "Unknown channel".into());

// Always keep updates at bottom in case of failure during functions
events::dispatch_updated_device(&packet_api.app_handle, &packet_api.device)
.map_err(|e| DeviceUpdateError::EventDispatchFailure(e.to_string()))?;
Expand Down Expand Up @@ -207,12 +199,6 @@ pub fn handle_waypoint_mesh_packet<R: tauri::Runtime>(
data: converted_data.clone(),
});

let from_user_name = get_node_user_name(&mut packet_api.device, &packet.from)
.unwrap_or_else(|| packet.from.to_string());

let channel_name = get_channel_name(&mut packet_api.device, &packet.channel)
.unwrap_or_else(|| "Unknown channel".into());

events::dispatch_updated_device(&packet_api.app_handle, &packet_api.device)
.map_err(|e| DeviceUpdateError::EventDispatchFailure(e.to_string()))?;

Expand Down
Loading