From 174fcc6cc6d62d0bdc1d89b5acc6d3a746ca80d6 Mon Sep 17 00:00:00 2001 From: Isaac Holston <32341824+iholston@users.noreply.github.com> Date: Fri, 20 Sep 2024 18:49:39 -0400 Subject: [PATCH] refactor: removed lockfile authentication --- Cargo.lock | 584 +++++++++++++++++++++++++++------ Cargo.toml | 11 +- {resources => assets}/icon.ico | Bin build.rs | 2 +- src/accept.rs | 138 -------- src/cmd.rs | 87 +++++ src/lcu.rs | 45 +++ src/main.rs | 48 ++- src/tray.rs | 88 +++-- 9 files changed, 711 insertions(+), 292 deletions(-) rename {resources => assets}/icon.ico (100%) delete mode 100644 src/accept.rs create mode 100644 src/cmd.rs create mode 100644 src/lcu.rs diff --git a/Cargo.lock b/Cargo.lock index 1b588df..f34f131 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -52,6 +52,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "android-activity" version = "0.5.2" @@ -155,9 +164,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.7" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "bitflags" @@ -637,6 +646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -694,6 +704,7 @@ dependencies = [ "futures-core", "futures-io", "futures-macro", + "futures-sink", "futures-task", "memchr", "pin-project-lite", @@ -857,7 +868,7 @@ version = "0.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-crate 2.0.2", "proc-macro-error", "proc-macro2", @@ -940,15 +951,15 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.24" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2c4422095b67ee78da96fbb51a4cc413b3b25883c7717ff7ca1ab31022c9c9" +checksum = "524e8ac6999421f49a846c2d4411f337e53497d8ec55d67753beffa43c5d9205" dependencies = [ + "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "futures-util", "http", "indexmap", "slab", @@ -970,16 +981,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "hermit-abi" -version = "0.3.9" +name = "heck" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "http" -version = "0.2.11" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -988,12 +999,24 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.6" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" dependencies = [ "bytes", "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http", + "http-body", "pin-project-lite", ] @@ -1003,47 +1026,78 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" -[[package]] -name = "httpdate" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" - [[package]] name = "hyper" -version = "0.14.28" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf96e135eb83a2a8ddf766e426a841d8ddd7449d5f00d34ea02b41d2f19eef80" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", - "futures-core", "futures-util", "h2", "http", "http-body", "httparse", - "httpdate", "itoa", "pin-project-lite", - "socket2", + "smallvec", "tokio", - "tower-service", - "tracing", "want", ] +[[package]] +name = "hyper-rustls" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08afdbb5c31130e3034af566421053ab03787c640246a446327f550d11bcb333" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + [[package]] name = "hyper-tls" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", + "http-body-util", "hyper", + "hyper-util", "native-tls", "tokio", "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] @@ -1161,9 +1215,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libappindicator" @@ -1191,9 +1245,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libloading" @@ -1212,7 +1266,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" dependencies = [ "cfg-if", - "windows-targets 0.52.4", + "windows-targets 0.52.6", ] [[package]] @@ -1274,7 +1328,15 @@ version = "2.1.1" dependencies = [ "base64 0.13.1", "image", + "lazy_static", + "powershell_script", + "regex", "reqwest", + "serde", + "serde_derive", + "serde_json", + "strum", + "strum_macros", "tasklist", "tray-icon", "winit", @@ -1466,16 +1528,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "num_enum" version = "0.7.2" @@ -1636,6 +1688,26 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pin-project" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.52", +] + [[package]] name = "pin-project-lite" version = "0.2.13" @@ -1693,6 +1765,21 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "powershell_script" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef8336090917f3d3a044256bc0e5c51d5420e5d09dfa1df4868083c5231a454" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -1755,6 +1842,54 @@ dependencies = [ "memchr", ] +[[package]] +name = "quinn" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c5fdde3cdae7203427dc4f0a68fe0ed09833edc525a03456b153b79828684" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" +dependencies = [ + "bytes", + "rand", + "ring", + "rustc-hash", + "rustls", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fe68c2e9e1a1234e218683dbdf9f9dfcb094113c5ac2b938dfcb9bab4c4140b" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.59.0", +] + [[package]] name = "quote" version = "1.0.35" @@ -1764,6 +1899,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "raw-window-handle" version = "0.6.0" @@ -1819,22 +1984,55 @@ dependencies = [ "thiserror", ] +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "reqwest" -version = "0.11.24" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6920094eb85afde5e4a138be3f2de8bbdf28000f0029e72c45025a56b042251" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "bytes", "encoding_rs", + "futures-channel", "futures-core", "futures-util", "h2", "http", "http-body", + "http-body-util", "hyper", + "hyper-rustls", "hyper-tls", + "hyper-util", "ipnet", "js-sys", "log", @@ -1843,7 +2041,10 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", + "quinn", + "rustls", "rustls-pemfile", + "rustls-pki-types", "serde", "serde_json", "serde_urlencoded", @@ -1851,12 +2052,29 @@ dependencies = [ "system-configuration", "tokio", "tokio-native-tls", + "tokio-rustls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winreg", + "webpki-roots", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" +dependencies = [ + "cc", + "cfg-if", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.52.0", ] [[package]] @@ -1865,6 +2083,12 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc_version" version = "0.4.0" @@ -1887,15 +2111,53 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "rustls" +version = "0.23.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c58f8c84392efc0a126acce10fa59ff7b3d2ac06ab451a33f2741989b806b044" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + [[package]] name = "rustls-pemfile" -version = "1.0.4" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +checksum = "196fe16b00e106300d3e45ecfcb764fa292a535d7326a29a5875c579c7417425" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", + "rustls-pki-types", ] +[[package]] +name = "rustls-pki-types" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0a2ce646f8655401bb81e7927b812614bd5d91dbc968696be50603510fcaf0" + +[[package]] +name = "rustls-webpki" +version = "0.102.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84678086bd54edf2b415183ed7a94d0efb049f1b646a33e22a36f3794be6ae56" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + [[package]] name = "ryu" version = "1.0.17" @@ -1976,18 +2238,18 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -1996,11 +2258,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] @@ -2091,12 +2354,43 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + [[package]] name = "strict-num" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.52", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "1.0.109" @@ -2120,26 +2414,29 @@ dependencies = [ [[package]] name = "sync_wrapper" -version = "0.1.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] [[package]] name = "system-configuration" -version = "0.5.1" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.2", "core-foundation", "system-configuration-sys", ] [[package]] name = "system-configuration-sys" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" dependencies = [ "core-foundation-sys", "libc", @@ -2152,7 +2449,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a2d580ff6a20c55dfb86be5f9c238f67835d0e81cbdea8bf5680e0897320331" dependencies = [ "cfg-expr", - "heck", + "heck 0.4.1", "pkg-config", "toml 0.8.2", "version-compare", @@ -2266,7 +2563,6 @@ dependencies = [ "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", "socket2", "windows-sys 0.48.0", @@ -2282,6 +2578,17 @@ dependencies = [ "tokio", ] +[[package]] +name = "tokio-rustls" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" +dependencies = [ + "rustls", + "rustls-pki-types", + "tokio", +] + [[package]] name = "tokio-util" version = "0.7.10" @@ -2350,6 +2657,27 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + [[package]] name = "tower-service" version = "0.3.2" @@ -2433,6 +2761,12 @@ version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + [[package]] name = "url" version = "2.5.0" @@ -2682,6 +3016,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webpki-roots" +version = "0.26.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bd24728e5af82c6c4ec1b66ac4844bdf8156257fccda846ec58b42cd0cdbe6a" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "weezl" version = "0.1.8" @@ -2732,6 +3075,36 @@ dependencies = [ "windows_x86_64_msvc 0.38.0", ] +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.45.0" @@ -2756,7 +3129,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -2791,17 +3173,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -2818,9 +3201,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -2842,9 +3225,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -2866,9 +3249,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -2890,9 +3279,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -2914,9 +3303,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -2932,9 +3321,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -2956,9 +3345,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winit" @@ -3017,16 +3406,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "winres" version = "0.1.12" @@ -3109,6 +3488,7 @@ version = "0.7.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" dependencies = [ + "byteorder", "zerocopy-derive", ] @@ -3122,3 +3502,9 @@ dependencies = [ "quote", "syn 2.0.52", ] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index af53d8f..3ec71f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,12 +4,21 @@ version = "2.1.1" edition = "2021" [dependencies] +lazy_static = "1.5.0" +reqwest = { version = "0.12.5", features = ["json", "rustls-tls", "blocking"] } +serde_derive = "1.0.205" +serde_json = "1.0.122" base64 = "0.13.0" image = "0.23.14" -reqwest = { version = "0.11.24", features = ["blocking"] } tasklist = "0.2.13" tray-icon = "0.11.3" winit = "0.29.13" +regex = "1.10.6" +powershell_script = "1.1.0" +serde = { version = "1.0.205", features = ["derive"] } +strum = "0.26.3" +strum_macros = "0.26.4" + [build-dependencies] winres = "0.1.12" diff --git a/resources/icon.ico b/assets/icon.ico similarity index 100% rename from resources/icon.ico rename to assets/icon.ico diff --git a/build.rs b/build.rs index fd4ad51..c895417 100644 --- a/build.rs +++ b/build.rs @@ -3,7 +3,7 @@ use winres::WindowsResource; fn main() -> std::io::Result<()> { if std::env::var_os("CARGO_CFG_WINDOWS").is_some() { WindowsResource::new() - .set_icon("resources/icon.ico") + .set_icon("assets/icon.ico") .compile()?; } Ok(()) diff --git a/src/accept.rs b/src/accept.rs deleted file mode 100644 index 31a166e..0000000 --- a/src/accept.rs +++ /dev/null @@ -1,138 +0,0 @@ -use std::io::{Error, ErrorKind}; -use std::sync::{atomic::{AtomicBool, Ordering}, Arc}; -use std::{fs, path::Path, thread, time::Duration}; - -use base64::encode; -use reqwest::blocking::Client; -use reqwest::header::{HeaderMap, HeaderValue}; - -#[derive(Clone)] -struct LeagueSession { - id: u32, - client: Client, - addr: String, -} - -impl LeagueSession { - pub fn new(league_pid: u32) -> Result> { - let mut lockfile_path = String::new(); - unsafe { - let temp = tasklist::get_proc_path(league_pid); - let path = Path::new(&temp); - if let Some(parent) = path.parent() { - if let Some(parent_str) = parent.to_str() { - lockfile_path = format!("{}\\{}", parent_str.to_string(), "lockfile"); - } - } - } - let contents = fs::read_to_string(lockfile_path)?; - let data: Vec<&str> = contents.split(":").collect(); - if data.len() != 5 { - return Err(Box::new(Error::new( - ErrorKind::Other, - "Could not parse lockfile", - ))); - } - let auth = format!( - "Basic {}", - encode(format!("{}:{}", "riot".to_string(), data[3].to_string()).as_bytes()) - ); - let url = format!( - "{}://{}:{}", - data[4].to_string(), - String::from("127.0.0.1"), - data[2].to_string() - ); - let mut headers = HeaderMap::new(); - headers.insert("Authorization", HeaderValue::from_str(&auth)?); - let session = Client::builder() - .default_headers(headers) - .danger_accept_invalid_certs(true) - .build()?; - Ok(LeagueSession { - id: league_pid, - client: session, - addr: url, - }) - } -} - -#[derive(Clone)] -pub struct Acceptor { - game_pname: String, - game_pid: u32, - session: Option, - pub paused: Arc, - pub terminate: Arc, -} - -impl Acceptor { - pub fn new() -> Acceptor { - Acceptor { - game_pname: String::from("LeagueClient.exe"), - game_pid: 0, - session: None, - paused: Arc::new(AtomicBool::new(false)), - terminate: Arc::new(AtomicBool::new(false)), - } - } - - pub fn run(&mut self) { - while !self.terminate.load(Ordering::SeqCst) { - if !self.paused.load(Ordering::SeqCst) && self.game_running() { - if let Some(_) = self.session.as_ref().filter(|ls| ls.id == self.game_pid) { - let phase = self.get_game_phase(); - if phase == "Matchmaking" { - thread::sleep(Duration::from_millis(300)); - continue; - } - if phase == "ReadyCheck" { - self.accept_match(); - thread::sleep(Duration::from_secs(1)); - continue; - } - } else { - match LeagueSession::new(self.game_pid) { - Ok(session) => { - self.session = Some(session); - } - Err(_) => {} - } - } - } - thread::sleep(Duration::from_secs(3)); - } - } - - fn game_running(&mut self) -> bool { - unsafe { - if let Some(pid) = tasklist::find_process_id_by_name(&self.game_pname).get(0) { - self.game_pid = *pid; - return true; - } - } - false - } - - fn get_game_phase(&self) -> String { - if let Some(session) = &self.session { - let url = format!("{}{}", session.addr, "/lol-gameflow/v1/gameflow-phase"); - if let Ok(response) = session.client.get(url).send() { - if let Some(body) = response.text().ok() { - return body.trim_matches('"').to_string(); - } - } - } - String::from("Phase not found") - } - - fn accept_match(&self) { - if let Some(session) = &self.session { - let url = format!( - "{}{}", - session.addr, "/lol-matchmaking/v1/ready-check/accept" - ); - let _ = session.client.post(url).send(); - } - } -} diff --git a/src/cmd.rs b/src/cmd.rs new file mode 100644 index 0000000..cfc492f --- /dev/null +++ b/src/cmd.rs @@ -0,0 +1,87 @@ +use serde::{Deserialize, Serialize}; +use lazy_static::lazy_static; + +const LCU_PORT_KEY: &str = "--app-port="; +const LCU_TOKEN_KEY: &str = "--remoting-auth-token="; +const LCU_DIR_KEY: &str = "--install-directory="; +const LCU_COMMAND: &str = "Get-CimInstance Win32_Process -Filter \"name = 'LeagueClientUx.exe'\" | Select-Object -ExpandProperty CommandLine"; + +lazy_static! { + static ref PORT_REGEXP: regex::Regex = regex::Regex::new(r"--app-port=\d+").unwrap(); + static ref TOKEN_REGEXP: regex::Regex = regex::Regex::new(r"--remoting-auth-token=\S+").unwrap(); + static ref DIR_REGEXP: regex::Regex = regex::Regex::new(r#"--install-directory=(.*?)""#).unwrap(); + static ref MAC_DIR_REGEXP: regex::Regex = regex::Regex::new(r"--install-directory=([^\s]+).*?--").unwrap(); +} + +#[derive(Default, Debug, Clone, Serialize, Deserialize)] +pub struct CommandLineOutput { + pub auth_url: String, + pub token: String, + pub port: String, + pub dir: String, +} + +#[cfg(target_os = "windows")] +pub fn get_commandline() -> CommandLineOutput { + use powershell_script::PsScriptBuilder; + + let ps = PsScriptBuilder::new() + .no_profile(true) + .non_interactive(true) + .hidden(true) + .print_commands(false) + .build(); + + match ps.run(LCU_COMMAND) { + Ok(out) => { + let output = out.stdout(); + + if output.is_some() { + return match_stdout(&String::from(output.unwrap())); + } + } + Err(err) => println!("cmd error: {:?}", err), + } + + CommandLineOutput { + ..Default::default() + } +} + +fn match_stdout(stdout: &str) -> CommandLineOutput { + let port = if let Some(port_match) = PORT_REGEXP.find(stdout) { + port_match.as_str().replace(LCU_PORT_KEY, "") + } else { + "0".to_string() + }; + + let token = if let Some(token_match) = TOKEN_REGEXP.find(stdout) { + token_match + .as_str() + .replace(LCU_TOKEN_KEY, "") + .replace(['\\', '\"'], "") + } else { + "".to_string() + }; + + let auth_url = make_auth_url(&token, &port); + + let raw_dir = if let Some(dir_match) = DIR_REGEXP.find(stdout) { + dir_match.as_str().replace(LCU_DIR_KEY, "") + } else { + "".to_string() + }; + let output_dir = raw_dir.replace('\"', ""); + let dir = format!("{output_dir}/"); + + CommandLineOutput { + auth_url, + token, + port, + dir, + } +} + +fn make_auth_url(token: &String, port: &String) -> String { + format!("https://riot:{token}@127.0.0.1:{port}") +} diff --git a/src/lcu.rs b/src/lcu.rs new file mode 100644 index 0000000..42cd1f5 --- /dev/null +++ b/src/lcu.rs @@ -0,0 +1,45 @@ +use std::time::Duration; +use lazy_static::lazy_static; + +lazy_static! { + static ref CLIENT: reqwest::blocking::Client = { + reqwest::blocking::Client::builder() + .use_rustls_tls() + .danger_accept_invalid_certs(true) + .timeout(Duration::from_secs(2)) + .no_proxy() + .build() + .unwrap() + }; +} + +pub fn make_client() -> &'static reqwest::blocking::Client { + &CLIENT +} + +pub fn accept_match(endpoint: &str) { + let client = make_client(); + let url = format!("{endpoint}/lol-matchmaking/v1/ready-check/accept"); + let _ = client + .post(url) + .version(reqwest::Version::HTTP_2) + .header(reqwest::header::ACCEPT, "application/json") + .send(); +} + +pub fn get_phase(endpoint: &str) -> String { + let mut phase = String::from("Unknown"); + let url = format!("{endpoint}/lol-gameflow/v1/gameflow-phase"); + let client = make_client(); + let response = client + .get(url) + .version(reqwest::Version::HTTP_2) + .header(reqwest::header::ACCEPT, "application/json") + .send() + .ok(); + if let Some(response) = response { + phase = response.text().unwrap_or(phase); + phase = phase.trim_matches('"').to_string(); + } + phase +} diff --git a/src/main.rs b/src/main.rs index c911a6d..eb78a60 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,50 @@ #![windows_subsystem = "windows"] -mod accept; +mod cmd; +mod lcu; mod tray; -use accept::Acceptor; -use tray::TrayApp; +use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::thread; +use std::time::Duration; + +use crate::tray::TrayApp; fn main() { - let mut app = TrayApp::new(Acceptor::new()); - app.run(); + let pause = Arc::new(AtomicBool::new(false)); + let pause_clone = Arc::clone(&pause); + let terminate = Arc::new(AtomicBool::new(false)); + let terminate_clone = Arc::clone(&terminate); + + // Start Acceptor + let mut auth = cmd::get_commandline(); + thread::spawn(move || { + while !terminate.load(Ordering::SeqCst) { + if !pause.load(Ordering::SeqCst) && !auth.auth_url.is_empty() { + match lcu::get_phase(&auth.auth_url).as_str() { + "Lobby" => { + thread::sleep(Duration::from_millis(1000)); + continue; + } + "Matchmaking" => { + thread::sleep(Duration::from_millis(300)); + continue; + } + "ReadyCheck" => { + lcu::accept_match(&auth.auth_url); + thread::sleep(Duration::from_millis(1000)); + continue; + } + _ => {}, + } + } + auth = cmd::get_commandline(); + thread::sleep(Duration::from_millis(5000)); + } + }); + + // Start Tray Icon + let mut icon = TrayApp::new(); + icon.show(pause_clone, terminate_clone); } diff --git a/src/tray.rs b/src/tray.rs index 3c349b0..e5f28e6 100644 --- a/src/tray.rs +++ b/src/tray.rs @@ -1,29 +1,37 @@ -use std::sync::atomic::Ordering; -use std::thread; - -use tray_icon::menu::{Menu, MenuEvent, MenuItem, PredefinedMenuItem}; +use std::sync::Arc; +use std::sync::atomic::{AtomicBool, Ordering}; use tray_icon::{Icon, TrayIcon, TrayIconBuilder}; +use tray_icon::menu::{Menu, MenuEvent, MenuItem, PredefinedMenuItem}; use winit::event_loop::{ControlFlow, EventLoopBuilder}; -use crate::Acceptor; +const ICON_BYTES: &'static [u8] = include_bytes!("../assets/icon.ico"); -const ICON_BYTES: &'static [u8] = include_bytes!("../resources/icon.ico"); +fn load_icon() -> Icon { + let (icon_rgba, icon_width, icon_height) = { + let image = image::load_from_memory_with_format(&ICON_BYTES, image::ImageFormat::Ico) + .expect("Failed to open icon path") + .into_rgba8(); + let (width, height) = image.dimensions(); + let rgba = image.into_raw(); + (rgba, width, height) + }; + Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon") +} pub struct TrayApp { #[allow(dead_code)] icon: TrayIcon, - start: MenuItem, - pause: MenuItem, - quit: MenuItem, - acceptor: Acceptor, + menu_start: MenuItem, + menu_pause: MenuItem, + menu_quit: MenuItem, } impl TrayApp { - pub fn new(acceptor: Acceptor) -> Self { - let tray_menu = Menu::new(); + pub fn new() -> Self { let menu_start = MenuItem::new("Start", false, None); let menu_pause = MenuItem::new("Pause", true, None); let menu_quit = MenuItem::new("Quit", true, None); + let tray_menu = Menu::new(); tray_menu .append_items(&[ &menu_start, @@ -33,27 +41,23 @@ impl TrayApp { &menu_quit, ]) .unwrap(); - let tray_icon = TrayIconBuilder::new() + + let icon = TrayIconBuilder::new() .with_menu(Box::new(tray_menu)) - .with_tooltip("LoL-Acceptor") - .with_icon(Self::load_icon()) + .with_tooltip("LoL-Accept") + .with_icon(load_icon()) .build() .unwrap(); + TrayApp { - icon: tray_icon, - start: menu_start, - pause: menu_pause, - quit: menu_quit, - acceptor, + icon, + menu_start, + menu_pause, + menu_quit, } } - pub fn run(&mut self) { - let mut acceptor_clone = self.acceptor.clone(); - thread::spawn(move || { - acceptor_clone.run(); - }); - + pub fn show(&mut self, pause: Arc, terminate: Arc) { let menu_channel = MenuEvent::receiver(); let event_loop = EventLoopBuilder::new().build().unwrap(); @@ -61,32 +65,20 @@ impl TrayApp { .run(move |_event, event_loop| { event_loop.set_control_flow(ControlFlow::Wait); if let Ok(event) = menu_channel.try_recv() { - if event.id() == self.start.id() { - self.acceptor.paused.store(false, Ordering::SeqCst); - self.start.set_enabled(false); - self.pause.set_enabled(true); - } else if event.id() == self.pause.id() { - self.acceptor.paused.store(true, Ordering::SeqCst); - self.start.set_enabled(true); - self.pause.set_enabled(false); - } else if event.id() == self.quit.id() { - self.acceptor.terminate.store(true, Ordering::SeqCst); + if event.id() == self.menu_start.id() { + pause.store(false, Ordering::SeqCst); + self.menu_start.set_enabled(false); + self.menu_pause.set_enabled(true); + } else if event.id() == self.menu_pause.id() { + pause.store(true, Ordering::SeqCst); + self.menu_start.set_enabled(true); + self.menu_pause.set_enabled(false); + } else if event.id() == self.menu_quit.id() { + terminate.store(true, Ordering::SeqCst); event_loop.exit(); } } }) .unwrap(); } - - fn load_icon() -> Icon { - let (icon_rgba, icon_width, icon_height) = { - let image = image::load_from_memory_with_format(&ICON_BYTES, image::ImageFormat::Ico) - .expect("Failed to open icon path") - .into_rgba8(); - let (width, height) = image.dimensions(); - let rgba = image.into_raw(); - (rgba, width, height) - }; - Icon::from_rgba(icon_rgba, icon_width, icon_height).expect("Failed to open icon") - } }