Working egui client

This commit is contained in:
Piotr Siuszko 2022-09-24 19:07:43 +02:00
parent b8eaf85895
commit ffb7baaaa1
7 changed files with 383 additions and 54 deletions

329
egui_client/Cargo.lock generated
View File

@ -30,12 +30,21 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57e6e951cfbb2db8de1828d49073a113a29fd7117b1596caa781a258c7e38d72" checksum = "57e6e951cfbb2db8de1828d49073a113a29fd7117b1596caa781a258c7e38d72"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"getrandom", "getrandom",
"once_cell", "once_cell",
"version_check", "version_check",
] ]
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "arboard" name = "arboard"
version = "2.1.1" version = "2.1.1"
@ -89,6 +98,15 @@ version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
[[package]]
name = "block-buffer"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
"generic-array",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.11.0" version = "3.11.0"
@ -115,6 +133,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "bytes" name = "bytes"
version = "1.2.1" version = "1.2.1"
@ -146,6 +170,12 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -161,6 +191,21 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "chrono"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1"
dependencies = [
"iana-time-zone",
"js-sys",
"num-integer",
"num-traits",
"time",
"wasm-bindgen",
"winapi",
]
[[package]] [[package]]
name = "clipboard-win" name = "clipboard-win"
version = "4.4.2" version = "4.4.2"
@ -222,6 +267,18 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "confy"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5069e3065d9ad485706017d12bb4b4318170b8087358c163c2dfce50b6b38275"
dependencies = [
"directories",
"serde",
"thiserror",
"toml",
]
[[package]] [[package]]
name = "core-foundation" name = "core-foundation"
version = "0.9.3" version = "0.9.3"
@ -275,13 +332,22 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "cpufeatures"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "crc32fast" name = "crc32fast"
version = "1.3.2" version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -348,6 +414,36 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [
"generic-array",
]
[[package]]
name = "directories"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "551a778172a450d7fc12e629ca3b0428d00f6afa9a43da1b630d54604e97371c"
dependencies = [
"cfg-if 0.1.10",
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
dependencies = [
"libc",
"redox_users",
"winapi",
]
[[package]] [[package]]
name = "dispatch" name = "dispatch"
version = "0.2.0" version = "0.2.0"
@ -481,6 +577,24 @@ dependencies = [
"str-buf", "str-buf",
] ]
[[package]]
name = "exe"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2327a5b94310f33654812ff74ec7cd226a89eb430c46d4e1308c7e895da12f19"
dependencies = [
"bitflags",
"byteorder",
"chrono",
"hex",
"md-5",
"num-traits",
"pkbuffer",
"sha-1",
"sha2",
"widestring 0.4.3",
]
[[package]] [[package]]
name = "expat-sys" name = "expat-sys"
version = "2.1.6" version = "2.1.6"
@ -580,6 +694,16 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "generic-array"
version = "0.14.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9"
dependencies = [
"typenum",
"version_check",
]
[[package]] [[package]]
name = "gethostname" name = "gethostname"
version = "0.2.3" version = "0.2.3"
@ -596,10 +720,10 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"js-sys", "js-sys",
"libc", "libc",
"wasi", "wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen", "wasm-bindgen",
] ]
@ -691,6 +815,25 @@ dependencies = [
"gl_generator", "gl_generator",
] ]
[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
[[package]]
name = "iana-time-zone"
version = "0.1.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"js-sys",
"wasm-bindgen",
"winapi",
]
[[package]] [[package]]
name = "ident_case" name = "ident_case"
version = "1.0.1" version = "1.0.1"
@ -713,7 +856,7 @@ version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
@ -772,7 +915,7 @@ version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd" checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"winapi", "winapi",
] ]
@ -792,7 +935,7 @@ version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
] ]
[[package]] [[package]]
@ -804,6 +947,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "md-5"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
dependencies = [
"block-buffer",
"digest",
"opaque-debug",
]
[[package]] [[package]]
name = "memchr" name = "memchr"
version = "2.5.0" version = "2.5.0"
@ -851,7 +1005,7 @@ checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
dependencies = [ dependencies = [
"libc", "libc",
"log", "log",
"wasi", "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys", "windows-sys",
] ]
@ -958,7 +1112,7 @@ checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cc", "cc",
"cfg-if", "cfg-if 1.0.0",
"libc", "libc",
"memoffset", "memoffset",
] ]
@ -970,7 +1124,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"cfg-if", "cfg-if 1.0.0",
"libc", "libc",
"memoffset", "memoffset",
] ]
@ -991,6 +1145,25 @@ dependencies = [
"minimal-lexical", "minimal-lexical",
] ]
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "num_enum" name = "num_enum"
version = "0.5.7" version = "0.5.7"
@ -1047,6 +1220,12 @@ version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]] [[package]]
name = "osmesa-sys" name = "osmesa-sys"
version = "0.1.2" version = "0.1.2"
@ -1081,7 +1260,7 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"libc", "libc",
"redox_syscall", "redox_syscall",
"smallvec", "smallvec",
@ -1100,6 +1279,26 @@ version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
[[package]]
name = "pkbuffer"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c63758cdd196779b1d782c6c5f568cbd6b412eb3c51eab711f08e83cd57edef"
dependencies = [
"pkbuffer_derive",
]
[[package]]
name = "pkbuffer_derive"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c86ad26b9715c9c1664b79f6e5c44baf38fb87a5133bdd7ec90baff7b71d155"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "pkg-config" name = "pkg-config"
version = "0.3.25" version = "0.3.25"
@ -1174,11 +1373,48 @@ dependencies = [
"bitflags", "bitflags",
] ]
[[package]]
name = "redox_users"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
dependencies = [
"getrandom",
"redox_syscall",
"thiserror",
]
[[package]]
name = "registry"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83e4b158bf49b0d000013487636c92268de4cfd26cdbb629f020a612749f12c4"
dependencies = [
"bitflags",
"log",
"thiserror",
"utfx",
"winapi",
]
[[package]]
name = "rusty_hub"
version = "0.1.0"
dependencies = [
"confy",
"exe",
"registry",
"serde",
"serde_derive",
"walkdir",
]
[[package]] [[package]]
name = "rusty_hub_egui" name = "rusty_hub_egui"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"eframe", "eframe",
"rusty_hub",
] ]
[[package]] [[package]]
@ -1261,6 +1497,32 @@ dependencies = [
"pkg-config", "pkg-config",
] ]
[[package]]
name = "sha-1"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99cd6713db3cf16b6c84e06321e049a9b9f699826e16096d23bbcc44d15d51a6"
dependencies = [
"block-buffer",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
"opaque-debug",
]
[[package]]
name = "sha2"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
dependencies = [
"block-buffer",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
"opaque-debug",
]
[[package]] [[package]]
name = "shared_library" name = "shared_library"
version = "0.1.9" version = "0.1.9"
@ -1358,6 +1620,17 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"winapi",
]
[[package]] [[package]]
name = "tiny-skia" name = "tiny-skia"
version = "0.7.0" version = "0.7.0"
@ -1367,7 +1640,7 @@ dependencies = [
"arrayref", "arrayref",
"arrayvec", "arrayvec",
"bytemuck", "bytemuck",
"cfg-if", "cfg-if 1.0.0",
"png", "png",
"safe_arch", "safe_arch",
"tiny-skia-path", "tiny-skia-path",
@ -1413,7 +1686,7 @@ version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"pin-project-lite", "pin-project-lite",
"tracing-core", "tracing-core",
] ]
@ -1433,6 +1706,12 @@ version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd" checksum = "7b3e06c9b9d80ed6b745c7159c40b311ad2916abb34a49e9be2653b90db0d8dd"
[[package]]
name = "typenum"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987"
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.8" version = "0.3.8"
@ -1465,6 +1744,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "utfx"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133bf74f01486773317ddfcde8e2e20d2933cc3b68ab797e5d718bef996a81de"
[[package]] [[package]]
name = "vec_map" name = "vec_map"
version = "0.8.2" version = "0.8.2"
@ -1488,6 +1773,12 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]] [[package]]
name = "wasi" name = "wasi"
version = "0.11.0+wasi-snapshot-preview1" version = "0.11.0+wasi-snapshot-preview1"
@ -1500,7 +1791,7 @@ version = "0.2.83"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"wasm-bindgen-macro", "wasm-bindgen-macro",
] ]
@ -1525,7 +1816,7 @@ version = "0.4.33"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d"
dependencies = [ dependencies = [
"cfg-if", "cfg-if 1.0.0",
"js-sys", "js-sys",
"wasm-bindgen", "wasm-bindgen",
"web-sys", "web-sys",
@ -1663,10 +1954,16 @@ dependencies = [
"ndk-glue 0.6.2", "ndk-glue 0.6.2",
"url", "url",
"web-sys", "web-sys",
"widestring", "widestring 0.5.1",
"winapi", "winapi",
] ]
[[package]]
name = "widestring"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c168940144dd21fd8046987c16a46a33d5fc84eec29ef9dcddc2ac9e31526b7c"
[[package]] [[package]]
name = "widestring" name = "widestring"
version = "0.5.1" version = "0.5.1"

View File

@ -14,4 +14,5 @@ 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]
eframe = "0.19.0" eframe = "0.19.0"
rusty_hub = { path="../rusty_hub" }

