Use a local HTTP server
This commit is contained in:
parent
80e2e6da9e
commit
f389faef03
3 changed files with 630 additions and 44 deletions
24
src/main.rs
24
src/main.rs
|
@ -2,8 +2,9 @@ use anyhow::{anyhow, Result};
|
|||
use log::info;
|
||||
use rfd::FileDialog;
|
||||
use rust_embed::RustEmbed;
|
||||
use simplelog::{ConfigBuilder, ColorChoice, LevelFilter, TermLogger, TerminalMode};
|
||||
use std::path::PathBuf;
|
||||
use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
|
||||
use std::{path::PathBuf, thread::JoinHandle};
|
||||
use warp::Filter;
|
||||
use wry::{
|
||||
application::{
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
|
@ -22,7 +23,8 @@ fn main() -> Result<()> {
|
|||
TermLogger::init(
|
||||
LevelFilter::Info,
|
||||
ConfigBuilder::new()
|
||||
.set_time_offset_to_local().unwrap()
|
||||
.set_time_offset_to_local()
|
||||
.unwrap()
|
||||
.build(),
|
||||
TerminalMode::Mixed,
|
||||
ColorChoice::Auto,
|
||||
|
@ -56,6 +58,7 @@ fn main() -> Result<()> {
|
|||
info!("Generate HTML");
|
||||
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?
|
||||
.replace("__BASE_64_IMG__", &img_base_64);
|
||||
run_server(html);
|
||||
|
||||
info!("Create webview");
|
||||
let event_loop = EventLoop::new();
|
||||
|
@ -63,7 +66,9 @@ fn main() -> Result<()> {
|
|||
.with_title("Simple panorama viewer")
|
||||
.with_maximized(true)
|
||||
.build(&event_loop)?;
|
||||
let _webview = WebViewBuilder::new(window)?.with_html(html)?.build()?;
|
||||
let _webview = WebViewBuilder::new(window)?
|
||||
.with_url("http://127.0.0.1:62371")?
|
||||
.build()?;
|
||||
|
||||
info!("Event loop");
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
|
@ -82,3 +87,14 @@ fn main() -> Result<()> {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn run_server(html: String) -> JoinHandle<()> {
|
||||
std::thread::spawn(|| {
|
||||
let async_runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap();
|
||||
let hello = warp::any().map(move || warp::reply::html(html.clone()));
|
||||
async_runtime.block_on(warp::serve(hello).run(([127, 0, 0, 1], 62371)));
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue