Connect the native Beta to the project Web workspace
This commit is contained in:
1 parent
29193c03bc
commit
8b6dab8d52
5 files changed
+155
-20
No files matched your search
@@ -188,7 +188,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
std::process::exit(status);
|
||||
}
|
||||
let mut args = std::env::args_os().skip(1).peekable();
|
||||
let usage = "native_editor [--input-profile tex8bit|unicode|xetex] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...]";
|
||||
let usage = "native_editor [--input-profile tex8bit|unicode|xetex] [--web-dir DIR] SOURCE FORMAT FORMAT_RESOURCES NEW_RUN_DIR [PORT] [FILE ...]";
|
||||
let input_profile = if args.next_if(|arg| arg == "--input-profile").is_some() {
|
||||
match args.next().as_deref().and_then(std::ffi::OsStr::to_str) {
|
||||
Some("tex8bit") => InputProfile::TeX8Bit,
|
||||
@@ -199,6 +199,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
} else {
|
||||
InputProfile::TeX8Bit
|
||||
};
|
||||
let web = if args.next_if(|arg| arg == "--web-dir").is_some() {
|
||||
let path = PathBuf::from(args.next().ok_or(usage)?);
|
||||
Some(WebAssets::load(&path)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let mut args = args.map(PathBuf::from);
|
||||
let source = args.next().ok_or(usage)?.canonicalize()?;
|
||||
let format = args.next().ok_or(usage)?.canonicalize()?;
|
||||
@@ -234,7 +240,23 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
for request in server.incoming_requests() {
|
||||
let path = request.url().to_owned();
|
||||
match (request.method(), path.as_str()) {
|
||||
(&Method::Get, "/") => respond(request, 200, "text/html; charset=utf-8", PAGE.into()),
|
||||
(&Method::Get, "/") => respond(
|
||||
request,
|
||||
200,
|
||||
"text/html; charset=utf-8",
|
||||
web.as_ref().map_or_else(|| PAGE.into(), |assets| assets.index.clone()),
|
||||
),
|
||||
(&Method::Get, "/styles.css") if web.is_some() => respond(
|
||||
request, 200, "text/css; charset=utf-8", web.as_ref().unwrap().styles.clone(),
|
||||
),
|
||||
(&Method::Get, "/favicon.svg") if web.is_some() => respond(
|
||||
request, 200, "image/svg+xml", web.as_ref().unwrap().favicon.clone(),
|
||||
),
|
||||
// The shared Web shell requests this stylesheet. Native preview
|
||||
// pages carry their glyph outlines in their SVG output.
|
||||
(&Method::Get, "/fonts.css") if web.is_some() => {
|
||||
respond(request, 200, "text/css; charset=utf-8", Vec::new())
|
||||
}
|
||||
(&Method::Get, "/app.js") => respond(
|
||||
request,
|
||||
200,
|
||||
@@ -419,6 +441,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct WebAssets {
|
||||
index: Vec<u8>,
|
||||
styles: Vec<u8>,
|
||||
favicon: Vec<u8>,
|
||||
}
|
||||
|
||||
impl WebAssets {
|
||||
fn load(path: &Path) -> std::io::Result<Self> {
|
||||
Ok(Self {
|
||||
index: fs::read(path.join("index.html"))?,
|
||||
styles: fs::read(path.join("styles.css"))?,
|
||||
favicon: fs::read(path.join("favicon.svg"))?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn read_json<T: serde::de::DeserializeOwned>(request: &mut Request) -> Result<T, String> {
|
||||
let mut body = Vec::new();
|
||||
request
|
||||
|
||||
Reference in new issue
Block a user