Skip to content

Commit

Permalink
[net_util] Automatically open UFC Ripper in the default browser
Browse files Browse the repository at this point in the history
  • Loading branch information
m4heshd committed Apr 4, 2024
1 parent 70c1e9d commit 32e7e77
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions backend/src/net_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use tower_http::cors::{Any, CorsLayer};
use crate::{
app_util::{get_app_metadata, get_os_id, is_container},
bin_util::BINS,
config_util::{get_config, is_debug, update_config, ConfigUpdate},
config_util::{get_config, is_debug, update_config, ConfigUpdate, UFCRConfig},
fs_util::{write_file_to_disk, WebAssets},
rt_util::QuitUnwrap,
state_util::Vod,
Expand Down Expand Up @@ -58,7 +58,13 @@ static VOD_SEARCH_PARAMS: Lazy<String> = Lazy::new(|| {
///
/// Will panic if the port is already in use or fails to serve the Vue "dist" directory.
pub async fn init_server() {
let port = get_config().port;
let config = get_config();
let UFCRConfig {
port,
open_in_browser,
..
} = config.as_ref();

let index_file = Some("index.html".to_string());
let web_assets =
ServeEmbed::<WebAssets>::with_parameters(index_file.clone(), Redirect, index_file);
Expand All @@ -70,7 +76,7 @@ pub async fn init_server() {
.layer(create_cors_layer());

// TCP listener
let listener = TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], port)))
let listener = TcpListener::bind(SocketAddr::from(([0, 0, 0, 0], *port)))
.await
.unwrap_or_quit(format!("Failed to start the server on port \"{port}\"").as_str());

Expand All @@ -80,6 +86,12 @@ pub async fn init_server() {
if is_container() { "(container)" } else { "" }
);

if !is_container() && *open_in_browser {
if let Err(error) = open::that(format!("http://localhost:{port}")) {
log_err!("Failed to open the UFC Ripper GUI in default browser:\n{error}");
}
}

// Axum server
axum::serve(listener, app)
.await
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"scripts": {
"dev:backend": "cargo run --color=always --bin ufc-ripper",
"dev": "vite",
"build:backend:win32": "cargo build-win32",
"build:backend:win32": "npm run build && cargo build-win32",
"build": "vite build",
"docker:up": "docker compose up --detach --build",
"docker:down": "docker compose down --volumes",
Expand Down

0 comments on commit 32e7e77

Please sign in to comment.