Create workspace and upgrade dependencies

This commit is contained in:
Piotr Siuszko 2025-08-05 20:38:54 +02:00
parent 8b611fe33e
commit 946b0191cd
11 changed files with 106 additions and 79 deletions

13
Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[workspace]
resolver = "3"
members = ["rusty_hub_egui", "unity_hub_lib"]
[profile.release]
opt-level = 'z'
panic = 'abort'
lto = true
[profile.dev.package."*"]
opt-level = 2

View File

@ -5,24 +5,24 @@ edition = "2021"
homepage = "https://github.com/Leinnan/rusty_hub" homepage = "https://github.com/Leinnan/rusty_hub"
build = "build.rs" build = "build.rs"
[profile.release]
opt-level = 'z'
panic = 'abort'
lto = true
[profile.dev.package."*"]
opt-level = 2
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
confy = "0.6" confy = "0.6"
eframe = "0.29" eframe = { version = "0.32", default-features = false, features = [
egui_extras = "0.29" #"accesskit", # Make egui comptaible with screen readers. NOTE: adds a lot of dependencies.
"default_fonts", # Embed the default egui fonts.
"glow", # Use the glow rendering backend. Alternative: "wgpu".
"persistence", # Enable restoring app state when restarting the app.
"wayland", # To support Linux (and CI)
] }
egui = "0.32"
egui_extras = "0.32"
unity_hub_lib = { path="../unity_hub_lib" } unity_hub_lib = { path="../unity_hub_lib" }
rfd = "0.15" rfd = "0.15"
inline_tweak = "1" inline_tweak = "1"
poll-promise = "0.3" anyhow = "1"
[target.'cfg(windows)'.build-dependencies] [target.'cfg(windows)'.build-dependencies]
winres = "0.1" winres = "0.1"

View File

