Compare commits

..

2 commits

Author SHA1 Message Date
b6b1b8eeed
Revert native_dialog to 0.6 2023-11-06 22:14:45 +01:00
3f366c4e31
Remove html merge 2023-11-06 21:41:19 +01:00
11 changed files with 757 additions and 748 deletions

3
.gitmodules vendored
View file

@ -1,3 +0,0 @@
[submodule "ext/htmlfilemerger"]
path = ext/htmlfilemerger
url = https://github.com/DarkTrick/htmlfilemerger.git

1296
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@ anyhow = "1.0"
log = "0.4"
simplelog = "0.12"
wry = "0.34"
native-dialog = "0.7"
native-dialog = "0.6"
rust-embed = "8"
directories = "5"
clap = "4"

File diff suppressed because one or more lines are too long

@ -1 +0,0 @@
Subproject commit cf3a34373ff48519d699e08f8a0abf7c83e432c2

View file

@ -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>

View file

@ -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,22 +68,33 @@ 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
// @todo Option pas de resize / taille dans une config (confy)
// @todo Demande ensergistre laction la première fois
// @todo Option always en ligne de commnade
// @todo Icon
// @todo no dialog with v0.7
let ratio = (height * width) as f64 / MAX_IMG_SIZE as f64;
let new_height = (height as f64 / ratio.sqrt()) as u32;
let new_width = (width as f64 / ratio.sqrt()) as u32;
if MessageDialog::new()
.set_title("Resize")
.set_type(native_dialog::MessageType::Info)
.set_text(&format!(
"Resize the file to {} × {}",
new_width, new_height
@ -111,9 +122,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 +153,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 +161,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,