-
-
Notifications
You must be signed in to change notification settings - Fork 5
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 simple http #67
Closed
Closed
Add simple http #67
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8db9423
Add simple http
petrvecera 9fde25f
Up the version 1.2.7 beta
petrvecera fe0e329
Add MacOS instructions
petrvecera 31ef303
Add notifications on auth button (#68)
petrvecera 28f672b
Add simple http
petrvecera 5bcf8d4
Web server implmentation
petrvecera bba409c
Finish the server hosting
petrvecera cfd4e52
Merge remote-tracking branch 'origin/serve-as-http' into serve-as-http
petrvecera 16c99d0
Add sentry config
petrvecera 06333bd
Update actions
petrvecera c8f81e3
Fix main
petrvecera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::path::PathBuf; | ||
|
||
// COH3 Desktop App Utils | ||
use tauri_plugin_store::{Store, StoreBuilder}; | ||
use log::{info, warn}; | ||
use tauri::{AppHandle, Runtime}; | ||
|
||
|
||
pub fn load_store<R: Runtime>(handle: AppHandle<R>) -> Store<R> { | ||
let mut store = StoreBuilder::new(handle, PathBuf::from("config.dat")).build(); | ||
|
||
if let Err(err) = store.load() { | ||
warn!("error loading store from disk: {err}"); | ||
info!("saving store file to disk"); | ||
if let Err(err) = store.save() { | ||
warn!("error saving store file to disk: {err}"); | ||
} | ||
} | ||
|
||
store | ||
} | ||
|
||
|
||
// This is stupid I can't figure out how to return different types from a function and work with it correctly :'( | ||
// fn get_value_from_store<R: Runtime>(store: &Store<R>, key: String) -> Option<Result<String, bool>> { | ||
// match store.get(key) { | ||
// Some(value) => { | ||
// Some(serde_json::from_value(value.clone()).map_err(|_| false)) | ||
// }, | ||
// None => None, | ||
// } | ||
// } | ||
|
||
|
||
pub fn is_streamer_overlay_enabled<R: Runtime>(store: &Store<R>) -> bool { | ||
match store.get("streamerOverlayEnabled".to_string()) { | ||
Some(value) => serde_json::from_value(value.clone()).unwrap_or(false), | ||
None => false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod parse_log_file; | ||
pub mod plugins; | ||
pub mod overlay_server; | ||
pub mod dp_utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::fs::File; | ||
use std::panic; | ||
use log::{error, info}; | ||
use std::path::PathBuf; | ||
|
||
use tiny_http::{Server, Response, StatusCode}; | ||
|
||
pub fn run_http_server(streamer_overlay_path: PathBuf) { | ||
|
||
let result = panic::catch_unwind(|| { | ||
|
||
// Ideally we would allow setting up port in the settings | ||
info!("Starting streamer overlay server on port 47824"); | ||
let server = Server::http("127.0.0.1:47824").unwrap(); | ||
|
||
for request in server.incoming_requests() { | ||
|
||
let file = match File::open(&streamer_overlay_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 { | ||
error!("Couldn't start the streamer overlay server: {:?}", err); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this was how I was doing it originally, but it unfortunately doesn't play well with Javascript changes to the store because the JS changes don't update this Rust state struct. What I'd recommend is extracting this function instead: https://github.com/cohstats/coh3-stats-desktop-app/blob/master/src-tauri/src/plugins/cohdb/sync/mod.rs#L138
It's generic over any deserializable object, so it'll work for anything that can be deserialized from JSON (primitives, strings, and structs that derive
Deserialize
should all work here). You'll probably have to tell the compiler what type you're expecting though (you can see an example of that here: https://github.com/cohstats/coh3-stats-desktop-app/blob/master/src-tauri/src/plugins/cohdb/sync/mod.rs#L165).I don't have time now but I can probably take a look at this sometime next week if you have trouble with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I will take a look, looking at my code I have no idea why is there the store.save() :D I guess I was happy that it works.
My implementation is counting with need to restart the APP, because I would have to handle it using events I guess and I don't think it's necessary right.