Begin rust rewrite
This commit is contained in:
parent
0dc8c22491
commit
dfcbd9cecf
22 changed files with 23822 additions and 1096 deletions
66
src/main.rs
Normal file
66
src/main.rs
Normal file
|
@ -0,0 +1,66 @@
|
|||
use anyhow::{anyhow, bail, Result};
|
||||
use log::{error, info, warn};
|
||||
use rfd::FileDialog;
|
||||
use rust_embed::RustEmbed;
|
||||
use simplelog::{ColorChoice, Config, LevelFilter, TermLogger, TerminalMode};
|
||||
use std::path::PathBuf;
|
||||
use wry::{
|
||||
application::{
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
window::WindowBuilder,
|
||||
},
|
||||
webview::WebViewBuilder,
|
||||
};
|
||||
|
||||
#[derive(RustEmbed)]
|
||||
#[folder = "embed/"]
|
||||
struct Embed;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// Init log
|
||||
TermLogger::init(
|
||||
LevelFilter::Info,
|
||||
Config::default(),
|
||||
TerminalMode::Mixed,
|
||||
ColorChoice::Auto,
|
||||
)?;
|
||||
|
||||
let img_path = if let Some(img_path) = std::env::args_os().skip(1).next() {
|
||||
PathBuf::from(img_path)
|
||||
} else {
|
||||
FileDialog::new()
|
||||
.add_filter("JPG", &["jpg", "JPG", "jpeg", "pjpeg", "pjpg", "PJPG"])
|
||||
.add_filter("wibp", &["webp"])
|
||||
.set_directory(std::env::home_dir().unwrap())
|
||||
.pick_file()
|
||||
.ok_or_else(|| anyhow!("No file"))?
|
||||
};
|
||||
|
||||
let img_data = std::fs::read(img_path)?;
|
||||
let img_base_64 = base64::encode(img_data);
|
||||
let html = std::str::from_utf8(Embed::get("index.html").unwrap().data.as_ref())?
|
||||
.replace("__BASE_64_IMG__", &img_base_64);
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
let window = WindowBuilder::new()
|
||||
.with_title("Simple panorama viewer")
|
||||
.build(&event_loop)?;
|
||||
let _webview = WebViewBuilder::new(window)?
|
||||
.with_html(html)?
|
||||
.with_devtools(true)
|
||||
.build()?;
|
||||
|
||||
event_loop.run(move |event, _, control_flow| {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::NewEvents(StartCause::Init) => println!("Wry has started!"),
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
..
|
||||
} => *control_flow = ControlFlow::Exit,
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue