Improve window
This commit is contained in:
parent
dfcbd9cecf
commit
3558d2b34e
4 changed files with 64 additions and 14 deletions
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -320,6 +320,26 @@ dependencies = [
|
|||
"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]]
|
||||
name = "dispatch"
|
||||
version = "0.2.0"
|
||||
|
@ -1149,6 +1169,17 @@ dependencies = [
|
|||
"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]]
|
||||
name = "regex"
|
||||
version = "1.6.0"
|
||||
|
@ -1322,6 +1353,7 @@ version = "2.0.0"
|
|||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
"directories",
|
||||
"log",
|
||||
"rfd",
|
||||
"rust-embed",
|
||||
|
|
|
@ -11,3 +11,4 @@ wry = "0.20"
|
|||
rfd = "0.10"
|
||||
rust-embed = "6"
|
||||
base64 = "0.13"
|
||||
directories = "4"
|
||||
|
|
|
@ -10875,7 +10875,6 @@
|
|||
container: 'photosphere',
|
||||
panorama: "data:mage/png;base64,__BASE_64_IMG__",
|
||||
caption: 'Panorama displayed with Photo Sphere Viewer V4.7.1',
|
||||
autorotateDelay: false,
|
||||
defaultZoomLvl: 40,
|
||||
minFov: 5,
|
||||
maxFov: 75,
|
||||
|
|
44
src/main.rs
44
src/main.rs
|
@ -1,8 +1,8 @@
|
|||
use anyhow::{anyhow, bail, Result};
|
||||
use log::{error, info, warn};
|
||||
use anyhow::{anyhow, Result};
|
||||
use log::info;
|
||||
use rfd::FileDialog;
|
||||
use rust_embed::RustEmbed;
|
||||
use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode};
|
||||
use simplelog::{ConfigBuilder, ColorChoice, LevelFilter, TermLogger, TerminalMode};
|
||||
use std::path::PathBuf;
|
||||
use wry::{
|
||||
application::{
|
||||
|
@ -21,7 +21,9 @@ fn main() -> Result<()> {
|
|||
// Init log
|
||||
TermLogger::init(
|
||||
LevelFilter::Info,
|
||||
Config::default(),
|
||||
ConfigBuilder::new()
|
||||
.set_time_offset_to_local().unwrap()
|
||||
.build(),
|
||||
TerminalMode::Mixed,
|
||||
ColorChoice::Auto,
|
||||
)?;
|
||||
|
@ -29,37 +31,53 @@ fn main() -> Result<()> {
|
|||
let img_path = if let Some(img_path) = std::env::args_os().skip(1).next() {
|
||||
PathBuf::from(img_path)
|
||||
} 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()
|
||||
.add_filter("JPG", &["jpg", "JPG", "jpeg", "pjpeg", "pjpg", "PJPG"])
|
||||
.add_filter("wibp", &["webp"])
|
||||
.set_directory(std::env::home_dir().unwrap())
|
||||
.add_filter(
|
||||
"Images",
|
||||
&[
|
||||
"jpg", "JPG", "jpeg", "pjpeg", "pjpg", "PJPG", "webp", "avif",
|
||||
],
|
||||
)
|
||||
.set_directory(dir)
|
||||
.pick_file()
|
||||
.ok_or_else(|| anyhow!("No file"))?
|
||||
};
|
||||
|
||||
info!("Open `{}`", img_path.display());
|
||||
let img_data = std::fs::read(img_path)?;
|
||||
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())?
|
||||
.replace("__BASE_64_IMG__", &img_base_64);
|
||||
|
||||
info!("Create webview");
|
||||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new()
|
||||
.with_title("Simple panorama viewer")
|
||||
.with_maximized(true)
|
||||
.build(&event_loop)?;
|
||||
let _webview = WebViewBuilder::new(window)?
|
||||
.with_html(html)?
|
||||
.with_devtools(true)
|
||||
.build()?;
|
||||
let _webview = WebViewBuilder::new(window)?.with_html(html)?.build()?;
|
||||
|
||||
info!("Event loop");
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
|
||||
Event::NewEvents(StartCause::Init) => info!("Panorama open"),
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
..
|
||||
} => *control_flow = ControlFlow::Exit,
|
||||
} => {
|
||||
info!("Close");
|
||||
*control_flow = ControlFlow::Exit
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue