diff --git a/egui_client/Cargo.lock b/egui_client/Cargo.lock index cf31503..40aecc4 100644 --- a/egui_client/Cargo.lock +++ b/egui_client/Cargo.lock @@ -74,6 +74,18 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" +[[package]] +name = "atk-sys" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58aeb089fb698e06db8089971c7ee317ab9644bade33383f63631437b03aafb6" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "atomic_refcell" version = "0.1.8" @@ -145,6 +157,16 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" +[[package]] +name = "cairo-sys-rs" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c55d429bef56ac9172d25fecb85dc8068307d17acd74b377866b7a1ef25d3c8" +dependencies = [ + "libc", + "system-deps", +] + [[package]] name = "calloop" version = "0.10.1" @@ -170,6 +192,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" +[[package]] +name = "cfg-expr" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aacacf4d96c24b2ad6eb8ee6df040e4f27b0d0b39a5710c30091baa830485db" +dependencies = [ + "smallvec", +] + [[package]] name = "cfg-if" version = "0.1.10" @@ -700,6 +731,36 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "gdk-pixbuf-sys" +version = "0.15.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "140b2f5378256527150350a8346dbdb08fadc13453a7a2d73aecd5fab3c402a7" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gdk-sys" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e7a08c1e8f06f4177fb7e51a777b8c1689f743a7bc11ea91d44d2226073a88" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps", +] + [[package]] name = "generic-array" version = "0.14.6" @@ -733,6 +794,19 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gio-sys" +version = "0.15.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32157a475271e2c4a023382e9cab31c4584ee30a97da41d3c4e9fdd605abcf8d" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + [[package]] name = "gl_generator" version = "0.14.0" @@ -744,6 +818,16 @@ dependencies = [ "xml-rs", ] +[[package]] +name = "glib-sys" +version = "0.15.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef4b192f8e65e9cf76cbf4ea71fa8e3be4a0e18ffe3d68b8da6836974cc5bad4" +dependencies = [ + "libc", + "system-deps", +] + [[package]] name = "glow" version = "0.11.2" @@ -821,6 +905,41 @@ dependencies = [ "gl_generator", ] +[[package]] +name = "gobject-sys" +version = "0.15.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d57ce44246becd17153bd035ab4d32cfee096a657fc01f2231c9278378d1e0a" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gtk-sys" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5bc2f0587cba247f60246a0ca11fe25fb733eabc3de12d1965fc07efab87c84" +dependencies = [ + "atk-sys", + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "system-deps", +] + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hex" version = "0.4.3" @@ -1275,6 +1394,18 @@ dependencies = [ "ttf-parser", ] +[[package]] +name = "pango-sys" +version = "0.15.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2a00081cde4661982ed91d80ef437c20eacaf6aa1a5962c0279ae194662c3aa" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -1428,6 +1559,30 @@ dependencies = [ "winapi", ] +[[package]] +name = "rfd" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0149778bd99b6959285b0933288206090c50e2327f47a9c463bfdbf45c8823ea" +dependencies = [ + "block", + "dispatch", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "lazy_static", + "log", + "objc", + "objc-foundation", + "objc_id", + "raw-window-handle 0.5.0", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows", +] + [[package]] name = "rusty_hub" version = "0.1.0" @@ -1446,6 +1601,7 @@ dependencies = [ "confy", "eframe", "image", + "rfd", "rusty_hub", ] @@ -1632,6 +1788,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "system-deps" +version = "6.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a45a1c4c9015217e12347f2a411b57ce2c4fc543913b14b6fe40483328e709" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml", + "version-compare", +] + [[package]] name = "thiserror" version = "1.0.35" @@ -1788,6 +1957,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "version-compare" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe88247b92c1df6b6de80ddc290f3976dbdf2f5f5d3fd049a9fb598c6dd5ca73" + [[package]] name = "version_check" version = "0.9.4" @@ -2042,17 +2217,30 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57b543186b344cc61c85b5aab0d2e3adf4e0f99bc076eff9aa5927bcc0b8a647" +dependencies = [ + "windows_aarch64_msvc 0.37.0", + "windows_i686_gnu 0.37.0", + "windows_i686_msvc 0.37.0", + "windows_x86_64_gnu 0.37.0", + "windows_x86_64_msvc 0.37.0", +] + [[package]] name = "windows-sys" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] [[package]] @@ -2061,30 +2249,60 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2623277cb2d1c216ba3b578c0f3cf9cdebeddb6e66b1b218bb33596ea7769c3a" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3925fd0b0b804730d44d4b6278c50f9699703ec49bcd628020f46f4ba07d9e1" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce907ac74fe331b524c1298683efbf598bb031bc84d5e274db2083696d07c57c" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2babfba0828f2e6b32457d5341427dcbb577ceef556273229959ac23a10af33d" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4dd6dc7df2d84cf7b33822ed5b86318fb1781948e9663bacd047fc9dd52259d" + [[package]] name = "winit" version = "0.27.3" diff --git a/egui_client/Cargo.toml b/egui_client/Cargo.toml index 803a02b..58c84ad 100644 --- a/egui_client/Cargo.toml +++ b/egui_client/Cargo.toml @@ -17,4 +17,5 @@ opt-level = 2 confy = "^0.5.0" eframe = "0.19.0" rusty_hub = { path="../rusty_hub" } -image = { version = "0.24.0", default-features = false, features = ["png"] } \ No newline at end of file +image = { version = "0.24.0", default-features = false, features = ["png"] } +rfd = "0.10.0" \ No newline at end of file diff --git a/egui_client/src/main.rs b/egui_client/src/main.rs index c85c971..d8e1b7f 100644 --- a/egui_client/src/main.rs +++ b/egui_client/src/main.rs @@ -1,6 +1,10 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release extern crate confy; -use eframe::{egui, IconData, NativeOptions}; +use eframe::{ + egui::{self, Ui}, + IconData, NativeOptions, +}; +use rfd::FileDialog; use rusty_hub::hub::Hub; use std::io::Cursor; @@ -61,8 +65,13 @@ fn setup_custom_fonts(ctx: &egui::Context) { ctx.set_fonts(fonts); } +pub enum WindowTab { + Projects, + Editors, +} struct MyApp { hub: Hub, + current_tab: WindowTab, } impl MyApp { @@ -70,20 +79,18 @@ impl MyApp { setup_custom_fonts(&cc.egui_ctx); Self { hub: confy::load("lwa_unity_hub", "config").unwrap(), + current_tab: WindowTab::Projects, } } -} -impl eframe::App for MyApp { - fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { - egui::TopBottomPanel::top("topPanel").show(ctx, |ui| ui.label("Rusty Unity Hub")); - egui::SidePanel::left("dsadsa").show(ctx, |ui| { - ui.set_height(25.0); - ui.add_space(14.0); - ui.button("Projects"); - ui.add_space(14.0); - ui.button("Editors"); - }); + fn save_config(&mut self, rebuild: bool) { + if rebuild { + self.hub.config.rebuild(); + } + let _ = confy::store("lwa_unity_hub", "config", &self.hub); + } + + pub fn draw_central_panel(&mut self, ctx: &egui::Context) { egui::CentralPanel::default().show(ctx, |ui| { egui::ScrollArea::vertical().show(ui, |ui| { egui::Grid::new("some_unique_id") @@ -93,47 +100,106 @@ impl eframe::App for MyApp { .max_col_width(1000.0) .num_columns(3) .show(ui, |ui| { - let mut index: usize = 0; - for project in &self.hub.projects { - ui.scope(|ui| { - ui.set_enabled(self.hub.editor_for_project(project).is_some()); - if ui - .button(format!("Open {}", &project.title)) - .on_disabled_hover_text(format!( - "Select different Unity version" - )) - .clicked() - { - self.hub.run_project_nr(index); - } - ui.set_enabled(true); - }); - - let version_response = ui.add( - egui::Label::new(&project.version).sense(egui::Sense::click()), - ); - version_response.context_menu(|ui| { - for editor in &self.hub.config.editors_configurations { - if ui.button(format!("Open in {}", &editor.version)).clicked() { - Hub::run_project(&editor, &project); - ui.close_menu(); - } - } - }); - let path_response = - ui.add(egui::Label::new(&project.path).sense(egui::Sense::click())); - path_response.context_menu(|ui| { - if ui.button("Open directory").clicked() { - use std::process::Command; - Command::new("explorer").arg(&project.path).spawn().unwrap(); - ui.close_menu(); - } - }); - ui.end_row(); - index = index + 1; - } + match self.current_tab { + WindowTab::Projects => self.draw_project(&ctx, ui), + WindowTab::Editors => self.draw_editors(&ctx, ui), + }; }); }); }); } + + fn draw_editors(&mut self, _ctx: &egui::Context, ui: &mut Ui) { + ui.label("Editor search paths"); + if ui.button("Add new").clicked() { + let directory = FileDialog::new().pick_folder(); + if let Some(dir) = directory { + self.hub + .config + .unity_search_paths + .push(dir.into_os_string().into_string().unwrap()); + self.save_config(true); + } + } + if ui.button("Refresh").clicked() { + self.hub.config.rebuild(); + } + ui.end_row(); + let mut i = 0; + for editor in self.hub.config.unity_search_paths.clone() { + if ui.button("Remove").clicked() { + self.hub.config.unity_search_paths.remove(i); + self.save_config(true); + return; + } + ui.label(editor); + ui.end_row(); + i = i + 1; + } + ui.label("Installed editor versions"); + ui.end_row(); + for editor in &self.hub.config.editors_configurations { + ui.label(&editor.version); + ui.label(editor.platforms.join(",")); + ui.label(&editor.base_path); + ui.end_row(); + } + } + fn draw_project(&mut self, _ctx: &egui::Context, ui: &mut Ui) { + let mut index: usize = 0; + for project in &self.hub.projects { + ui.scope(|ui| { + ui.set_enabled(self.hub.editor_for_project(project).is_some()); + if ui + .button(format!("Open {}", &project.title)) + .on_disabled_hover_text(format!("Select different Unity version")) + .clicked() + { + self.hub.run_project_nr(index); + } + ui.set_enabled(true); + }); + + let version_response = + ui.add(egui::Label::new(&project.version).sense(egui::Sense::click())); + version_response.context_menu(|ui| { + for editor in &self.hub.config.editors_configurations { + if ui.button(format!("Open in {}", &editor.version)).clicked() { + Hub::run_project(&editor, &project); + ui.close_menu(); + } + } + }); + let path_response = ui.add(egui::Label::new(&project.path).sense(egui::Sense::click())); + path_response.context_menu(|ui| { + if ui.button("Open directory").clicked() { + use std::process::Command; + Command::new("explorer").arg(&project.path).spawn().unwrap(); + ui.close_menu(); + } + }); + ui.end_row(); + index = index + 1; + } + } +} + +impl eframe::App for MyApp { + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + egui::TopBottomPanel::top("topPanel").show(ctx, |ui| { + ui.label("Rusty Unity Hub"); + }); + egui::SidePanel::left("dsadsa").show(ctx, |ui| { + ui.set_height(25.0); + ui.add_space(14.0); + if ui.button("Projects").clicked() { + self.current_tab = WindowTab::Projects; + } + ui.add_space(14.0); + if ui.button("Editors").clicked() { + self.current_tab = WindowTab::Editors; + } + }); + self.draw_central_panel(&ctx); + } } diff --git a/rusty_hub/src/config.rs b/rusty_hub/src/config.rs index 9a7428b..fbafb61 100644 --- a/rusty_hub/src/config.rs +++ b/rusty_hub/src/config.rs @@ -14,8 +14,12 @@ impl Configuration { let paths = self.get_unity_paths(); for path in &paths { let editor = UnityEditor::new(&path); - if editor.is_some() { - self.editors_configurations.push(editor.unwrap()); + if editor.is_none() { + continue; + } + let editor = editor.unwrap(); + if !self.editors_configurations.contains(&editor) { + self.editors_configurations.push(editor); } } } diff --git a/rusty_hub/src/hub.rs b/rusty_hub/src/hub.rs index eaafbab..7bc3a2a 100644 --- a/rusty_hub/src/hub.rs +++ b/rusty_hub/src/hub.rs @@ -1,6 +1,6 @@ use std::process::Command; -use crate::{config::Configuration, unity_project::UnityProject, unity_editor::UnityEditor}; +use crate::{config::Configuration, unity_editor::UnityEditor, unity_project::UnityProject}; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct Hub { @@ -34,11 +34,11 @@ impl Hub { pub fn run_project(editor: &UnityEditor, project: &UnityProject) { println!("{} -projectpath {}", editor.exe_path, project.path); - Command::new(&editor.exe_path) - .arg("-projectpath") - .arg(&project.path) - .spawn() - .expect("Failed to run project"); + Command::new(&editor.exe_path) + .arg("-projectpath") + .arg(&project.path) + .spawn() + .expect("Failed to run project"); } } impl Default for Hub { diff --git a/rusty_hub/src/unity_editor.rs b/rusty_hub/src/unity_editor.rs index 7d4dcd5..4dec50e 100644 --- a/rusty_hub/src/unity_editor.rs +++ b/rusty_hub/src/unity_editor.rs @@ -12,6 +12,12 @@ pub struct UnityEditor { pub platforms: Vec, } +impl PartialEq for UnityEditor { + fn eq(&self, other: &Self) -> bool { + self.exe_path == other.exe_path + } +} + impl UnityEditor { pub fn new(path: &str) -> Option { let base_path = Path::new(path);