This commit is contained in:
Tim-Paik 2023-03-24 21:40:29 +08:00
parent 1bebb857ee
commit 167bee14e7
Signed by: Tim-Paik
GPG Key ID: DC36A050DB42566D
10 changed files with 483 additions and 469 deletions

916
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -6,12 +6,12 @@ version = "0.1.0"
[dependencies]
anyhow = "1.0"
gumdrop = "0.8"
inquire = "0.5"
inquire = "0.6"
neutauri_data = {path = "../neutauri_data", features = ["bundler"]}
new_mime_guess = "4.0"
serde = {version = "1.0", features = ["derive"]}
toml = "0.5"
wry = {version = "0.23", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen", "devtools"]}
toml = "0.7"
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"}

View File

@ -83,8 +83,7 @@ pub(crate) fn bundle(config_path: String) -> anyhow::Result<()> {
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)?;

View File

@ -1,6 +1,6 @@
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},
@ -168,7 +168,7 @@ pub(crate) fn dev(config_path: String) -> Result<()> {
wry::http::Response::builder()
.header("Content-Type", mime)
.header("Access-Control-Allow-Origin", "*")
.body(data)
.body(Cow::Owned(data))
.map_err(|e| e.into())
})
.with_ipc_handler(|window: &Window, req: String| {

View File

@ -54,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())
);

View File

@ -4,14 +4,15 @@ 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.23", 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"]
bundler = ["anyhow", "new_mime_guess", "toml", "image"]
runtime = []

View File

@ -307,7 +307,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 +399,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)
}

BIN
neutauri_demo Executable file

Binary file not shown.

View File

@ -5,7 +5,7 @@ version = "0.1.0"
[dependencies]
neutauri_data = {path = "../neutauri_data", features = ["runtime"]}
wry = {version = "0.23", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen"]}
wry = {version = "0.27", default-features = false, features = ["protocol", "tray", "transparent", "fullscreen"]}
[target.'cfg(windows)'.build-dependencies]
winres = "0.1"

View File

@ -1,7 +1,7 @@
#![windows_subsystem = "windows"]
use neutauri_data as data;
use std::path::PathBuf;
use std::{borrow::Cow, path::PathBuf};
use wry::{
application::{
dpi::{PhysicalSize, Size},
@ -141,7 +141,10 @@ fn main() -> wry::Result<()> {
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));
@ -150,7 +153,7 @@ fn main() -> wry::Result<()> {
};
wry::http::Response::builder()
.header("Content-Type", file.mimetype())
.body(file.decompressed_data()?)
.body(Cow::Owned(file.decompressed_data()?))
.map_err(|e| e.into())
})
.with_ipc_handler(|window: &Window, req: String| {