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 explorer flag to open World Explorer in browser #1581

Merged
merged 4 commits into from
Mar 19, 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
152 changes: 152 additions & 0 deletions 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 bin/torii/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ tracing-subscriber.workspace = true
tracing.workspace = true
url.workspace = true
torii-relay.workspace = true
webbrowser = "0.8"

[dev-dependencies]
camino.workspace = true
Expand Down
15 changes: 13 additions & 2 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use torii_core::sql::Sql;
use torii_core::types::Model;
use torii_server::proxy::Proxy;
use tracing::info;
use tracing::{error, info};
use tracing_subscriber::{fmt, EnvFilter};
use url::{form_urlencoded, Url};

Expand Down Expand Up @@ -98,6 +98,10 @@
/// The metrics will be served at the given interface and port.
#[arg(long, value_name = "SOCKET", value_parser = parse_socket_address, help_heading = "Metrics")]
metrics: Option<SocketAddr>,

/// Open World Explorer on the browser.
#[arg(long)]
explorer: bool,

Check warning on line 104 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L104

Added line #L104 was not covered by tests
}

#[tokio::main]
Expand Down Expand Up @@ -201,9 +205,16 @@
let encoded: String =
form_urlencoded::byte_serialize(gql_endpoint.replace("0.0.0.0", "localhost").as_bytes())
.collect();
let explorer_url = format!("https://worlds.dev/torii?url={}", encoded);

Check warning on line 208 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L208

Added line #L208 was not covered by tests
info!(target: "torii::cli", "Starting torii endpoint: {}", endpoint);
info!(target: "torii::cli", "Serving Graphql playground: {}", gql_endpoint);
info!(target: "torii::cli", "World Explorer is available on: {}\n", format!("https://worlds.dev/torii?url={}", encoded));
info!(target: "torii::cli", "World Explorer is available on: {}\n", explorer_url);

Check warning on line 212 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L211-L212

Added lines #L211 - L212 were not covered by tests
if args.explorer {
if let Err(e) = webbrowser::open(&explorer_url) {
error!("Failed to open World Explorer in the browser: {e}");
}
}

Check warning on line 217 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L214-L217

Added lines #L214 - L217 were not covered by tests

if let Some(listen_addr) = args.metrics {
let prometheus_handle = prometheus_exporter::install_recorder("torii")?;
Expand Down
Loading