Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add flutter-dart #327

Merged
merged 3 commits into from
May 21, 2024
Merged
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
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ filesync

*/target


target
Cargo.lock
3 changes: 0 additions & 3 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
{
"recommendations": ["tauri-apps.tauri-vscode", "rust-lang.rust-analyzer"]
}
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[workspace]
members = ["./desktop/core"]
4 changes: 3 additions & 1 deletion desktop/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sysinfo = "0.29.2"
tauri = {version = "1.2", features = [ "clipboard-write-text", "window-all", "app-all", "dialog-all", "fs-all", "path-all", "shell-open"] }
tokio = {version = "1.26.0", features = ["full"] }
tokio-util = {version = "0.7", features = ["io"] }
tower = {version = "0.4", features = ["util"] }
tower = {version = "0.4", features = [ "util"] }
tower-http = {version = "0.4.0", features = ["fs", "trace", "cors"] }
tracing = "0.1.37"
tracing-subscriber = {version = "0.3.16", features = ["env-filter"] }
Expand All @@ -57,7 +57,9 @@ wifidirect-legacy-ap = "0.4.0"
aes-gcm = "0.10.3"
sha2 = "0.10.8"
rand = "0.8.5"
tokio-stream = "0.1"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
custom-protocol = ["tauri/custom-protocol"]

11 changes: 11 additions & 0 deletions desktop/core/src/assets/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Inventore ratione amet odio ullam doloremque consequuntur quaerat pariatur non omnis expedita, adipisci rem. Reiciendis corporis deserunt delectus doloremque eveniet, explicabo voluptatem.
</body>
</html>
6 changes: 0 additions & 6 deletions desktop/core/src/file_manager/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ use walkdir::DirEntry;
extern crate dirs;
use path_absolutize::*;




/// a function to compute file size
/// accept files size in byte and parse it to human readable KB, MB, TB, GB e.t.
pub fn compute_file_size(size: u128) -> String {
Expand All @@ -26,8 +23,6 @@ pub fn compute_file_size(size: u128) -> String {
}
}



