mirror of
https://github.com/Tim-Paik/neutauri.git
synced 2024-10-12 23:29:41 +00:00
Add support for creating projects, upgrade wry. Warning: Partially unavailable, Wayland support is broken
This commit is contained in:
@ -6,11 +6,12 @@ version = "0.1.0"
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
gumdrop = "0.8"
|
||||
inquire = "0.2"
|
||||
neutauri_data = {path = "../neutauri_data", 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"]}
|
||||
wry = {version = "0.20", 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()?,
|
||||
|
@ -1,3 +1,4 @@
|
||||
use anyhow::{Context, Result};
|
||||
use neutauri_data as data;
|
||||
use std::{fs, io::Read, path::PathBuf};
|
||||
use wry::{
|
||||
@ -29,10 +30,17 @@ fn custom_protocol_uri_to_path<T: Into<String>>(protocol: T, uri: T) -> wry::Res
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dev(config_path: String) -> wry::Result<()> {
|
||||
let config_path = std::path::Path::new(&config_path).canonicalize()?;
|
||||
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())
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
||||
.with_context(|| "toml parsing error")?;
|
||||
let source = config.source.canonicalize()?;
|
||||
|
||||
let event_loop = EventLoop::new();
|
||||
@ -140,6 +148,7 @@ 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)
|
||||
|
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();
|
||||
@ -67,6 +76,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 +85,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),
|
||||
}
|
||||
|
Reference in New Issue
Block a user