diff --git a/tooling/cli/src/helpers/web_dev_server.rs b/tooling/cli/src/helpers/web_dev_server.rs index d06699f9d17c..4e14f0da5665 100644 --- a/tooling/cli/src/helpers/web_dev_server.rs +++ b/tooling/cli/src/helpers/web_dev_server.rs @@ -7,7 +7,7 @@ use axum::{ http::{header::CONTENT_TYPE, StatusCode, Uri}, response::IntoResponse, routing::get, - Router, Server, + serve, Router, }; use html5ever::{namespace_url, ns, LocalName, QualName}; use kuchiki::{traits::TendrilSink, NodeRef}; @@ -73,48 +73,43 @@ pub fn start>(path: P, ip: IpAddr, port: Option) -> crate::R 1430 }); - let (server, server_url) = loop { + let (listener, server_url) = loop { let server_url = SocketAddr::new(ip, port); - let server = Server::try_bind(&server_url); - - if !auto_port { - break (server, server_url); + if let Ok(listener) = tokio::net::TcpListener::bind(server_url).await { + break (Some(listener), server_url); } - if server.is_ok() { - break (server, server_url); + if !auto_port { + break (None, server_url); } port += 1; }; - let state = Arc::new(State { - serve_dir, - tx, - address: server_url, - }); - let state_ = state.clone(); - let router = Router::new() - .fallback(move |uri| handler(uri, state_)) - .route( - "/__tauri_cli", - get(move |ws: WebSocketUpgrade| async move { - ws.on_upgrade(|socket| async move { ws_handler(socket, state).await }) - }), - ); - - match server { - Ok(server) => { - server_url_tx.send(Ok(server_url)).unwrap(); - server.serve(router.into_make_service()).await.unwrap(); - } - Err(e) => { - server_url_tx - .send(Err(anyhow::anyhow!( - "failed to start development server on {server_url}: {e}" - ))) - .unwrap(); - } + if let Some(listener) = listener { + let state = Arc::new(State { + serve_dir, + tx, + address: server_url, + }); + let state_ = state.clone(); + let router = Router::new() + .fallback(move |uri| handler(uri, state_)) + .route( + "/__tauri_cli", + get(move |ws: WebSocketUpgrade| async move { + ws.on_upgrade(|socket| async move { ws_handler(socket, state).await }) + }), + ); + + server_url_tx.send(Ok(server_url)).unwrap(); + serve(listener, router).await.unwrap(); + } else { + server_url_tx + .send(Err(anyhow::anyhow!( + "failed to start development server on {server_url}" + ))) + .unwrap(); } }) }); diff --git a/tooling/cli/src/icon.rs b/tooling/cli/src/icon.rs index dcdab31f98f8..b7147ca27305 100644 --- a/tooling/cli/src/icon.rs +++ b/tooling/cli/src/icon.rs @@ -23,7 +23,6 @@ use image::{ imageops::FilterType, open, ColorType, DynamicImage, ImageBuffer, ImageEncoder, Rgba, }; -use resvg::usvg::{fontdb, TreeParsing, TreeTextToPath}; use resvg::{tiny_skia, usvg}; use serde::Deserialize; @@ -61,21 +60,21 @@ pub struct Options { } enum Source { - Svg(resvg::Tree), + Svg(resvg::usvg::Tree), DynamicImage(DynamicImage), } impl Source { fn width(&self) -> u32 { match self { - Self::Svg(svg) => svg.size.width() as u32, + Self::Svg(svg) => svg.size().width() as u32, Self::DynamicImage(i) => i.width(), } } fn height(&self) -> u32 { match self { - Self::Svg(svg) => svg.size.height() as u32, + Self::Svg(svg) => svg.size().height() as u32, Self::DynamicImage(i) => i.height(), } } @@ -84,8 +83,9 @@ impl Source { match self { Self::Svg(svg) => { let mut pixmap = tiny_skia::Pixmap::new(size, size).unwrap(); - let scale = size as f32 / svg.size.height(); - svg.render( + let scale = size as f32 / svg.size().height(); + resvg::render( + &svg, tiny_skia::Transform::from_scale(scale, scale), &mut pixmap.as_mut(), ); @@ -125,13 +125,8 @@ pub fn command(options: Options) -> Result<()> { ..Default::default() }; - let mut fontdb = fontdb::Database::new(); - fontdb.load_system_fonts(); - let svg_data = std::fs::read(&input).unwrap(); - let mut tree = usvg::Tree::from_data(&svg_data, &opt).unwrap(); - tree.convert_text(&fontdb); - resvg::Tree::from_usvg(&tree) + usvg::Tree::from_data(&svg_data, &opt, &Default::default()).unwrap() }; Source::Svg(rtree) diff --git a/tooling/cli/src/lib.rs b/tooling/cli/src/lib.rs index 05babd432621..20a413a0aea2 100644 --- a/tooling/cli/src/lib.rs +++ b/tooling/cli/src/lib.rs @@ -30,7 +30,7 @@ mod plugin; mod signer; use clap::{ArgAction, CommandFactory, FromArgMatches, Parser, Subcommand, ValueEnum}; -use env_logger::fmt::Color; +use env_logger::fmt::style::{AnsiColor, Style}; use env_logger::Builder; use log::{debug, log_enabled, Level}; use serde::Deserialize; @@ -209,27 +209,23 @@ where let action = action.to_cow_str().unwrap(); is_command_output = action == "stdout" || action == "stderr"; if !is_command_output { - let mut action_style = f.style(); - action_style.set_color(Color::Green).set_bold(true); + let style = Style::new().fg_color(Some(AnsiColor::Green.into())).bold(); - write!(f, "{:>12} ", action_style.value(action))?; + write!(f, " {style}{}{style:#} ", action)?; } } else { - let mut level_style = f.default_level_style(record.level()); - level_style.set_bold(true); - + let style = f.default_level_style(record.level()).bold(); write!( f, - "{:>12} ", - level_style.value(prettyprint_level(record.level())) + " {style}{}{style:#} ", + prettyprint_level(record.level()) )?; } if !is_command_output && log_enabled!(Level::Debug) { - let mut target_style = f.style(); - target_style.set_color(Color::Black); + let style = Style::new().fg_color(Some(AnsiColor::Black.into())); - write!(f, "[{}] ", target_style.value(record.target()))?; + write!(f, "[{style}{}{style:#}] ", record.target())?; } writeln!(f, "{}", record.args())