Skip to content

Commit

Permalink
Add simple http
Browse files Browse the repository at this point in the history
  • Loading branch information
petrvecera committed Feb 19, 2024
1 parent 9365804 commit 8db9423
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src-tauri/Cargo.lock

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

2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ vault = "8"
window-shadows = "0.2"
# monitoring by sentry
sentry = "0.32.2"
# For the OBS interface we need to expose webserver
tiny_http = "0.11"

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
Expand Down
50 changes: 50 additions & 0 deletions src-tauri/src/dp_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::fs::File;
use std::path::Path;
use std::panic;
use log::{error, info, warn};

use tiny_http::{Server, Response, StatusCode};

// const server: tiny_http::Server = Server::http("127.0.0.1:8000").unwrap();
//
// const request: tiny_http::Request = match server.recv() {
// Ok(rq) => rq,
// Err(e) => { println!("error: {}", e); break }
// };
//
// const response: tiny_http::Response = tiny_http::Response::from_file(File::open(&Path::new("image.png")).unwrap());
// const responded = request.respond(response);
//
//


pub fn test_fn() {

let result = panic::catch_unwind(|| {

println!("Starting server...");
let server = Server::http("127.0.0.1:8000").unwrap();

for request in server.incoming_requests() {
let file_path = Path::new(r"C:\Users\pagep\AppData\Roaming\com.coh3stats.desktop\streamerOverlay.html");
let file = match File::open(&file_path) {
Ok(file) => file,
Err(_) => {
let response = Response::new_empty(StatusCode(404));
let _ = request.respond(response);
continue;
}
};

let response = Response::from_file(file);
let _ = request.respond(response);
}

});

if let Err(err) = result {
println!("Error: {:?}", err);
error!("Couldn't start the : {:?}", err);
}

}
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod parse_log_file;
pub mod plugins;
pub mod dp_utils;
7 changes: 6 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

extern crate machine_uid;

use coh3_stats_desktop_app::{parse_log_file, plugins::cohdb};
use coh3_stats_desktop_app::{parse_log_file, plugins::cohdb, dp_utils::test_fn};
use log::error;
use std::path::Path;
use std::thread;
use tauri::Manager;
use tauri_plugin_log::LogTarget;
use window_shadows::set_shadow;
Expand All @@ -27,6 +28,10 @@ fn main() {
..Default::default()
}));

let _handle = thread::spawn(|| {
test_fn();
});

tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
default_log_file_path,
Expand Down

0 comments on commit 8db9423

Please sign in to comment.