View File

@ -1,6 +1,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui; use eframe::egui;
use rusty_hub::hub::Hub;
fn main() { fn main() {
let options = eframe::NativeOptions::default(); let options = eframe::NativeOptions::default();
@ -19,9 +20,7 @@ fn setup_custom_fonts(ctx: &egui::Context) {
// .ttf and .otf files supported. // .ttf and .otf files supported.
fonts.font_data.insert( fonts.font_data.insert(
"my_font".to_owned(), "my_font".to_owned(),
egui::FontData::from_static(include_bytes!( egui::FontData::from_static(include_bytes!("../static/FiraCode-VF.ttf")),
"../static/FiraCode-VF.ttf"
)),
); );
// Put my font first (highest priority) for proportional text: // Put my font first (highest priority) for proportional text:
@ -44,6 +43,7 @@ fn setup_custom_fonts(ctx: &egui::Context) {
struct MyApp { struct MyApp {
text: String, text: String,
hub: Hub,
} }
impl MyApp { impl MyApp {
@ -51,6 +51,7 @@ impl MyApp {
setup_custom_fonts(&cc.egui_ctx); setup_custom_fonts(&cc.egui_ctx);
Self { Self {
text: "Edit this text field if you want".to_owned(), text: "Edit this text field if you want".to_owned(),
hub: Hub::default(),
} }
} }
} }
@ -58,8 +59,42 @@ impl MyApp {
impl eframe::App for MyApp { impl eframe::App for MyApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| { egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("egui using custom fonts"); egui::Grid::new("some_unique_id")
ui.text_edit_multiline(&mut self.text); .striped(true)
.min_row_height(30.0)
.max_col_width(500.0)
.show(ui, |ui| {
let mut index: usize = 0;
for project in &self.hub.projects {
if self.hub.editor_for_project(project).is_some() {
if ui.button("run").clicked() {
self.hub.run_project_nr(index);
}
}
ui.label(&project.title);
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;
}
});
}); });
} }
} }

