Browse Source

bundler ready

main
Tim-Paik 5 months ago
parent
commit
4df957fdf3
Signed by: Tim-Paik
GPG Key ID: DC36A050DB42566D
  1. 6
      .cargo/config.toml
  2. 1
      .gitignore
  3. 133
      Cargo.lock
  4. 17
      neutauri.toml.example
  5. 8
      neutauri_bundler/Cargo.toml
  6. 332
      neutauri_bundler/src/data.rs
  7. 50
      neutauri_bundler/src/main.rs
  8. 3
      neutauri_runtime/Cargo.toml
  9. 176
      neutauri_runtime/src/data.rs
  10. 1
      neutauri_runtime/src/main.rs
  11. 1
      web_src/build/bundle.css
  12. 2
      web_src/build/bundle.js
  13. 1
      web_src/build/bundle.js.map
  14. BIN
      web_src/favicon.png
  15. 63
      web_src/global.css
  16. 18
      web_src/index.html

6
.cargo/config.toml

@ -0,0 +1,6 @@
[profile.release]
lto = true
opt-level = "z"
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

1
.gitignore vendored

@ -1 +1,2 @@
/target
neutauri.toml

133
Cargo.lock generated

@ -59,17 +59,6 @@ dependencies = [
"system-deps 3.2.0",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.0.1"
@ -187,36 +176,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08799f92c961c7a1cf0cc398a9073da99e21ce388b46372c37f3191f2f3eed3e"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"indexmap",
"lazy_static",
"os_str_bytes",
"strsim 0.10.0",
"termcolor",
"textwrap",
]
[[package]]
name = "clap_derive"
version = "3.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fd2078197a22f338bd4fbf7d6387eb6f0d6a3c69e6cbc09f5c93e97321fd92a"
dependencies = [
"heck 0.4.0",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "cocoa"
version = "0.24.0"
@ -446,7 +405,7 @@ dependencies = [
"ident_case",
"proc-macro2",
"quote",
"strsim 0.9.3",
"strsim",
"syn",
]
@ -712,7 +671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2aad66361f66796bfc73f530c51ef123970eb895ffba991a234fcf7bea89e518"
dependencies = [
"anyhow",
"heck 0.3.3",
"heck",
"proc-macro-crate 1.1.0",
"proc-macro-error",
"proc-macro2",
@ -810,7 +769,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21de1da96dc117443fb03c2e270b2d34b7de98d0a79a19bbb689476173745b79"
dependencies = [
"anyhow",
"heck 0.3.3",
"heck",
"proc-macro-crate 1.1.0",
"proc-macro-error",
"proc-macro2",
@ -818,12 +777,6 @@ dependencies = [
"syn",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
[[package]]
name = "heck"
version = "0.3.3"
@ -833,12 +786,6 @@ dependencies = [
"unicode-segmentation",
]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
version = "0.1.19"
@ -895,16 +842,6 @@ dependencies = [
"tiff",
]
[[package]]
name = "indexmap"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -1008,12 +945,6 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "memchr"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
[[package]]
name = "memoffset"
version = "0.6.5"
@ -1098,7 +1029,13 @@ checksum = "e1bcdd74c20ad5d95aacd60ef9ba40fdf77f767051040541df557b7a9b2a2121"
name = "neutauri_bundler"
version = "0.1.0"
dependencies = [
"clap",
"bincode",
"brotli",
"image",
"new_mime_guess",
"serde",
"toml",
"wry",
]
[[package]]
@ -1107,10 +1044,7 @@ version = "0.1.0"
dependencies = [
"bincode",
"brotli",
"image",
"new_mime_guess",
"serde",
"toml",
"wry",
]
@ -1220,15 +1154,6 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]]
name = "pango"
version = "0.14.8"
@ -1547,12 +1472,6 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
version = "0.18.0"
@ -1571,7 +1490,7 @@ version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87c85aa3f8ea653bfd3ddf25f7ee357ee4d204731f6aa9ad04002306f6e2774c"
dependencies = [
"heck 0.3.3",
"heck",
"proc-macro2",
"quote",
"syn",
@ -1583,7 +1502,7 @@ version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d06aaeeee809dbc59eb4556183dd927df67db1540de5be8d3ec0b6636358a5ec"
dependencies = [
"heck 0.3.3",
"heck",
"proc-macro2",
"quote",
"syn",
@ -1606,7 +1525,7 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3ecc17269a19353b3558b313bba738b25d82993e30d62a18406a24aba4649b"
dependencies = [
"heck 0.3.3",
"heck",
"pkg-config",
"strum 0.18.0",
"strum_macros 0.18.0",
@ -1623,7 +1542,7 @@ checksum = "480c269f870722b3b08d2f13053ce0c2ab722839f472863c3e2d61ff3a1c2fa6"
dependencies = [
"anyhow",
"cfg-expr",
"heck 0.3.3",
"heck",
"itertools",
"pkg-config",
"strum 0.21.0",
@ -1696,21 +1615,6 @@ dependencies = [
"pkg-config",
]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
[[package]]
name = "thiserror"
version = "1.0.30"
@ -1935,15 +1839,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

17
neutauri.toml.example

@ -0,0 +1,17 @@
# Neutauri Config
## Source and Target
source = "web_src"
target = "neutauri_demo"
## Window
always_on_top = false
decorations = true
fullscreen = false
inner_size = "Small" ## "Small", "Medium", "Large"
maximized = false
resizable = true
spa = false
title = "Neutauri Demo"
transparent = false
visible = true

8
neutauri_bundler/Cargo.toml

@ -4,4 +4,10 @@ name = "neutauri_bundler"
version = "0.1.0"
[dependencies]
clap = {version = "3.0", features = ["derive"]}
bincode = "1.3"
brotli = "3.3"
image = "0.23"
new_mime_guess = "4.0"
serde = {version = "1.0", features = ["derive"]}
toml = "0.5"
wry = "0.12"

332
neutauri_bundler/src/data.rs

@ -0,0 +1,332 @@
use bincode::Options;
use serde::{Deserialize, Serialize};
use std::{
fs,
io::{self, Read, Result},
path::{self, Component, Path, PathBuf},
};
use wry::application::dpi::Position;
const MAGIC_NUMBER_START: &[u8; 9] = b"NEUTFSv01";
const MAGIC_NUMBER_END: &[u8; 9] = b"NEUTFSEnd";
const USIZE_LEN: usize = usize::MAX.to_be_bytes().len();
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum Compress {
Brotli,
None,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct File {
mime: String,
data: Vec<u8>,
compress: Compress,
}
#[derive(Serialize, Deserialize, Debug)]
struct Dir {
files: Vec<(String, File)>,
dirs: Vec<(String, Dir)>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Data {
pub window_attr: WindowAttr,
pub webview_attr: WebViewAttr,
fs: Dir,
}
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
pub enum WindowSize {
Large,
Medium,
Small,
Fixed { width: f64, height: f64 },
Scale { factor: f64 },
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Config {
pub source: PathBuf,
pub target: PathBuf,
pub inner_size: Option<WindowSize>,
pub min_inner_size: Option<WindowSize>,
pub max_inner_size: Option<WindowSize>,
pub resizable: bool,
pub fullscreen: bool,
pub title: String,
pub maximized: bool,
pub visible: bool,
pub transparent: bool,
pub decorations: bool,
pub always_on_top: bool,
pub window_icon: Option<PathBuf>,
pub spa: bool,
pub url: Option<String>,
pub html: Option<PathBuf>,
pub initialization_script: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Debug, Default)]
pub struct Icon {
pub rgba: Vec<u8>,
pub width: u32,
pub height: u32,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WindowAttr {
pub inner_size: Option<WindowSize>,
pub min_inner_size: Option<WindowSize>,
pub max_inner_size: Option<WindowSize>,
pub position: Option<Position>,
pub resizable: bool,
pub fullscreen: bool,
pub title: String,
pub maximized: bool,
pub visible: bool,
pub transparent: bool,
pub decorations: bool,
pub always_on_top: bool,
pub window_icon: Option<Icon>,
}
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WebViewAttr {
pub visible: bool,
pub transparent: bool,
pub spa: bool,
pub url: Option<String>,
pub html: Option<String>,
pub initialization_script: Option<String>,
}
impl Dir {
// 使用本地文件系统填充 Dir 结构体
fn fill_with<P: AsRef<path::Path>>(
&mut self,
root: P,
path: P,
length: &mut u64,
) -> Result<()> {
// 遍历目录
for entry in fs::read_dir(path)? {
let path = entry?.path();
// 获取目录/文件名,如果为".."则跳过
let name = match path.file_name() {
Some(s) => match s.to_str() {
Some(s) => s.to_string(),
None => break,
},
None => break,
};
// 优先填充文件
if path.is_file() {
let mut source = fs::File::open(&path)?;
let mime = new_mime_guess::from_path(&path)
.first_or_octet_stream()
.to_string();
let mut data = brotli::CompressorReader::new(&mut source, 4096, 9, 21);
let mut buffer = Vec::new();
data.read_to_end(&mut buffer)?;
let size = buffer.len();
let file = File {
mime,
data: buffer,
compress: Compress::Brotli,
};
*length += size as u64;
self.files.push((name, file));
} else if path.is_dir() {
// 构造子目录
let mut dir = Dir {
files: Vec::new(),
dirs: Vec::new(),
};
// 填充子目录
dir.fill_with(root.as_ref(), &path, length)?;
self.dirs.push((name, dir));
}
}
Ok(())
}
}
impl Data {
pub fn build_from_dir<P: AsRef<path::Path>>(
source: P,
window_attr: WindowAttr,
webview_attr: WebViewAttr,
) -> Result<Vec<u8>> {
let embed_fs = Self::from_dir(source, window_attr, webview_attr)?;
embed_fs.build()
}
fn from_dir<P: AsRef<path::Path>>(
source: P,
window_attr: WindowAttr,
webview_attr: WebViewAttr,
) -> Result<Self> {
let source = source.as_ref();
let mut length: u64 = 0;
let mut dir = Dir {
files: Vec::new(),
dirs: Vec::new(),
};
dir.fill_with(source, source, &mut length)?;
Ok(Self {
fs: dir,
window_attr,
webview_attr,
})
}
fn build(self) -> Result<Vec<u8>> {
let serialize_options = bincode::DefaultOptions::new()
.with_fixint_encoding()
.allow_trailing_bytes()
.with_limit(104857600 /* 100MiB */);
// 构建文件头
let data = match serialize_options.serialize(&self) {
Ok(vec) => vec,
Err(e) => {
return Err(io::Error::new(io::ErrorKind::InvalidData, e));
}
};
let mut target: Vec<u8> = Vec::new();
target.extend(MAGIC_NUMBER_START);
target.extend(&data.len().to_be_bytes());
target.extend(&data);
let target_length = target.len();
let target_length = target_length + USIZE_LEN;
let target_length = target_length + MAGIC_NUMBER_END.len();
target.extend(target_length.to_be_bytes());
target.extend(MAGIC_NUMBER_END);
Ok(target)
}
pub fn pack<P: AsRef<path::Path>>(config_path: P) -> 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() {
Some(path) => path.join(&config.source).canonicalize()?,
None => config.source.canonicalize()?,
};
let target = match config_path.parent() {
Some(path) => normalize_path(&path.join(&config.target)),
None => normalize_path(&config.target),
};
fs::write(
target,
Self::build_from_dir(source, config.window_attr()?, config.webview_attr()?)?,
)?;
Ok(())
}
}
impl Default for Config {
fn default() -> Self {
Self {
source: PathBuf::from("."),
target: PathBuf::from("app.neu"),
inner_size: Some(WindowSize::Medium),
min_inner_size: None,
max_inner_size: None,
resizable: true,
fullscreen: false,
title: "".to_string(),
maximized: false,
visible: true,
transparent: false,
decorations: true,
always_on_top: false,
window_icon: None,
spa: false,
url: Some("/index.html".to_string()),
html: None,
initialization_script: Some("".to_string()),
}
}
}
impl Config {
pub fn window_attr(&self) -> Result<WindowAttr> {
Ok(WindowAttr {
inner_size: self.inner_size,
min_inner_size: self.min_inner_size,
max_inner_size: self.max_inner_size,
position: None,
resizable: self.resizable,
fullscreen: self.fullscreen,
title: self.title.clone(),
maximized: self.maximized,
visible: self.visible,
transparent: self.transparent,
decorations: self.decorations,
always_on_top: self.always_on_top,
window_icon: match &self.window_icon {
Some(path) => Some(load_icon(path.as_path())?),
None => None,
},
})
}
pub fn webview_attr(&self) -> Result<WebViewAttr> {
Ok(WebViewAttr {
visible: self.visible,
transparent: self.transparent,
spa: self.spa,
url: self.url.clone(),
html: match &self.html {
Some(path) => fs::read_to_string(path.as_path()).ok(),
None => None,
},
initialization_script: self.initialization_script.clone(),
})
}
}
pub fn pack<P: AsRef<path::Path>>(config: P) -> Result<()> {
Data::pack(config)
}
fn load_icon(path: &Path) -> Result<Icon> {
let image = image::open(path)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
.to_rgba8();
Ok(Icon {
width: image.dimensions().0,
height: image.dimensions().1,
rgba: image.into_raw(),
})
}
pub fn normalize_path(path: &Path) -> PathBuf {
let mut components = path.components().peekable();
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
components.next();
PathBuf::from(c.as_os_str())
} else {
PathBuf::new()
};
for component in components {
match component {
Component::Prefix(..) => unreachable!(),
Component::RootDir => {
ret.push(component.as_os_str());
}
Component::CurDir => {}
Component::ParentDir => {
ret.pop();
}
Component::Normal(c) => {
ret.push(c);
}
}
}
ret
}

50
neutauri_bundler/src/main.rs

@ -1,15 +1,41 @@
use clap::Parser;
use std::{fs, io::Write};
/// Simple program to greet a person
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
/// Path to Congfig
#[clap(short, long)]
config: String,
}
mod data;
fn main() {
let args = Args::parse();
println!("{}", args.config);
fn main() -> wry::Result<()> {
let arg = std::env::args().nth(1).unwrap_or_else(|| "neutauri.toml".to_string());
if arg == "--help" || arg == "-h" {
println!("Usage: neutauri_bundler [neutauri.toml]");
return Ok(());
}
let config_path = std::path::Path::new(&arg).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))?;
let source = match config_path.parent() {
Some(path) => path.join(&config.source).canonicalize()?,
None => config.source.canonicalize()?,
};
let target = match config_path.parent() {
Some(path) => data::normalize_path(&path.join(&config.target)),
None => data::normalize_path(&config.target),
};
if target.extension() == Some(std::ffi::OsStr::new("neu")) {
data::pack(arg)?;
return Ok(());
}
let data = data::Data::build_from_dir(source, config.window_attr()?, config.webview_attr()?)?;
let mut option = fs::OpenOptions::new();
let option = option.write(true).create(true).truncate(true);
let option = if cfg!(unix) {
std::os::unix::prelude::OpenOptionsExt::mode(option, 0o755)
} else {
option
};
let mut f = option.open(&target)?;
let runtime_data = include_bytes!("../../target/release/neutauri_runtime");
f.write_all(runtime_data)?;
f.write_all(&data)?;
f.sync_all()?;
f.flush()?;
Ok(())
}

3
neutauri_runtime/Cargo.toml

@ -6,8 +6,5 @@ version = "0.1.0"
[dependencies]
bincode = "1.3"
brotli = "3.3"
image = "0.23"
new_mime_guess = "4.0"
serde = {version = "1.0", features = ["derive"]}
toml = "0.5"
wry = "0.12"

176
neutauri_runtime/src/data.rs

@ -115,130 +115,7 @@ impl File {
}
}
impl Dir {
// 使用本地文件系统填充 Dir 结构体
fn fill_with<P: AsRef<path::Path>>(
&mut self,
root: P,
path: P,
length: &mut u64,
) -> Result<()> {
// 遍历目录
for entry in fs::read_dir(path)? {
let path = entry?.path();
// 获取目录/文件名,如果为".."则跳过
let name = match path.file_name() {
Some(s) => match s.to_str() {
Some(s) => s.to_string(),
None => break,
},
None => break,
};
// 优先填充文件
if path.is_file() {
let mut source = fs::File::open(&path)?;
let mime = new_mime_guess::from_path(&path)
.first_or_octet_stream()
.to_string();
let mut data = brotli::CompressorReader::new(&mut source, 4096, 9, 21);
let mut buffer = Vec::new();
data.read_to_end(&mut buffer)?;
let size = buffer.len();
let file = File {
mime,
data: buffer,
compress: Compress::Brotli,
};
*length += size as u64;
self.files.push((name, file));
} else if path.is_dir() {
// 构造子目录
let mut dir = Dir {
files: Vec::new(),
dirs: Vec::new(),
};
// 填充子目录
dir.fill_with(root.as_ref(), &path, length)?;
self.dirs.push((name, dir));
}
}
Ok(())
}
}
impl Data {
pub fn build_from_dir<P: AsRef<path::Path>>(
source: P,
window_attr: WindowAttr,
webview_attr: WebViewAttr,
) -> Result<Vec<u8>> {
let embed_fs = Self::from_dir(source, window_attr, webview_attr)?;
embed_fs.build()
}
fn from_dir<P: AsRef<path::Path>>(
source: P,
window_attr: WindowAttr,
webview_attr: WebViewAttr,
) -> Result<Self> {
let source = source.as_ref();
let mut length: u64 = 0;
let mut dir = Dir {
files: Vec::new(),
dirs: Vec::new(),
};
dir.fill_with(source, source, &mut length)?;
Ok(Self {
fs: dir,
window_attr,
webview_attr,
})
}
fn build(self) -> Result<Vec<u8>> {
let serialize_options = bincode::DefaultOptions::new()
.with_fixint_encoding()
.allow_trailing_bytes()
.with_limit(104857600 /* 100MiB */);
// 构建文件头
let data = match serialize_options.serialize(&self) {
Ok(vec) => vec,
Err(e) => {
return Err(io::Error::new(io::ErrorKind::InvalidData, e));
}
};
let mut target: Vec<u8> = Vec::new();
target.extend(MAGIC_NUMBER_START);
target.extend(&data.len().to_be_bytes());
target.extend(&data);
let target_length = target.len();
let target_length = target_length + USIZE_LEN;
let target_length = target_length + MAGIC_NUMBER_END.len();
target.extend(target_length.to_be_bytes());
target.extend(MAGIC_NUMBER_END);
Ok(target)
}
pub fn pack<P: AsRef<path::Path>>(config_path: P) -> 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() {
Some(path) => path.join(&config.source).canonicalize()?,
None => config.source.canonicalize()?,
};
let target = match config_path.parent() {
Some(path) => normalize_path(&path.join(&config.target)),
None => normalize_path(&config.target),
};
fs::write(
target,
Self::build_from_dir(source, config.window_attr()?, config.webview_attr()?)?,
)?;
Ok(())
}
pub fn new<P: AsRef<path::Path> + Copy>(path: P) -> Result<Self> {
let mut base = fs::File::open(path)?;
let base_length = base.metadata()?.len();
@ -344,62 +221,11 @@ impl Default for Config {
}
}
impl Config {
pub fn window_attr(&self) -> Result<WindowAttr> {
Ok(WindowAttr {
inner_size: self.inner_size,
min_inner_size: self.min_inner_size,
max_inner_size: self.max_inner_size,
position: None,
resizable: self.resizable,
fullscreen: self.fullscreen,
title: self.title.clone(),
maximized: self.maximized,
visible: self.visible,
transparent: self.transparent,
decorations: self.decorations,
always_on_top: self.always_on_top,
window_icon: match &self.window_icon {
Some(path) => Some(load_icon(path.as_path())?),
None => None,
},
})
}
pub fn webview_attr(&self) -> Result<WebViewAttr> {
Ok(WebViewAttr {
visible: self.visible,
transparent: self.transparent,
spa: self.spa,
url: self.url.clone(),
html: match &self.html {
Some(path) => fs::read_to_string(path.as_path()).ok(),
None => None,
},
initialization_script: self.initialization_script.clone(),
})
}
}
pub fn load<P: AsRef<path::Path> + Copy>(path: P) -> Result<Data> {
Data::new(path)
}
pub fn pack<P: AsRef<path::Path>>(config: P) -> Result<()> {
Data::pack(config)
}
fn load_icon(path: &Path) -> Result<Icon> {
let image = image::open(path)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
.to_rgba8();
Ok(Icon {
width: image.dimensions().0,
height: image.dimensions().1,
rgba: image.into_raw(),
})
}
fn normalize_path(path: &Path) -> PathBuf {
pub fn normalize_path(path: &Path) -> PathBuf {
let mut components = path.components().peekable();
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
components.next();

1
neutauri_runtime/src/main.rs

@ -33,7 +33,6 @@ fn custom_protocol_uri_to_path<T: Into<String>>(protocol: T, uri: T) -> wry::Res
}
fn main() -> wry::Result<()> {
data::pack("config.toml")?;
let res = match data::load(std::env::current_exe()?.as_path()) {
Ok(data) => data,
Err(_) => data::load("app.neu")?,

1
web_src/build/bundle.css

@ -0,0 +1 @@
.svelte-vxnnxe{font-family:inherit;font-size:inherit}.center.svelte-vxnnxe{text-align:center;margin:auto}.crud.svelte-vxnnxe{display:flex}.left.svelte-vxnnxe{text-align:center;margin:auto}.right.svelte-vxnnxe{text-align:center;margin:auto}input.svelte-vxnnxe{width:100%;display:block;margin:0 0 0.5em 0}select.svelte-vxnnxe{width:14em}.buttons.svelte-vxnnxe{clear:both}

2
web_src/build/bundle.js

File diff suppressed because one or more lines are too long

1
web_src/build/bundle.js.map

File diff suppressed because one or more lines are too long

BIN
web_src/favicon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

63
web_src/global.css

@ -0,0 +1,63 @@
html, body {
position: relative;
width: 100%;
height: 100%;
}
body {
color: #333;
margin: 0;
padding: 8px;
box-sizing: border-box;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}
a {
color: rgb(0,100,200);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:visited {
color: rgb(0,80,160);
}
label {
display: block;
}
input, button, select, textarea {
font-family: inherit;
font-size: inherit;
-webkit-padding: 0.4em 0;
padding: 0.4em;
margin: 0 0 0.5em 0;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 2px;
}
input:disabled {
color: #ccc;
}
button {
color: #333;
background-color: #f4f4f4;
outline: none;
}
button:disabled {
color: #999;
}
button:not(:disabled):active {
background-color: #ddd;
}
button:focus {
border-color: #666;
}

18
web_src/index.html

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<title>Svelte app</title>
<link rel='icon' type='image/png' href='/favicon.png'>
<link rel='stylesheet' href='/global.css'>
<link rel='stylesheet' href='/build/bundle.css'>
<script defer src='/build/bundle.js'></script>
</head>
<body>
</body>
</html>
Loading…
Cancel
Save