Improve window

This commit is contained in:
Rémi BERTHO 2022-09-05 14:37:55 +02:00
parent dfcbd9cecf
commit 3558d2b34e
Signed by: dalan
GPG key ID: EE3B917931C07B64
4 changed files with 64 additions and 14 deletions

32
Cargo.lock generated
View file

@ -320,6 +320,26 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "directories"
version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]] [[package]]
name = "dispatch" name = "dispatch"
version = "0.2.0" version = "0.2.0"
@ -1149,6 +1169,17 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "redox_users"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom",
"redox_syscall",
"thiserror",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.6.0" version = "1.6.0"
@ -1322,6 +1353,7 @@ version = "2.0.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
"directories",
"log", "log",
"rfd", "rfd",
"rust-embed", "rust-embed",

View file

@ -11,3 +11,4 @@ wry = "0.20"
rfd = "0.10" rfd = "0.10"
rust-embed = "6" rust-embed = "6"
base64 = "0.13" base64 = "0.13"
directories = "4"

View file

@ -10875,7 +10875,6 @@
container: 'photosphere', container: 'photosphere',
panorama: "data:mage/png;base64,__BASE_64_IMG__", panorama: "data:mage/png;base64,__BASE_64_IMG__",
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1', caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
autorotateDelay: false,
defaultZoomLvl: 40, defaultZoomLvl: 40,
minFov: 5, minFov: 5,
maxFov: 75, maxFov: 75,

View file

@ -1,8 +1,8 @@
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, Result};
use log::{error, info, warn}; use log::info;
use rfd::FileDialog; use rfd::FileDialog;
use rust_embed::RustEmbed; use rust_embed::RustEmbed;
use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode}; use simplelog::{ConfigBuilder, ColorChoice, LevelFilter, TermLogger, TerminalMode};
use std::path::PathBuf; use std::path::PathBuf;
use wry::{ use wry::{
application::{ application::{
@ -21,7 +21,9 @@ fn main() -> Result<()> {
// Init log // Init log
TermLogger::init( TermLogger::init(
LevelFilter::Info, LevelFilter::Info,
Config::default(), ConfigBuilder::new()
.set_time_offset_to_local().unwrap()
.build(),
TerminalMode::Mixed, TerminalMode::Mixed,
ColorChoice::Auto, ColorChoice::Auto,
)?; )?;
@ -29,37 +31,53 @@ fn main() -> Result<()> {
let img_path = if let Some(img_path) = std::env::args_os().skip(1).next() { let img_path = if let Some(img_path) = std::env::args_os().skip(1).next() {
PathBuf::from(img_path) PathBuf::from(img_path)
} else { } else {
let user_dirs = directories::UserDirs::new().unwrap();
let dir = if let Some(img_dir) = user_dirs.picture_dir() {
img_dir
} else {
user_dirs.home_dir()
};
FileDialog::new() FileDialog::new()
.add_filter("JPG", &["jpg", "JPG", "jpeg", "pjpeg", "pjpg", "PJPG"]) .add_filter(
.add_filter("wibp", &["webp"]) "Images",
.set_directory(std::env::home_dir().unwrap()) &[
"jpg", "JPG", "jpeg", "pjpeg", "pjpg", "PJPG", "webp", "avif",
],
)
.set_directory(dir)
.pick_file() .pick_file()
.ok_or_else(|| anyhow!("No file"))? .ok_or_else(|| anyhow!("No file"))?
}; };
info!("Open `{}`", img_path.display());
let img_data = std::fs::read(img_path)?; let img_data = std::fs::read(img_path)?;
let img_base_64 = base64::encode(img_data); let img_base_64 = base64::encode(img_data);
info!("Generate HTML");
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())? let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?
.replace("__BASE_64_IMG__", &img_base_64); .replace("__BASE_64_IMG__", &img_base_64);
info!("Create webview");
let event_loop = EventLoop::new(); let event_loop = EventLoop::new();
let window = WindowBuilder::new() let window = WindowBuilder::new()
.with_title("Simple panorama viewer") .with_title("Simple panorama viewer")
.with_maximized(true)
.build(&event_loop)?; .build(&event_loop)?;
let _webview = WebViewBuilder::new(window)? let _webview = WebViewBuilder::new(window)?.with_html(html)?.build()?;
.with_html(html)?
.with_devtools(true)
.build()?;
info!("Event loop");
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait; *control_flow = ControlFlow::Wait;
match event { match event {
Event::NewEvents(StartCause::Init) => println!("Wry has started!"), Event::NewEvents(StartCause::Init) => info!("Panorama open"),
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CloseRequested, event: WindowEvent::CloseRequested,
.. ..
} => *control_flow = ControlFlow::Exit, } => {
info!("Close");
*control_flow = ControlFlow::Exit
}
_ => (), _ => (),
} }
}); });