View File

@ -1,6 +1,6 @@
use std::process::Command; use std::process::Command;
use crate::{config::Configuration, unity_project::UnityProject}; use crate::{config::Configuration, unity_project::UnityProject, unity_editor::UnityEditor};
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Hub { pub struct Hub {
@ -15,22 +15,30 @@ impl Hub {
pub fn run_project_nr(&self, nr: usize) { pub fn run_project_nr(&self, nr: usize) {
let project = self.projects[nr].clone(); let project = self.projects[nr].clone();
let project_version = project.version;
if let Some(editor) = self.editor_for_project(&project) {
Hub::run_project(&editor, &project);
}
}
pub fn editor_for_project(&self, project: &UnityProject) -> Option<UnityEditor> {
let editor_option = self let editor_option = self
.config .config
.editors_configurations .editors_configurations
.clone() .clone()
.into_iter() .into_iter()
.find(|editor| editor.version.contains(&project_version)); .find(|editor| editor.version.contains(&project.version));
if let Some(editor) = editor_option { editor_option
println!("{} -projectpath {}", editor.exe_path, project.path); }
Command::new(editor.exe_path)
pub fn run_project(editor: &UnityEditor, project: &UnityProject) {
println!("{} -projectpath {}", editor.exe_path, project.path);
Command::new(&editor.exe_path)
.arg("-projectpath") .arg("-projectpath")
.arg(project.path) .arg(&project.path)
.spawn() .spawn()
.expect("Failed to run project"); .expect("Failed to run project");
}
} }
} }
impl Default for Hub { impl Default for Hub {

8
rusty_hub/src/lib.rs Normal file
View File

@ -0,0 +1,8 @@
#[macro_use]
extern crate serde_derive;
extern crate confy;
pub mod config;
pub mod hub;
pub mod unity_editor;
pub mod unity_project;

View File

@ -1,14 +0,0 @@
#[macro_use]
extern crate serde_derive;
extern crate confy;
mod config;
mod hub;
mod unity_editor;
mod unity_project;
fn main() {
let hub = self::hub::Hub::default();
println!("{:#?}", hub);
// hub.run_project_nr(0);
}

View File

@ -42,19 +42,13 @@ impl UnityProject {
} }
fn get_project_at_path(path: &str) -> Option<UnityProject> { fn get_project_at_path(path: &str) -> Option<UnityProject> {
let path = path.trim_matches(char::from(0)); let path = path.trim_matches(char::from(0)).replace("/", "\\");
let second_path = Path::new(&path.replace("/", "\\")).join("ProjectSettings"); let second_path = Path::new(&path).join("ProjectSettings");
if std::fs::metadata(&second_path).is_err() { if std::fs::metadata(&second_path).is_err() {
println!(
"DUPA: {:#?}, {:#?}",
second_path.display(),
std::fs::metadata(&second_path).err()
);
return None; return None;
} }
let project_version_file = std::fs::read_to_string(second_path.join("ProjectVersion.txt")); let project_version_file = std::fs::read_to_string(second_path.join("ProjectVersion.txt"));
if project_version_file.is_err() { if project_version_file.is_err() {
println!("DUPA2");
return None; return None;
} }
let project_version_file = project_version_file.unwrap(); let project_version_file = project_version_file.unwrap();
@ -64,7 +58,7 @@ impl UnityProject {
Some(UnityProject { Some(UnityProject {
path: path.to_string(), path: path.to_string(),
title: path.to_string(), title: path.split("\\").last().unwrap().to_string(),
version: project_version, version: project_version,
}) })
} }