Skip to content

Commit

Permalink
Merge pull request #283 from opeolluwa/master
Browse files Browse the repository at this point in the history
app -v0.6.24
  • Loading branch information
opeolluwa authored Oct 6, 2023
2 parents 13406f1 + 3c1cc53 commit 7fdbd5a
Show file tree
Hide file tree
Showing 41 changed files with 494 additions and 245 deletions.
106 changes: 99 additions & 7 deletions core/Cargo.lock

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

1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ walkdir = "2.3.3"
wildmatch = "2.1.1"
uuid = {version = "1.4.1", features = ["v4", "fast-rng", "macro-diagnostics"] }
ts-rs = "7.0.0"
pnet = "0.34.0"
[features]
# this feature is used for production builds or when `devPath` points to the filesystem
# DO NOT REMOVE!!
Expand Down
6 changes: 1 addition & 5 deletions core/bindings/CommandData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface CommandData<T> {
data: T | null;
message: string;
status: boolean;
}
export interface CommandData<T> { data: T | null, message: string, status: boolean, }
4 changes: 4 additions & 0 deletions core/bindings/Drives.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { MyDisk } from "./MyDisk";

export interface Drives { arrayOfDrives: Array<MyDisk>, }
3 changes: 3 additions & 0 deletions core/bindings/MyDisk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface MyDisk { type: string, deviceName: string, fileSystem: Array<number>, mountPoint: string, totalSpace: bigint, availableSpace: bigint, isRemovable: boolean, }
7 changes: 1 addition & 6 deletions core/bindings/Settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface Settings {
id: number;
language: string;
theme: string;
firstRun: boolean;
}
export interface Settings { id: number, language: string, theme: string, firstRun: boolean, }
13 changes: 13 additions & 0 deletions core/bindings/SystemInformation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { Drives } from "./Drives";

export interface SystemInformation {
systemName: string;
disk: Drives;
availableDisk: string;
usedDisk: string;
port: bigint;
remainingTime: string | null;
ipAddress: string;
serverBaseUrl: string;
}
9 changes: 1 addition & 8 deletions core/bindings/TransferHistory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TransferHistory {
id: string;
fileName: string;
fileSize: string;
date: string;
transactionType: string;
recipient: string;
}
export interface TransferHistory { id: string, fileName: string, fileSize: string, date: string, transactionType: string, recipient: string, }
7 changes: 1 addition & 6 deletions core/bindings/TransferHistoryBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export interface TransferHistoryBuilder {
fileName: string;
fileSize: string;
transactionType: string;
recipient: string;
}
export interface TransferHistoryBuilder { fileName: string, fileSize: string, transactionType: string, recipient: string, }
40 changes: 24 additions & 16 deletions core/src/api/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,65 @@
/// once this is done pass the network conf
use crate::{
utils::CommandData,
wifi::{linux_hotspot, WifiHotspotConfig},
wifi::{hotspot, network_scanner, WifiHotspotConfig},
};

#[tauri::command]
pub fn create_wifi_hotspot() -> CommandData<WifiHotspotConfig> {
#[cfg(target_os = "linux")]
{
// Linux-specific command
let Some(new_access_point) = linux_hotspot::create_hotspot().ok() else {
let Some(new_access_point) = hotspot::linux::create_hotspot().ok() else {
return CommandData::err("failed to create access point", WifiHotspotConfig::err());
};
CommandData::ok("created access point", new_access_point)
}

#[cfg(target_os = "windows")]
{
// Windows-specific command
todo!();
}

#[cfg(target_os = "macos")]
{
// macOS-specific command
todo!();
/* tauri::Command::new("open")
.arg("https://www.example.com")
.spawn()
.expect("Failed to execute command"); */
todo!()
}
}

// turn off wifi hotspot
#[tauri::command]
pub fn kill_wifi_hotspot() {
#[cfg(target_os = "linux")]
{
linux_hotspot::turn_off_hotspot()
hotspot::linux::turn_off_hotspot()
}

#[cfg(target_os = "windows")]
{
// Windows-specific command
todo!();
}

#[cfg(target_os = "macos")]
{
// macOS-specific command
todo!();
/* tauri::Command::new("open")
.arg("https://www.example.com")
.spawn()
.expect("Failed to execute command"); */
}
}

// scan for available network
#[tauri::command]
pub fn scan_wifi() {
#[cfg(target_os = "linux")]
{
network_scanner::linux::scan_wifi();
}

#[cfg(target_os = "windows")]
{
network_scanner::windows::scan_wifi();
}

#[cfg(target_os = "macos")]
{
network_scanner::mac::scan_wifi();
}
}
2 changes: 1 addition & 1 deletion core/src/fs/file.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::utils::compute_file_size;
use crate::utils::fs::compute_file_size;
use filesize::PathExt;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
Expand Down
2 changes: 1 addition & 1 deletion core/src/fs/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use walkdir::{DirEntry, WalkDir};
use wildmatch::WildMatch;

use super::file::File;
use crate::utils::{is_hidden, CommandData};
use crate::utils::{fs::is_hidden, CommandData};
use assert_fs::prelude::*;

fn is_wildcard_match(pattern: &str, entry: &DirEntry) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion core/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::api::{
},
settings::{get_settings, update_settings},
utils::{generate_qr_code, get_ip_address, get_system_information},
wifi::{create_wifi_hotspot, kill_wifi_hotspot},
wifi::{create_wifi_hotspot, kill_wifi_hotspot, scan_wifi},
};
use lazy_static::lazy_static;
use server::http_server;
Expand Down Expand Up @@ -82,6 +82,7 @@ fn main() -> Result<(), tauri::Error> {
..Default::default()
};

scan_wifi();
// run core the server in a separate thread from tauri
tauri::async_runtime::spawn(http_server::core_server());
// run the UI code and the IPC (internal Procedure Call functions)
Expand All @@ -103,6 +104,7 @@ fn main() -> Result<(), tauri::Error> {
get_settings,
update_settings,
get_transfer_history,
scan_wifi // download_file, TODO: implement file transfering between peers
])
.run(tauri::generate_context!())
}
2 changes: 2 additions & 0 deletions core/src/server/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use axum::extract::DefaultBodyLimit;
use crate::database::Database;
use crate::server::router;
use crate::SERVER_PORT;
use crate::server::routes::handle_404;

/**
* @function core_server
Expand Down Expand Up @@ -58,6 +59,7 @@ pub async fn core_server() {
.layer(file_limit)
.layer(cors_layer)
.layer(tower_http::trace::TraceLayer::new_for_http());
// .fallback(handle_404);

// add a fallback service for handling routes to unknown paths
// let app = app.fallback(handle_404);
Expand Down
6 changes: 4 additions & 2 deletions core/src/server/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ use axum::{
Router,
};

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

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

0 comments on commit 7fdbd5a

Please sign in to comment.