-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Moved patches from different PRs. * Add bits & pieces and some services. * Rename `stdweb` feature to `std_web`. * Move tests and examples to different PR. * Revert some `cargo_web` handling removal. * Missed something. * Implement `console_error_panic_hook`. * Update Cargo.toml Co-authored-by: Justin Starry <justin.m.starry@gmail.com>
- Loading branch information
Showing
6 changed files
with
128 additions
and
10 deletions.
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
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 |
---|---|---|
@@ -1,12 +1,31 @@ | ||
//! This module contains useful utils to get information about the current document. | ||
use failure::{err_msg, Error}; | ||
#[cfg(feature = "std_web")] | ||
use stdweb::web::document; | ||
|
||
/// Returns `host` for the current document. Useful to connect to a server that server the app. | ||
pub fn host() -> Result<String, Error> { | ||
document() | ||
#[cfg(feature = "std_web")] | ||
{ | ||
document() | ||
.location() | ||
.ok_or_else(|| err_msg("can't get location")) | ||
.and_then(|l| l.host().map_err(Error::from)) | ||
} | ||
#[cfg(feature = "web_sys")] | ||
web_sys::window() | ||
.unwrap() | ||
.document() | ||
.unwrap() | ||
.location() | ||
.ok_or_else(|| err_msg("can't get location")) | ||
.and_then(|l| l.host().map_err(Error::from)) | ||
.and_then(|l| { | ||
l.host().map_err(|e| { | ||
err_msg( | ||
e.as_string() | ||
.unwrap_or_else(|| String::from("error not recoverable")), | ||
) | ||
}) | ||
}) | ||
} |