#[derive(serde::Serialize, Debug)]
pub struct DriveInformation {
name: String,
Expand All @@ -44,7 +39,6 @@ pub struct Drives {
array_of_drives: Vec<DriveInformation>,
}


// the file structure
#[derive(Debug, Default, Serialize, Deserialize, TS)]
#[serde(rename_all = "camelCase")]
Expand Down
4 changes: 2 additions & 2 deletions desktop/core/src/file_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
pub mod file;

use std::net::Ipv4Addr;
use std::path::PathBuf;
use crate::UPLOAD_PATH;
use crate::{
file_manager::file::{get_files_in_directory, File},
Expand All @@ -10,6 +8,8 @@ use crate::{
use dirs;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::net::Ipv4Addr;
use std::path::PathBuf;
use ts_rs::TS;

use crate::database::{self, TransferHistory, TransferHistoryBuilder};
Expand Down
1 change: 0 additions & 1 deletion desktop/core/src/ipc_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pub mod settings;
pub mod utils;
pub mod wifi;
2 changes: 1 addition & 1 deletion desktop/core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

extern crate uptime_lib;
use crate::file_manager::get_transfer_history;
use crate::file_manager::read_dir;
use crate::ipc_manager::settings::{get_application_data, get_settings, update_settings};
use crate::ipc_manager::utils::{
generate_qr_code, get_ip_address, get_system_information, is_connected_to_wifi,
};
use lazy_static::lazy_static;
use server::http_server;
use crate::file_manager::get_transfer_history;
mod database;
mod file_manager;
mod ipc_manager;
Expand Down
25 changes: 25 additions & 0 deletions desktop/core/src/network_manager/linux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


use super::WifiHotspotConfig;
use super::WifiHotspotConfigBuilder;
impl WifiHotspotConfigBuilder for WifiHotspotConfig {
fn create() -> Self {
todo!()
}

fn connect() -> crate::utils::CommandData<bool> {
todo!()
}

fn scan() -> Vec<String> {
todo!()
}

fn stop() -> () {
todo!()
}

fn refresh() -> () {
todo!()
}
}
25 changes: 25 additions & 0 deletions desktop/core/src/network_manager/mac.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

use super::WifiHotspotConfig;
use super::WifiHotspotConfigBuilder;

impl WifiHotspotConfigBuilder for WifiHotspotConfig {
fn create() -> Self {
todo!()
}

fn connect() -> crate::utils::CommandData<bool> {
todo!()
}

fn scan() -> Vec<String> {
todo!()
}

fn stop() -> () {
todo!()
}

fn refresh() -> () {
todo!()
}
}
86 changes: 28 additions & 58 deletions desktop/core/src/network_manager/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
#[allow(unused)]

use std::fmt;

use crate::utils::system_info::SystemInformation;
use nanoid::nanoid;
use serde::{Deserialize, Serialize};
use crate::utils::CommandData;

///TODO: use conditional import
// pub mod hotspot;
pub mod ip_manager;

#[cfg_attr(target_os = "linux", path = "linux.rs")]
#[cfg_attr(target_os = "macos", path = "mac.rs")]
#[cfg_attr(target_os = "windows", path = "windows.rs")]
pub mod network;


/// the Network config trait to be implemented independently fi=or windows, mac and linux
pub trait WifiHotspotConfigBuilder {
/// create new hotspot
fn create() -> Self;
/// connect to a wifi
fn connect() -> CommandData<bool>;
/// scan for network, return an array of network names / ssid
fn scan() -> Vec<String>;
/// terminate the wifi hot spot
fn stop() -> ();
/// refresh the network hotspot or wifi
fn refresh() -> ();
}
// pub mod network_scanner;
/// the network interface type contains the
/// - gateway ex 192.168.0.0.1
Expand All @@ -17,18 +33,18 @@ pub mod ip_manager;
/// - (optional) QR code to scan to connect
/// - (optional) the network card frequency, e.g 2.4GHz or 5Ghz
/// it will be used to communicate with the application interface
#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize)]
pub struct WifiHotspotConfig {
/// the network broadcast ip address
/// the network broadcast ip address eg 192.16.8.0.1
gateway: String,
/// the network name (generates)
/// the network name (generated)
ssid: String,
/// the network password
password: String,
/// the status of the network
status: Option<NetworkAccessStatus>,
/// message
message: Option<String>,
status: NetworkAccessStatus,
/// success or error message
message: String,
}

/// network was successfully created or there is an error
Expand All @@ -38,53 +54,7 @@ pub enum NetworkAccessStatus {
Error,
}

#[allow(unused)]

impl WifiHotspotConfig {

pub fn new(gateway: &str) -> Self {
let SystemInformation {
system_name: ssid, ..
} = SystemInformation::new(); // use the system name
let password = nanoid!(8); // generate username and password
let gateway = gateway.to_string();

Self {
gateway,
ssid,
password,
..Default::default()
}
}

#[allow(dead_code)]
pub fn ok(gateway: &str) -> Self {
let SystemInformation {
system_name: ssid, ..
} = SystemInformation::new(); // use the system name
let password = nanoid!(8); // generate username and password
let gateway = gateway.to_string();
let message = Some(String::from("Wifi hotspot created successfully"));

Self {
gateway,
ssid,
password,
status: Some(NetworkAccessStatus::Created),
message,
}
}

pub fn err() -> Self {
let message = Some(String::from("Failed to create Wifi hotspot"));

Self {
status: Some(NetworkAccessStatus::Created),
message,
..Default::default()
}
}
}
impl WifiHotspotConfig {}

impl fmt::Display for WifiHotspotConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
26 changes: 26 additions & 0 deletions desktop/core/src/network_manager/windows.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


use super::WifiHotspotConfig;
use super::WifiHotspotConfigBuilder;

impl WifiHotspotConfigBuilder for WifiHotspotConfig {
fn create() -> Self {
todo!()
}

fn connect() -> crate::utils::CommandData<bool> {
todo!()
}

fn scan() -> Vec<String> {
todo!()
}

fn stop() -> () {
todo!()
}

fn refresh() -> () {
todo!()
}
}
18 changes: 17 additions & 1 deletion desktop/core/src/server/http_server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::path::PathBuf;

use reqwest::Method;

use tower_http::cors::Any;
use tower_http::cors::CorsLayer;
use tower_http::services::ServeDir;
use tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

Expand All @@ -11,6 +14,7 @@ use crate::database::Database;
use crate::server::router;

use crate::server::routes::handle_404;
use crate::server::routes::notify_peer;
use crate::SERVER_PORT;

/**
Expand Down Expand Up @@ -55,13 +59,25 @@ pub async fn core_server() {

println!(" the server port is http://{}", ip_address);


let assets_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("assets");

let static_files_service = ServeDir::new(assets_dir).append_index_html_on_directories(true);


// build our application with the required routes
let app = router::app()
.fallback_service(static_files_service)
.layer(file_limit)
.layer(cors_layer)
.layer(tower_http::trace::TraceLayer::new_for_http())
.fallback(handle_404);
;

// build our application with a route
// let app = axum::Router::new()
// .fallback_service(static_files_service)
// .route("/sse", axum::routing::get(notify_peer))
// .layer(tower_http::trace::TraceLayer::new_for_http());
// run the server
axum::Server::bind(&ip_address)
.serve(app.into_make_service())
Expand Down
7 changes: 4 additions & 3 deletions desktop/core/src/server/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ use axum::{
};

use super::routes::{
accept_file_upload, download_file, file_upload_form, get_file, health_check, ping_server,
system_information,
accept_file_upload, download_file, file_upload_form, get_file, health_check, notify_peer,
ping_server, system_information,
};

// the app is moved here to allow sharing across test modules
pub fn app() -> Router {
Router::new()
.route("/", get(ping_server))
// .route("/", get(ping_server))
.route("/upload", post(accept_file_upload).get(file_upload_form))
.route("/health", post(accept_file_upload).get(health_check))
.route("/api/sys-info", get(system_information))
.route("/api/download", get(download_file))
.route("/api/file", get(get_file))
.route("/notify", get(notify_peer))
}
Loading