mirror of
https://github.com/Tim-Paik/neutauri.git
synced 2024-10-12 23:29:41 +00:00
Compare commits
10 Commits
8962b3d80b
...
main
Author | SHA1 | Date | |
---|---|---|---|
e1fb1c4494 | |||
9413e2d232 | |||
3449221f81
|
|||
2a8e27995a
|
|||
167bee14e7
|
|||
1bebb857ee
|
|||
a333c2a507
|
|||
69531170b9
|
|||
915b34cb5d
|
|||
44fa046fc9
|
1755
Cargo.lock
generated
1755
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -6,11 +6,13 @@ version = "0.1.0"
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
gumdrop = "0.8"
|
||||
neutauri_data = {path = "../neutauri_data", features = ["bundler"]}
|
||||
inquire = "0.6"
|
||||
neutauri_data = {path = "../neutauri_data", default-features = false, features = ["bundler"]}
|
||||
new_mime_guess = "4.0"
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
toml = "0.5"
|
||||
wry = {version = "0.19", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen", "devtools"]}
|
||||
toml = "0.7"
|
||||
vc-ltl = "5.0.5"
|
||||
wry = {version = "0.27", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen", "devtools"]}
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
rcedit = {git = "https://github.com/Tim-Paik/rcedit-rs.git", rev = "2805fca"}
|
||||
|
@ -1,4 +1,3 @@
|
||||
#[cfg(windows)]
|
||||
use anyhow::Context;
|
||||
use neutauri_data as data;
|
||||
#[cfg(windows)]
|
||||
@ -6,10 +5,7 @@ use std::{
|
||||
env,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
use std::{
|
||||
fs,
|
||||
io::{self, Write},
|
||||
};
|
||||
use std::{fs, io::Write};
|
||||
|
||||
fn options() -> fs::OpenOptions {
|
||||
#[cfg(not(windows))]
|
||||
@ -61,10 +57,17 @@ fn get_runtime_data(
|
||||
Ok(runtime_data)
|
||||
}
|
||||
|
||||
pub fn bundle(config_path: String) -> anyhow::Result<()> {
|
||||
let config_path = std::path::Path::new(&config_path).canonicalize()?;
|
||||
pub(crate) fn bundle(config_path: String) -> anyhow::Result<()> {
|
||||
let config_path = std::path::Path::new(&config_path)
|
||||
.canonicalize()
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Error reading config file from {}\n\n{}",
|
||||
&config_path, "You may want to create a neutauri.toml via the init subcommand?"
|
||||
)
|
||||
})?;
|
||||
let config: data::Config = toml::from_str(fs::read_to_string(&config_path)?.as_str())
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
.with_context(|| "toml parsing error")?;
|
||||
let source = match config_path.parent() {
|
||||
Some(path) => path.join(&config.source).canonicalize()?,
|
||||
None => config.source.canonicalize()?,
|
||||
@ -74,14 +77,13 @@ pub fn bundle(config_path: String) -> anyhow::Result<()> {
|
||||
None => data::normalize_path(&config.target),
|
||||
};
|
||||
fs::create_dir_all(target.parent().unwrap_or_else(|| std::path::Path::new("/")))?;
|
||||
let target = if target.extension() == None && cfg!(windows) {
|
||||
let target = if target.extension().is_none() && cfg!(windows) {
|
||||
target.with_extension("exe")
|
||||
} else {
|
||||
target
|
||||
};
|
||||
if target.extension() == Some(std::ffi::OsStr::new("neu")) {
|
||||
data::pack(config_path)?;
|
||||
return Ok(());
|
||||
return data::pack(config_path);
|
||||
}
|
||||
let data = data::Data::build_from_dir(source, config.window_attr()?, config.webview_attr()?)?;
|
||||
let mut f = options().open(&target)?;
|
||||
|
@ -1,38 +1,34 @@
|
||||
use anyhow::{Context, Result};
|
||||
use neutauri_data as data;
|
||||
use std::{fs, io::Read, path::PathBuf};
|
||||
use std::{fs, io::Read, path::PathBuf, borrow::Cow};
|
||||
use wry::{
|
||||
application::{
|
||||
dpi::{PhysicalSize, Size},
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
event::{Event, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
window::{Fullscreen, Icon, Window, WindowBuilder},
|
||||
},
|
||||
webview::{WebContext, WebViewBuilder},
|
||||
};
|
||||
|
||||
const PROTOCOL_PREFIX: &str = "{PROTOCOL}://";
|
||||
const PROTOCOL_PREFIX: &str = "dev://localhost";
|
||||
const PROTOCOL: &str = "dev";
|
||||
|
||||
fn custom_protocol_uri<T: Into<String>>(protocol: T, path: T) -> String {
|
||||
PROTOCOL_PREFIX.replacen("{PROTOCOL}", &protocol.into(), 1) + &path.into()
|
||||
}
|
||||
fn custom_protocol_uri_to_path<T: Into<String>>(protocol: T, uri: T) -> wry::Result<String> {
|
||||
let prefix = PROTOCOL_PREFIX.replacen("{PROTOCOL}", &protocol.into(), 1);
|
||||
let uri = uri.into();
|
||||
let path = uri.strip_prefix(&prefix);
|
||||
match path {
|
||||
Some(str) => Ok(str.to_string()),
|
||||
None => Err(wry::Error::Io(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidInput,
|
||||
prefix + " is not found in " + &uri,
|
||||
))),
|
||||
}
|
||||
fn custom_protocol_uri<T: Into<String>>(path: T) -> String {
|
||||
PROTOCOL_PREFIX.to_owned() + &path.into()
|
||||
}
|
||||
|
||||
pub fn dev(config_path: String) -> wry::Result<()> {
|
||||
let config_path = std::path::Path::new(&config_path).canonicalize()?;
|
||||
let config: data::Config = toml::from_str(fs::read_to_string(&config_path)?.as_str())
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
||||
pub(crate) fn dev(config_path: String) -> Result<()> {
|
||||
let config_path = std::path::Path::new(&config_path)
|
||||
.canonicalize()
|
||||
.with_context(|| {
|
||||
format!(
|
||||
"Error reading config file from {}\n\n{}",
|
||||
&config_path, "You may want to create a neutauri.toml via the init subcommand?"
|
||||
)
|
||||
})?;
|
||||
let config: data::Config = toml::from_str(fs::read_to_string(config_path)?.as_str())
|
||||
.with_context(|| "toml parsing error")?;
|
||||
let source = config.source.canonicalize()?;
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
@ -85,12 +81,12 @@ pub fn dev(config_path: String) -> wry::Result<()> {
|
||||
let webview_builder = match url {
|
||||
Some(url) => {
|
||||
if url.starts_with('/') {
|
||||
webview_builder.with_url(&custom_protocol_uri(PROTOCOL, &url))?
|
||||
webview_builder.with_url(&custom_protocol_uri(&url))?
|
||||
} else {
|
||||
webview_builder.with_url(&url)?
|
||||
}
|
||||
}
|
||||
None => webview_builder.with_url(&custom_protocol_uri(PROTOCOL, "/index.html"))?,
|
||||
None => webview_builder.with_url(&custom_protocol_uri("/index.html"))?,
|
||||
};
|
||||
let html = config.webview_attr()?.html;
|
||||
let webview_builder = match html {
|
||||
@ -140,13 +136,14 @@ pub fn dev(config_path: String) -> wry::Result<()> {
|
||||
WebContext::new(None)
|
||||
};
|
||||
let webview = webview_builder
|
||||
.with_clipboard(true)
|
||||
.with_visible(config.window_attr()?.visible)
|
||||
.with_transparent(config.window_attr()?.transparent)
|
||||
.with_web_context(&mut web_context)
|
||||
.with_custom_protocol(PROTOCOL.to_string(), move |request| {
|
||||
let path = custom_protocol_uri_to_path(PROTOCOL, request.uri())?;
|
||||
let path = request.uri().path();
|
||||
let mut local_path = source.clone();
|
||||
local_path.push(path.strip_prefix('/').unwrap_or(&path));
|
||||
local_path.push(path.strip_prefix('/').unwrap_or(path));
|
||||
let mut data = Vec::new();
|
||||
let mut mime: String = "application/octet-stream".to_string();
|
||||
match fs::File::open(&local_path) {
|
||||
@ -168,7 +165,11 @@ pub fn dev(config_path: String) -> wry::Result<()> {
|
||||
}
|
||||
}
|
||||
}
|
||||
wry::http::ResponseBuilder::new().mimetype(&mime).body(data)
|
||||
wry::http::Response::builder()
|
||||
.header("Content-Type", mime)
|
||||
.header("Access-Control-Allow-Origin", "*")
|
||||
.body(Cow::Owned(data))
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.with_ipc_handler(|window: &Window, req: String| {
|
||||
match req.as_str() {
|
||||
@ -184,11 +185,13 @@ pub fn dev(config_path: String) -> wry::Result<()> {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::NewEvents(StartCause::Init) => webview.focus(),
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
..
|
||||
} => *control_flow = ControlFlow::Exit,
|
||||
Event::GlobalShortcutEvent(id) => webview
|
||||
.evaluate_script(&format!("GlobalShortcutEvent({:})", id.0))
|
||||
.unwrap_or_default(),
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
45
neutauri_bundler/src/init.rs
Normal file
45
neutauri_bundler/src/init.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use anyhow::Ok;
|
||||
use neutauri_data as data;
|
||||
|
||||
const TEMPLATE: &str = include_str!("../../neutauri.toml.example");
|
||||
|
||||
pub(crate) fn init() -> anyhow::Result<()> {
|
||||
let config = TEMPLATE;
|
||||
let config = config.replace(
|
||||
"Neutauri Demo",
|
||||
&inquire::Text::new("The name of your program? (for window title)")
|
||||
.with_placeholder("Neutauri App")
|
||||
.with_default("Neutauri App")
|
||||
.prompt()?,
|
||||
);
|
||||
let config = config.replace(
|
||||
"web_src",
|
||||
&inquire::Text::new("Where is your web source code? (relative to the current directory)")
|
||||
.with_placeholder("web_src")
|
||||
.with_default("web_src")
|
||||
.prompt()?,
|
||||
);
|
||||
let config = config.replace(
|
||||
"neutauri_demo",
|
||||
&inquire::Text::new("The name of your output target?")
|
||||
.with_placeholder("app")
|
||||
.with_default("app")
|
||||
.prompt()?,
|
||||
);
|
||||
let config = config.replacen(
|
||||
"Small",
|
||||
inquire::Select::new(
|
||||
"The default size of the window?",
|
||||
vec!["Small", "Medium", "Large"],
|
||||
)
|
||||
.prompt()?,
|
||||
1,
|
||||
);
|
||||
let config_path = data::normalize_path(std::path::Path::new("./neutauri.toml"));
|
||||
std::fs::write(&config_path, config)?;
|
||||
eprintln!(
|
||||
"The configuration file has been written to \"{}\"",
|
||||
config_path.display()
|
||||
);
|
||||
Ok(())
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
use gumdrop::Options;
|
||||
mod bundle;
|
||||
mod dev;
|
||||
mod init;
|
||||
|
||||
#[derive(Debug, Options)]
|
||||
struct Args {
|
||||
@ -19,6 +20,8 @@ enum Command {
|
||||
Bundle(BundleOpts),
|
||||
#[options(help = "run the project in the current directory in development mode")]
|
||||
Dev(DevOpts),
|
||||
#[options(help = "initialize a neutauri project")]
|
||||
Init(InitOpts),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Options)]
|
||||
@ -37,6 +40,12 @@ struct DevOpts {
|
||||
config: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Options)]
|
||||
struct InitOpts {
|
||||
#[options(help = "print help information")]
|
||||
help: bool,
|
||||
}
|
||||
|
||||
fn print_help_and_exit(args: Args) {
|
||||
if args.command.is_some() {
|
||||
Args::parse_args_default_or_exit();
|
||||
@ -45,7 +54,6 @@ fn print_help_and_exit(args: Args) {
|
||||
eprintln!(
|
||||
"Usage: {:?} [SUBCOMMAND] [OPTIONS]",
|
||||
std::env::args()
|
||||
.into_iter()
|
||||
.next()
|
||||
.unwrap_or_else(|| "neutauri_bundler".to_string())
|
||||
);
|
||||
@ -67,6 +75,8 @@ fn main() -> anyhow::Result<()> {
|
||||
Some(command) => match command {
|
||||
Command::Bundle(opts) => {
|
||||
if opts.help_requested() {
|
||||
eprintln!("Package according to the configuration in neutauri.toml");
|
||||
eprintln!();
|
||||
print_help_and_exit(args);
|
||||
}
|
||||
let config_path = opts.config.unwrap_or_else(|| "neutauri.toml".to_string());
|
||||
@ -74,11 +84,21 @@ fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
Command::Dev(opts) => {
|
||||
if opts.help_requested() {
|
||||
eprintln!("Check the configuration in neutauri.toml and start directly");
|
||||
eprintln!();
|
||||
print_help_and_exit(args);
|
||||
}
|
||||
let config_path = opts.config.unwrap_or_else(|| "neutauri.toml".to_string());
|
||||
dev::dev(config_path)?;
|
||||
}
|
||||
Command::Init(opts) => {
|
||||
if opts.help_requested() {
|
||||
eprintln!("Interactively create a neutauri.toml configuration file");
|
||||
eprintln!();
|
||||
print_help_and_exit(args);
|
||||
}
|
||||
init::init()?;
|
||||
}
|
||||
},
|
||||
None => print_help_and_exit(args),
|
||||
}
|
||||
|
@ -4,14 +4,16 @@ name = "neutauri_data"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
anyhow = {version = "1.0", optional = true}
|
||||
bincode = "1.3"
|
||||
brotli = "3.3"
|
||||
image = {version = "0.24", optional = true}
|
||||
new_mime_guess = {version = "4.0", optional = true}
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
toml = {version = "0.5", optional = true}
|
||||
wry = {version = "0.19", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen"]}
|
||||
toml = {version = "0.7", optional = true}
|
||||
wry = {version = "0.27", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen"]}
|
||||
|
||||
[features]
|
||||
bundler = ["new_mime_guess", "toml", "image"]
|
||||
default = ["runtime"]
|
||||
bundler = ["anyhow", "new_mime_guess", "toml", "image"]
|
||||
runtime = []
|
@ -2,7 +2,7 @@ use bincode::Options;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
fs,
|
||||
io::{self, Read, Result, SeekFrom, Seek},
|
||||
io::{self, Read, Result},
|
||||
path::{self, Component, Path, PathBuf},
|
||||
};
|
||||
use wry::application::dpi::Position;
|
||||
@ -120,6 +120,7 @@ impl File {
|
||||
#[cfg(feature = "runtime")]
|
||||
impl Data {
|
||||
pub fn new<P: AsRef<path::Path> + Copy>(path: P) -> Result<Self> {
|
||||
use std::io::{Seek, SeekFrom};
|
||||
let mut base = fs::File::open(path)?;
|
||||
let base_length = base.metadata()?.len();
|
||||
let mut magic_number_start_data = [0; MAGIC_NUMBER_START.len()];
|
||||
@ -168,7 +169,7 @@ impl Data {
|
||||
Ok(fs)
|
||||
}
|
||||
|
||||
fn open_file(&self, current_dir: &Dir, mut path: path::Iter) -> Result<File> {
|
||||
fn open_file(current_dir: &Dir, mut path: path::Iter) -> Result<File> {
|
||||
let next_path = match path.next() {
|
||||
Some(str) => str.to_string_lossy().to_string(),
|
||||
None => return Err(io::Error::new(io::ErrorKind::NotFound, "file not found")),
|
||||
@ -180,7 +181,7 @@ impl Data {
|
||||
}
|
||||
for (name, dir) in ¤t_dir.dirs {
|
||||
if next_path == *name {
|
||||
return self.open_file(dir, path);
|
||||
return Self::open_file(dir, path);
|
||||
}
|
||||
}
|
||||
Err(io::Error::new(io::ErrorKind::NotFound, "file not found"))
|
||||
@ -195,7 +196,7 @@ impl Data {
|
||||
} else {
|
||||
path
|
||||
};
|
||||
self.open_file(&self.fs, path.iter())
|
||||
Self::open_file(&self.fs, path.iter())
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +297,7 @@ impl Data {
|
||||
|
||||
let mut target: Vec<u8> = Vec::new();
|
||||
target.extend(MAGIC_NUMBER_START);
|
||||
target.extend(&data.len().to_be_bytes());
|
||||
target.extend(data.len().to_be_bytes());
|
||||
target.extend(&data);
|
||||
let target_length = target.len();
|
||||
let target_length = target_length + USIZE_LEN;
|
||||
@ -307,7 +308,7 @@ impl Data {
|
||||
Ok(target)
|
||||
}
|
||||
|
||||
pub fn pack<P: AsRef<path::Path>>(config_path: P) -> Result<()> {
|
||||
pub fn pack<P: AsRef<path::Path>>(config_path: P) -> anyhow::Result<()> {
|
||||
let config_path = config_path.as_ref().canonicalize()?;
|
||||
let config: Config = toml::from_str(fs::read_to_string(&config_path)?.as_str())?;
|
||||
let source = match config_path.parent() {
|
||||
@ -399,7 +400,7 @@ pub fn load<P: AsRef<path::Path> + Copy>(path: P) -> Result<Data> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "bundler")]
|
||||
pub fn pack<P: AsRef<path::Path>>(config: P) -> Result<()> {
|
||||
pub fn pack<P: AsRef<path::Path>>(config: P) -> anyhow::Result<()> {
|
||||
Data::pack(config)
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,9 @@ name = "neutauri_runtime"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
neutauri_data = {path = "../neutauri_data", features = ["runtime"]}
|
||||
wry = {version = "0.19", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen"]}
|
||||
neutauri_data = {path = "../neutauri_data", default-features = false, features = ["runtime"]}
|
||||
vc-ltl = "5.0.5"
|
||||
wry = {version = "0.27", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen"]}
|
||||
|
||||
[target.'cfg(windows)'.build-dependencies]
|
||||
winres = "0.1"
|
||||
|
@ -1,34 +1,22 @@
|
||||
#![windows_subsystem = "windows"]
|
||||
|
||||
use neutauri_data as data;
|
||||
use std::path::PathBuf;
|
||||
use std::{borrow::Cow, path::PathBuf};
|
||||
use wry::{
|
||||
application::{
|
||||
dpi::{PhysicalSize, Size},
|
||||
event::{Event, StartCause, WindowEvent},
|
||||
event::{Event, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
window::{Fullscreen, Icon, Window, WindowBuilder},
|
||||
},
|
||||
webview::{WebContext, WebViewBuilder},
|
||||
};
|
||||
|
||||
const PROTOCOL_PREFIX: &str = "{PROTOCOL}://";
|
||||
const PROTOCOL_PREFIX: &str = "neu://localhost";
|
||||
const PROTOCOL: &str = "neu";
|
||||
|
||||
fn custom_protocol_uri<T: Into<String>>(protocol: T, path: T) -> String {
|
||||
PROTOCOL_PREFIX.replacen("{PROTOCOL}", &protocol.into(), 1) + &path.into()
|
||||
}
|
||||
fn custom_protocol_uri_to_path<T: Into<String>>(protocol: T, uri: T) -> wry::Result<String> {
|
||||
let prefix = PROTOCOL_PREFIX.replacen("{PROTOCOL}", &protocol.into(), 1);
|
||||
let uri = uri.into();
|
||||
let path = uri.strip_prefix(&prefix);
|
||||
match path {
|
||||
Some(str) => Ok(str.to_string()),
|
||||
None => Err(wry::Error::Io(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidInput,
|
||||
prefix + " is not found in " + &uri,
|
||||
))),
|
||||
}
|
||||
fn custom_protocol_uri<T: Into<String>>(path: T) -> String {
|
||||
PROTOCOL_PREFIX.to_owned() + &path.into()
|
||||
}
|
||||
|
||||
fn main() -> wry::Result<()> {
|
||||
@ -86,12 +74,12 @@ fn main() -> wry::Result<()> {
|
||||
let webview_builder = match url {
|
||||
Some(url) => {
|
||||
if url.starts_with('/') {
|
||||
webview_builder.with_url(&custom_protocol_uri(PROTOCOL, &url))?
|
||||
webview_builder.with_url(&custom_protocol_uri(&url))?
|
||||
} else {
|
||||
webview_builder.with_url(&url)?
|
||||
}
|
||||
}
|
||||
None => webview_builder.with_url(&custom_protocol_uri(PROTOCOL, "/index.html"))?,
|
||||
None => webview_builder.with_url(&custom_protocol_uri("/index.html"))?,
|
||||
};
|
||||
let html = res.webview_attr.html.clone();
|
||||
let webview_builder = match html {
|
||||
@ -141,6 +129,7 @@ fn main() -> wry::Result<()> {
|
||||
WebContext::new(None)
|
||||
};
|
||||
let webview = webview_builder
|
||||
.with_clipboard(true)
|
||||
.with_visible(res.window_attr.visible)
|
||||
.with_transparent(res.window_attr.transparent)
|
||||
.with_web_context(&mut web_context)
|
||||
@ -148,20 +137,24 @@ fn main() -> wry::Result<()> {
|
||||
r#"window.oncontextmenu = (event) => { event.preventDefault(); }"#,
|
||||
)
|
||||
.with_custom_protocol(PROTOCOL.to_string(), move |request| {
|
||||
let path = custom_protocol_uri_to_path(PROTOCOL, request.uri())?;
|
||||
let path = request.uri().path();
|
||||
let mut file = match res.open(path) {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::NotFound && res.webview_attr.spa {
|
||||
if e.kind() == std::io::ErrorKind::NotFound
|
||||
&& res.webview_attr.spa
|
||||
&& path != "/index.html"
|
||||
{
|
||||
res.open("index.html")?
|
||||
} else {
|
||||
return Err(wry::Error::Io(e));
|
||||
}
|
||||
}
|
||||
};
|
||||
wry::http::ResponseBuilder::new()
|
||||
.mimetype(&file.mimetype())
|
||||
.body(file.decompressed_data()?)
|
||||
wry::http::Response::builder()
|
||||
.header("Content-Type", file.mimetype())
|
||||
.body(Cow::Owned(file.decompressed_data()?))
|
||||
.map_err(|e| e.into())
|
||||
})
|
||||
.with_ipc_handler(|window: &Window, req: String| {
|
||||
match req.as_str() {
|
||||
@ -177,11 +170,13 @@ fn main() -> wry::Result<()> {
|
||||
*control_flow = ControlFlow::Wait;
|
||||
|
||||
match event {
|
||||
Event::NewEvents(StartCause::Init) => webview.focus(),
|
||||
Event::WindowEvent {
|
||||
event: WindowEvent::CloseRequested,
|
||||
..
|
||||
} => *control_flow = ControlFlow::Exit,
|
||||
Event::GlobalShortcutEvent(id) => webview
|
||||
.evaluate_script(&format!("GlobalShortcutEvent({:})", id.0))
|
||||
.unwrap_or_default(),
|
||||
_ => (),
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user