@ -22,16 +22,14 @@ pub struct HubClient {
fn setup_custom_fonts(ctx: &egui::Context) { fn setup_custom_fonts(ctx: &egui::Context) {
// Start with the default fonts (we will be adding to them rather than replacing them). // Start with the default fonts (we will be adding to them rather than replacing them).
let mut fonts = egui::FontDefinitions::default(); let mut fonts = egui::FontDefinitions::default();
if let Ok((regular, semibold)) = get_fonts() {
// Install my own font (maybe supporting non-latin characters).
// .ttf and .otf files supported.
fonts.font_data.insert( fonts.font_data.insert(
"regular".to_owned(), "regular".to_owned(),
egui::FontData::from_static(include_bytes!("../static/Inter-Regular.ttf")), egui::FontData::from_owned(regular).into(),
); );
fonts.font_data.insert( fonts.font_data.insert(
"semibold".to_owned(), "semibold".to_owned(),
egui::FontData::from_static(include_bytes!("../static/Inter-SemiBold.ttf")), egui::FontData::from_owned(semibold).into(),
); );
// Put my font first (highest priority) for proportional text: // Put my font first (highest priority) for proportional text:
@ -55,6 +53,37 @@ fn setup_custom_fonts(ctx: &egui::Context) {
// Tell egui to use these fonts: // Tell egui to use these fonts:
ctx.set_fonts(fonts); ctx.set_fonts(fonts);
}
ctx.style_mut(|style| {
for font_id in style.text_styles.values_mut() {
font_id.size *= 1.4;
}
});
}
#[cfg(not(windows))]
fn get_fonts() -> anyhow::Result<(Vec<u8>, Vec<u8>)> {
use std::fs;
let font_path = std::path::Path::new("/System/Library/Fonts");
let regular = fs::read(font_path.join("SFNSRounded.ttf"))?;
let semibold = fs::read(font_path.join("SFCompact.ttf"))?;
Ok((regular, semibold))
}
#[cfg(windows)]
fn get_fonts() -> anyhow::Result<(Vec<u8>, Vec<u8>)> {
use std::fs;
let app_data = std::env::var("APPDATA")?;
let font_path = std::path::Path::new(&app_data);
let regular = fs::read(font_path.join("../Local/Microsoft/Windows/Fonts/aptos.ttf"))?;
let semibold = fs::read(font_path.join("../Local/Microsoft/Windows/Fonts/aptos-semibold.ttf"))?;
Ok((regular, semibold))
} }
impl HubClient { impl HubClient {
@ -167,7 +196,7 @@ impl HubClient {
.arg(&editor.base_path) .arg(&editor.base_path)
.spawn() .spawn()
.unwrap(); .unwrap();
ui.close_menu(); ui.close();
} }
}); });
}, },
@ -189,7 +218,7 @@ impl HubClient {
} else { } else {
egui::Color32::TRANSPARENT egui::Color32::TRANSPARENT
}; };
egui::Frame::none().fill(color).show(ui, |ui| { egui::Frame::NONE.fill(color).show(ui, |ui| {
ui.add_sized( ui.add_sized(
[text_height, text_height], [text_height, text_height],
egui::Button::new("").frame(false), egui::Button::new("").frame(false),
@ -215,7 +244,7 @@ impl HubClient {
} }
if ui.button(text).clicked() { if ui.button(text).clicked() {
Hub::run_project(editor, project); Hub::run_project(editor, project);
ui.close_menu(); ui.close();
} }
} }
}); });
@ -226,7 +255,7 @@ impl HubClient {
.arg(&project.path) .arg(&project.path)
.spawn() .spawn()
.unwrap(); .unwrap();
ui.close_menu(); ui.close();
} }
}); });
ui.label(egui::RichText::new(project.title.to_string()).heading()) ui.label(egui::RichText::new(project.title.to_string()).heading())
@ -329,9 +358,7 @@ impl HubClient {
.set_level(rfd::MessageLevel::Warning) .set_level(rfd::MessageLevel::Warning)
} }
1 => message = message.set_description("Project founded!"), 1 => message = message.set_description("Project founded!"),
_ => { _ => message = message.set_description(format!("Founded {} projects.", amount)),
message = message.set_description(format!("Founded {} projects.", amount))
}
} }
message.show(); message.show();
self.save_config(true); self.save_config(true);
@ -354,7 +381,8 @@ impl HubClient {
let response = ui.add_sized( let response = ui.add_sized(
button_size, button_size,
egui::Label::new(rich_text).selectable(false) egui::Label::new(rich_text)
.selectable(false)
.sense(egui::Sense::click()), .sense(egui::Sense::click()),
); );
if response.hovered() { if response.hovered() {
@ -409,7 +437,7 @@ impl eframe::App for HubClient {
}); });
egui::TopBottomPanel::bottom("bottomPanel").show(ctx, |ui| { egui::TopBottomPanel::bottom("bottomPanel").show(ctx, |ui| {
ui.with_layout(Layout::right_to_left(eframe::emath::Align::Center), |ui| { ui.with_layout(Layout::right_to_left(eframe::emath::Align::Center), |ui| {
egui::widgets::global_dark_light_mode_switch(ui); egui::widgets::global_theme_preference_switch(ui);
ui.hyperlink_to( ui.hyperlink_to(
format!("{} v {}", egui::special_emojis::GITHUB, VERSION), format!("{} v {}", egui::special_emojis::GITHUB, VERSION),
HOMEPAGE, HOMEPAGE,

View File

@ -17,19 +17,14 @@ fn main() -> eframe::Result<()> {
eframe::icon_data::from_png_bytes(&include_bytes!("../static/hub.png")[..]) eframe::icon_data::from_png_bytes(&include_bytes!("../static/hub.png")[..])
.expect("Failed to load icon"), .expect("Failed to load icon"),
), ),
// always_on_top: false,
// maximized: false,
// decorated: true,
// fullscreen: false,
// drag_and_drop_support: false,
// initial_window_size: Some(egui::vec2(850.0, 400.0)),
// min_window_size: Some(egui::vec2(850.0, 400.0)),
// icon_data: Some(icon),
..Default::default() ..Default::default()
}; };
eframe::run_native( eframe::run_native(
&format!("{} v {}", APP_NAME, VERSION), &format!("{} v {}", APP_NAME, VERSION),
options, options,
Box::new(|cc| Ok(Box::new(crate::hub_client::HubClient::new(cc)))), Box::new(|cc| {
egui_extras::install_image_loaders(&cc.egui_ctx);
Ok(Box::new(crate::hub_client::HubClient::new(cc)))
}),
) )
} }

View File

@ -3,20 +3,9 @@ name = "unity_hub_lib"
version = "0.2.0" version = "0.2.0"
edition = "2021" edition = "2021"
[profile.release]
opt-level = 'z'
panic = 'abort'
lto = true
[profile.dev.package."*"]
opt-level = 2
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
serde = "1" serde = { version = "1", features = ["derive"] }
serde_derive = "1"
walkdir = "2" walkdir = "2"
exe = "0.5" exe = "0.5"
registry = "1.2" registry = "1.3"
dpc-pariter = "0.5.1" dpc-pariter = "0.5.1"

View File

@ -1,5 +1,6 @@
use crate::{consts, unity_editor::UnityEditor}; use crate::{consts, unity_editor::UnityEditor};
use dpc_pariter::IteratorExt; use dpc_pariter::IteratorExt;
use serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
use walkdir::{DirEntry, WalkDir}; use walkdir::{DirEntry, WalkDir};

View File

@ -1,5 +1,6 @@
use crate::{config::Configuration, unity_editor::UnityEditor, unity_project::UnityProject}; use crate::{config::Configuration, unity_editor::UnityEditor, unity_project::UnityProject};
use dpc_pariter::IteratorExt; use dpc_pariter::IteratorExt;
use serde::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::HashSet;
use std::{path::PathBuf, process::Command}; use std::{path::PathBuf, process::Command};
use walkdir::WalkDir; use walkdir::WalkDir;

View File

@ -1,6 +1,3 @@
#[macro_use]
extern crate serde_derive;
pub mod config; pub mod config;
pub mod consts; pub mod consts;
pub mod hub; pub mod hub;

View File

@ -1,4 +1,5 @@
use dpc_pariter::IteratorExt; use dpc_pariter::IteratorExt;
use serde::{Deserialize, Serialize};
use std::path::Path; use std::path::Path;
#[derive(Debug, Serialize, Deserialize, Clone, Eq, Hash)] #[derive(Debug, Serialize, Deserialize, Clone, Eq, Hash)]

View File

@ -1,5 +1,6 @@
use crate::consts; use crate::consts;
use crate::project_template::ProjectTemplate; use crate::project_template::ProjectTemplate;
use serde::{Deserialize, Serialize};
use std::borrow::Borrow; use std::borrow::Borrow;
use std::collections::HashMap; use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
@ -25,7 +26,7 @@ impl UnityEditor {
let base_path = Path::new(path); let base_path = Path::new(path);
let exe_path = base_path.join(consts::UNITY_EXE_NAME); let exe_path = base_path.join(consts::UNITY_EXE_NAME);
let meta = std::fs::metadata(&exe_path); let meta = std::fs::metadata(&exe_path);
if !meta.is_ok() || !meta.unwrap().is_file() { if !meta.is_ok_and(|meta| meta.is_file()) {
return None; return None;
} }
@ -91,7 +92,7 @@ impl UnityEditor {
let mut platforms = Vec::new(); let mut platforms = Vec::new();
let base_path = Path::new(unity_folder).join("Data").join("PlaybackEngines"); let base_path = Path::new(unity_folder).join("Data").join("PlaybackEngines");
if !std::fs::metadata(&base_path).is_ok() { if std::fs::metadata(&base_path).is_err() {
return platforms; return platforms;
} }
let dir = std::fs::read_dir(base_path); let dir = std::fs::read_dir(base_path);

View File

@ -1,3 +1,4 @@
use serde::{Deserialize, Serialize};
use std::{ops::Sub, path::Path, str}; use std::{ops::Sub, path::Path, str};
use crate::consts; use crate::consts;
@ -76,20 +77,20 @@ impl UnityProject {
iter.next(); iter.next();
let project_version = iter.next().unwrap().to_string(); let project_version = iter.next().unwrap().to_string();
return Some(project_version); Some(project_version)
} }
pub fn try_get_project_at_path(path: &str) -> Option<UnityProject> { pub fn try_get_project_at_path(path: &str) -> Option<UnityProject> {
#[cfg(windows)] #[cfg(windows)]
let path = path.trim_matches(char::from(0)).replace("/", "\\"); let path = path.trim_matches(char::from(0)).replace("/", "\\");
#[cfg(unix)] #[cfg(not(windows))]
let path = path.trim_matches(char::from(0)); let path = path.trim_matches(char::from(0)).to_string();
if !UnityProject::is_project_at_path(&path) { if !UnityProject::is_project_at_path(&path) {
return None; return None;
} }
let mut project = UnityProject { let mut project = UnityProject {
path: path.to_string(), path: path.clone(),
title: path.split(consts::SLASH).last().unwrap().to_string(), title: path.split(consts::SLASH).last().unwrap().to_string(),
branch: String::new(), branch: String::new(),
version: String::new(), version: String::new(),