Remove html merge
This commit is contained in:
parent
f481105fd9
commit
3f366c4e31
9 changed files with 50 additions and 154 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "ext/htmlfilemerger"]
|
||||
path = ext/htmlfilemerger
|
||||
url = https://github.com/DarkTrick/htmlfilemerger.git
|
File diff suppressed because one or more lines are too long
0
js/browser.min.js → embed/js/browser.min.js
vendored
0
js/browser.min.js → embed/js/browser.min.js
vendored
0
js/three.min.js → embed/js/three.min.js
vendored
0
js/three.min.js → embed/js/three.min.js
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit cf3a34373ff48519d699e08f8a0abf7c83e432c2
|
|
@ -1,63 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Panorama viewer</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<link rel="stylesheet" href="../css/photo-sphere-viewer.min.css">
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%; height: 100%; overflow: hidden; margin: 0; padding:
|
||||
0;
|
||||
}
|
||||
|
||||
#photosphere {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.psv-button.custom-button {
|
||||
font-size: 22px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.demo-label {
|
||||
color: white;
|
||||
font-size: 20px;
|
||||
font-family: Helvetica, sans-serif;
|
||||
text-align: center;
|
||||
padding: 5px;
|
||||
border: 1px solid white;
|
||||
background: rgba(0,0,0,0.4);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="photosphere"></div>
|
||||
|
||||
<script src="../js/three.min.js"></script>
|
||||
<script src="../js/browser.min.js"></script>
|
||||
<script src="../js/photo-sphere-viewer.min.js"></script>
|
||||
|
||||
<h1>Panorama</h1>>
|
||||
<script>
|
||||
var PSV = new PhotoSphereViewer.Viewer({
|
||||
container: 'photosphere',
|
||||
panorama: 'img',
|
||||
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
|
||||
defaultZoomLvl: 40,
|
||||
minFov: 5,
|
||||
maxFov: 75,
|
||||
navbar: [
|
||||
'autorotate',
|
||||
'zoom',
|
||||
'caption'
|
||||
]
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
48
src/main.rs
48
src/main.rs
|
@ -1,6 +1,6 @@
|
|||
#![windows_subsystem = "windows"]
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use clap::{Arg, Command};
|
||||
use fast_image_resize as fr;
|
||||
use image::{io::Reader as ImageReader, DynamicImage};
|
||||
|
@ -68,9 +68,19 @@ fn main() -> Result<()> {
|
|||
.ok_or_else(|| anyhow!("No file"))?
|
||||
};
|
||||
|
||||
if !img_path.exists() {
|
||||
MessageDialog::new()
|
||||
.set_title("Image error")
|
||||
.set_text(&format!("Image `{}` does not exist", img_path.display()))
|
||||
.set_type(native_dialog::MessageType::Error)
|
||||
.show_alert()?;
|
||||
bail!("File `{}` does not exist !", img_path.display());
|
||||
}
|
||||
|
||||
info!("Open `{}`", img_path.display());
|
||||
let (width, height) = image::image_dimensions(&img_path)?;
|
||||
const MAX_IMG_SIZE: u32 = 20_000_000;
|
||||
info!("Image size {} * {}", width, height);
|
||||
let img_data_path = if height * width > MAX_IMG_SIZE {
|
||||
// @todo utilisation de rfd au lieu de message_dialog
|
||||
// @todo Option pas de resize / taille en ligne de commande
|
||||
|
@ -111,9 +121,8 @@ fn main() -> Result<()> {
|
|||
img_path
|
||||
};
|
||||
|
||||
info!("Generate HTML");
|
||||
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?.to_string();
|
||||
run_server(html, img_data_path);
|
||||
info!("Run server");
|
||||
run_server(img_data_path);
|
||||
|
||||
info!("Create webview");
|
||||
let event_loop = EventLoop::new();
|
||||
|
@ -143,7 +152,7 @@ fn main() -> Result<()> {
|
|||
});
|
||||
}
|
||||
|
||||
fn run_server(html: String, img_path: PathBuf) -> JoinHandle<()> {
|
||||
fn run_server(img_path: PathBuf) -> JoinHandle<()> {
|
||||
std::thread::spawn(|| {
|
||||
info!("Create runtime");
|
||||
let async_runtime = tokio::runtime::Builder::new_current_thread()
|
||||
|
@ -151,13 +160,38 @@ fn run_server(html: String, img_path: PathBuf) -> JoinHandle<()> {
|
|||
.build()
|
||||
.unwrap();
|
||||
info!("Create response");
|
||||
let hello = warp::path!("index.html").map(move || warp::reply::html(html.clone()));
|
||||
let index = warp::path("index.html").map(|| {
|
||||
info!("Request `index.html`");
|
||||
let datas = get_file_data("index.html");
|
||||
warp::reply::html(datas)
|
||||
});
|
||||
let css = warp::path!("css" / String).map(move |val: String| {
|
||||
info!("Request css `{}`", &val);
|
||||
let datas = get_file_data(&format!("css/{}", val));
|
||||
warp::http::Response::builder().body(datas)
|
||||
});
|
||||
let js = warp::path!("js" / String).map(move |val: String| {
|
||||
info!("Request js `{}`", &val);
|
||||
let datas = get_file_data(&format!("js/{}", val));
|
||||
warp::http::Response::builder().body(datas)
|
||||
});
|
||||
let img = warp::path!("img").map(move || std::fs::read(&img_path).unwrap());
|
||||
info!("Launch webserver");
|
||||
async_runtime.block_on(warp::serve(hello.or(img)).run(([127, 0, 0, 1], 62371)));
|
||||
async_runtime
|
||||
.block_on(warp::serve(img.or(index).or(css).or(js)).run(([127, 0, 0, 1], 62371)));
|
||||
})
|
||||
}
|
||||
|
||||
fn get_file_data(filename: &str) -> String {
|
||||
if let Some(file) = Embed::get(filename) {
|
||||
std::str::from_utf8(file.data.as_ref())
|
||||
.unwrap_or("")
|
||||
.to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// Fast resize
|
||||
pub fn fast_image_resize(
|
||||
img: &DynamicImage,
|
||||
|
|
Loading…
Reference in a new issue