diff --git a/Cargo.lock b/Cargo.lock index fa374df..bf54eee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,6 +69,15 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.104" @@ -128,6 +137,15 @@ dependencies = [ "stable_deref_trait", ] +[[package]] +name = "ash" +version = "0.38.0+1.3.281" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb44936d800fea8f016d7f2311c6a4f97aebd5dc86f09906139ec848cf3a46f" +dependencies = [ + "libloading", +] + [[package]] name = "async-broadcast" version = "0.7.2" @@ -405,6 +423,12 @@ dependencies = [ "no_std_io2", ] +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "block2" version = "0.5.1" @@ -581,6 +605,8 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81" dependencies = [ + "serde", + "termcolor", "unicode-width", ] @@ -619,6 +645,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -632,8 +668,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", - "core-foundation", - "core-graphics-types", + "core-foundation 0.9.4", + "core-graphics-types 0.1.3", "foreign-types", "libc", ] @@ -645,7 +681,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" +dependencies = [ + "bitflags 2.13.2", + "core-foundation 0.10.1", "libc", ] @@ -989,6 +1036,12 @@ dependencies = [ "zlib-rs", ] +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + [[package]] name = "foldhash" version = "0.2.0" @@ -1233,6 +1286,17 @@ dependencies = [ "weezl", ] +[[package]] +name = "gl_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + [[package]] name = "glam" version = "0.25.0" @@ -1269,6 +1333,78 @@ dependencies = [ "walkdir", ] +[[package]] +name = "glow" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e5ea60d70410161c8bf5da3fdfeaa1c72ed2c15f8bbb9d19fe3a4fad085f08" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "glutin_wgl_sys" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4ee00b289aba7a9e5306d57c2d05499b2e5dc427f84ac708bd2c090212cf3e" +dependencies = [ + "gl_generator", +] + +[[package]] +name = "gpu-alloc" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45cf04b2726f02df5508c6de726acdc90cdf97ac771a9a0ffd8ba10a6e696bf9" +dependencies = [ + "bitflags 2.13.2", + "gpu-alloc-types", +] + +[[package]] +name = "gpu-alloc-types" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2bbed164dd10ed526c2e4fe3e721ca4a71c61730e5aafac6844b417b3227058" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "gpu-allocator" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd" +dependencies = [ + "log", + "presser", + "thiserror 1.0.69", + "windows 0.58.0", +] + +[[package]] +name = "gpu-descriptor" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b89c83349105e3732062a895becfc71a8f921bb71ecbbdd8ff99263e3b53a0ca" +dependencies = [ + "bitflags 2.13.2", + "gpu-descriptor-types", + "hashbrown 0.15.5", +] + +[[package]] +name = "gpu-descriptor-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdf242682df893b86f33a73828fb09ca4b2d3bb6cc95249707fc684d27484b91" +dependencies = [ + "bitflags 2.13.2", +] + [[package]] name = "guillotiere" version = "0.6.2" @@ -1304,13 +1440,22 @@ dependencies = [ "smallvec", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash 0.1.5", +] + [[package]] name = "hashbrown" version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ - "foldhash", + "foldhash 0.2.0", ] [[package]] @@ -1764,6 +1909,23 @@ dependencies = [ "mutate_once", ] +[[package]] +name = "khronos-egl" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aae1df220ece3c0ada96b8153459b67eebe9ae9212258bb0134ae60416fdf76" +dependencies = [ + "libc", + "libloading", + "pkg-config", +] + +[[package]] +name = "khronos_api" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" + [[package]] name = "kira-installer" version = "0.1.0" @@ -1909,6 +2071,15 @@ version = "0.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f66e8d5d03f609abc3a39e6f08e4164ebf1447a732906d39eb9b99b7919ef39" +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + [[package]] name = "maybe-rayon" version = "0.1.1" @@ -1943,6 +2114,21 @@ dependencies = [ "autocfg", ] +[[package]] +name = "metal" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00c15a6f673ff72ddcc22394663290f870fb224c1bfce55734a75c414150e605" +dependencies = [ + "bitflags 2.13.2", + "block", + "core-graphics-types 0.2.0", + "foreign-types", + "log", + "objc", + "paste", +] + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -1994,7 +2180,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "windows", + "windows 0.62.2", "zbus", ] @@ -2025,6 +2211,7 @@ dependencies = [ "num-traits", "once_cell", "rustc-hash 1.1.0", + "spirv", "thiserror 2.0.20", "unicode-ident", ] @@ -2181,6 +2368,15 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + [[package]] name = "objc-sys" version = "0.3.5" @@ -2547,6 +2743,15 @@ dependencies = [ "libredox", ] +[[package]] +name = "ordered-float" +version = "5.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c7c9e0d9b23589f26070720bac724174bfec1083e82f7854cdd0267518343c0" +dependencies = [ + "num-traits", +] + [[package]] name = "ordered-stream" version = "0.2.0" @@ -2723,6 +2928,12 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "presser" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" + [[package]] name = "proc-macro-crate" version = "3.5.0" @@ -2871,6 +3082,12 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" +[[package]] +name = "range-alloc" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca45419789ae5a7899559e9512e58ca889e41f04f1f2445e9f4b290ceccd1d08" + [[package]] name = "rangemap" version = "1.8.0" @@ -3436,6 +3653,15 @@ dependencies = [ "x11rb", ] +[[package]] +name = "spirv" +version = "0.3.0+sdk-1.3.268.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eda41003dc44290527a59b13432d4a0379379fa074b70174882adfbdfd917844" +dependencies = [ + "bitflags 2.13.2", +] + [[package]] name = "stable_deref_trait" version = "1.2.1" @@ -3515,6 +3741,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -3995,12 +4230,18 @@ dependencies = [ "cfg_aliases", "document-features", "hashbrown 0.16.1", + "js-sys", "log", + "naga", + "parking_lot", "portable-atomic", "profiling", "raw-window-handle", "smallvec", "static_assertions", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", "wgpu-core", "wgpu-hal", "wgpu-types", @@ -4031,11 +4272,31 @@ dependencies = [ "rustc-hash 1.1.0", "smallvec", "thiserror 2.0.20", + "wgpu-core-deps-apple", + "wgpu-core-deps-emscripten", "wgpu-core-deps-windows-linux-android", "wgpu-hal", "wgpu-types", ] +[[package]] +name = "wgpu-core-deps-apple" +version = "27.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0772ae958e9be0c729561d5e3fd9a19679bcdfb945b8b1a1969d9bfe8056d233" +dependencies = [ + "wgpu-hal", +] + +[[package]] +name = "wgpu-core-deps-emscripten" +version = "27.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b06ac3444a95b0813ecfd81ddb2774b66220b264b3e2031152a4a29fda4da6b5" +dependencies = [ + "wgpu-hal", +] + [[package]] name = "wgpu-core-deps-windows-linux-android" version = "27.0.0" @@ -4051,18 +4312,47 @@ version = "27.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b21cb61c57ee198bc4aff71aeadff4cbb80b927beb912506af9c780d64313ce" dependencies = [ + "android_system_properties", + "arrayvec", + "ash", + "bit-set", "bitflags 2.13.2", + "block", + "bytemuck", "cfg-if", "cfg_aliases", + "core-graphics-types 0.2.0", + "glow", + "glutin_wgl_sys", + "gpu-alloc", + "gpu-allocator", + "gpu-descriptor", + "hashbrown 0.16.1", + "js-sys", + "khronos-egl", + "libc", "libloading", "log", + "metal", "naga", + "ndk-sys", + "objc", + "once_cell", + "ordered-float", + "parking_lot", "portable-atomic", "portable-atomic-util", + "profiling", + "range-alloc", "raw-window-handle", "renderdoc-sys", + "smallvec", "thiserror 2.0.20", + "wasm-bindgen", + "web-sys", "wgpu-types", + "windows 0.58.0", + "windows-core 0.58.0", ] [[package]] @@ -4101,6 +4391,16 @@ dependencies = [ "thiserror 2.0.20", ] +[[package]] +name = "windows" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd04d41d93c4992d421894c18c8b43496aa748dd4c081bac0dc93eb0489272b6" +dependencies = [ + "windows-core 0.58.0", + "windows-targets", +] + [[package]] name = "windows" version = "0.62.2" @@ -4108,7 +4408,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" dependencies = [ "windows-collections", - "windows-core", + "windows-core 0.62.2", "windows-future", "windows-numerics", ] @@ -4119,7 +4419,20 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" dependencies = [ - "windows-core", + "windows-core 0.62.2", +] + +[[package]] +name = "windows-core" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ba6d44ec8c2591c134257ce647b7ea6b20335bf6379a27dac5f1641fcf59f99" +dependencies = [ + "windows-implement 0.58.0", + "windows-interface 0.58.0", + "windows-result 0.2.0", + "windows-strings 0.1.0", + "windows-targets", ] [[package]] @@ -4128,11 +4441,11 @@ version = "0.62.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" dependencies = [ - "windows-implement", - "windows-interface", + "windows-implement 0.60.2", + "windows-interface 0.59.3", "windows-link", - "windows-result", - "windows-strings", + "windows-result 0.4.1", + "windows-strings 0.5.1", ] [[package]] @@ -4141,11 +4454,22 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" dependencies = [ - "windows-core", + "windows-core 0.62.2", "windows-link", "windows-threading", ] +[[package]] +name = "windows-implement" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "windows-implement" version = "0.60.2" @@ -4157,6 +4481,17 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "windows-interface" +version = "0.58.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + [[package]] name = "windows-interface" version = "0.59.3" @@ -4180,10 +4515,19 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" dependencies = [ - "windows-core", + "windows-core 0.62.2", "windows-link", ] +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-result" version = "0.4.1" @@ -4193,6 +4537,16 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result 0.2.0", + "windows-targets", +] + [[package]] name = "windows-strings" version = "0.5.1" @@ -4316,7 +4670,7 @@ dependencies = [ "calloop", "cfg_aliases", "concurrent-queue", - "core-foundation", + "core-foundation 0.9.4", "core-graphics", "cursor-icon", "dpi", @@ -4421,6 +4775,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" +[[package]] +name = "xml-rs" +version = "0.8.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e450f9b2ed1dff33c94c12589a87338689467b9c4f5d8a5710bd09a847d2c8a7" + [[package]] name = "y4m" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index 51ec07f..c044b92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,8 @@ edition = "2024" [dependencies] blocking = "1.6" -iced = { version = "0.14", default-features = false, features = ["crisp", "linux-theme-detection", "tiny-skia", "x11", "smol", "image"] } +iced = { version = "0.14", default-features = false, features = ["crisp", "linux-theme-detection", "tiny-skia", "wgpu", "x11", "smol", "image"] } +#iced = { git = "https://github.com/iced-rs/iced", branch = "vello_cpu", default-features = false, features = ["crisp", "linux-theme-detection", "vello-cpu", "x11", "smol", "image"]} iced_moving_picture = "0" log = "0.4" rust-i18n = "3" @@ -29,6 +30,7 @@ lto = true debug = false incremental = false codegen-units = 1 +# We need level 3 for tiny-skia otherwise render is lagging opt-level = "s" strip = true diff --git a/src/kira_disk_layout.rs b/src/kira_disk_layout.rs index 1724611..4a1ad4a 100644 --- a/src/kira_disk_layout.rs +++ b/src/kira_disk_layout.rs @@ -116,6 +116,23 @@ impl BlkDev { } } +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct BcachefsProp { + pub password: Option, + pub comp_alg: Option, +} + +impl BcachefsProp { + pub fn new(password: Option, comp_alg: Option) -> Self { + Self { password:password, comp_alg: comp_alg } + } + + pub fn default() -> Self { + Self { password: None, comp_alg: None } + } + +} + #[derive(Debug, Clone, PartialEq, Eq)] pub enum FSType { VFAT, @@ -124,7 +141,7 @@ pub enum FSType { SWAP, EXT4, BTRFS, - BCACHEFS, + BCACHEFS(BcachefsProp), UNKNOWN, } @@ -137,7 +154,7 @@ impl std::fmt::Display for FSType { Self::SWAP => write!(f, "swap"), Self::EXT4 => write!(f, "ext4"), Self::BTRFS => write!(f, "btrfs"), - Self::BCACHEFS => write!(f, "bcachefs"), + Self::BCACHEFS(_) => write!(f, "bcachefs"), Self::UNKNOWN => write!(f, "unknown"), } } @@ -153,7 +170,7 @@ impl FSType { "swap" => Self::SWAP, "ext4" => Self::EXT4, "btrfs" => Self::BTRFS, - "bcachefs" => Self::BCACHEFS, + "bcachefs" => Self::BCACHEFS(BcachefsProp::default()), _ => Self::UNKNOWN, } } @@ -168,7 +185,7 @@ impl FSType { Self::EXT4 => "ext4", Self::BTRFS => "btrfs", // workaroud as parted do not support bcachefs partition type - Self::BCACHEFS => "bcachefs", + Self::BCACHEFS(_) => "xfs", // lets do something generic here instead of panic Self::UNKNOWN => "linux-swap", } @@ -191,10 +208,7 @@ impl FSType { pub enum PartRole { EFI, ROOT, - HOME, - SWAP, - LuksRoot, - LuksHome, + SWAP } #[derive(Debug, Clone, PartialEq, Eq)] @@ -413,7 +427,7 @@ impl PartLayout { self.add_part(p_size, fs_type, gpt_label, fs_label, mount_point, role) } - pub fn gen_kira_layout(dev: BlkDev, efi_size: KiraSize, swap_size: KiraSize) -> Self { + pub fn gen_kira_layout(dev: BlkDev, efi_size: KiraSize, swap_size: KiraSize, maybe_password: Option, maybe_compr: Option) -> Self { let mut res: PartLayout = PartLayout::new(dev); // UEFI partition @@ -428,7 +442,7 @@ impl PartLayout { ) .add_part_reserve( swap_size, - FSType::BTRFS, + FSType::BCACHEFS(BcachefsProp::new(maybe_password, maybe_compr)), Some("bee-root".into()), None, Some("/".into()), diff --git a/src/kira_system.rs b/src/kira_system.rs index 5149561..e3c3f41 100644 --- a/src/kira_system.rs +++ b/src/kira_system.rs @@ -150,13 +150,14 @@ fn parted_get_last_part_num(dev: &BlkDev) -> Result { /// parted --script $install_device mklabel gpt /// Its blocking function pub fn parted_init_gpt_part_table(dev: &BlkDev) -> Result<(), ExecCommandError> { - exec_parted(&vec![ + let dev_full_name = dev.full_name(); + let args = vec![ "--script", - dev.full_name().as_str(), + &dev_full_name, "mklabel", "gpt", - ]) - .map(|_| ()) + ]; + exec_command("parted", &args) } const LINUX_ROOT_X86_64_TYPE: &str = "4F68BCE3-E8CD-4DB1-96E7-FBCAF984B709"; @@ -217,6 +218,7 @@ pub fn parted_mkpart(dev: &BlkDev, part: &PartInfo) -> Result<(), ExecCommandErr } /// creating single drive bcachefs volume +/// compression: lz4, zstd pub fn bcachefs_format( dev_name: &str, compression: Option, @@ -226,10 +228,11 @@ pub fn bcachefs_format( // --data_checksum=none - do not make sense on single dev volumes // sudo bcachefs format --force --compression=lz4 --background_compression=lz4 --encrypted --passphrase_file=./test.pass /dev/loop0 - let mut arg = vec!["format", "--force", "--data_checksum=none"]; + let mut arg = vec!["format", "--force"]; // if compression algorythm specified - if let Some(compresss_alg) = &compression { - arg.push(compresss_alg.as_str()); + let maybe_comp_cmd = compression.and_then(|alg| Some(format!("--compression={}", alg))); + if let Some(comp_cmd) = &maybe_comp_cmd { + arg.push(comp_cmd); } // if we want encrypted volume if let Some(passw) = password { diff --git a/src/main.rs b/src/main.rs index 4ae3c4b..1a1139b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,35 +72,31 @@ enum Message { struct KiraState { current_view: Views, - toml_config: toml::Table, - config: KiraConfig, + k_config: KiraConfig, stages_save: Vec, } -const CONFIG_PATH_STR: &str = "kira_config.toml"; +// const CONFIG_PATH_STR: &str = "kira_config.toml"; -fn load_kira_config(config_path: &str) -> Result> { - use std::fs; - use toml::Table; - // 1. Read the file content into a String - let content = fs::read_to_string(config_path)?; +// fn load_kira_config(config_path: &str) -> Result> { +// use std::fs; +// use toml::Table; +// // 1. Read the file content into a String +// let content = fs::read_to_string(config_path)?; - // 2. Parse the string into a Table - let table: Table = content.parse()?; +// // 2. Parse the string into a Table +// let table: Table = content.parse()?; - log::info!("{:?}", table); - Ok(table) -} +// log::info!("{:?}", table); +// Ok(table) +// } impl KiraState { fn boot() -> (Self, Task) { ( Self { current_view: Views::Start, - toml_config: toml::Table::new(), - config: KiraConfig { - config_trail: Vec::new(), - }, + k_config: KiraConfig ::default(), stages_save: Vec::new(), }, Task::done(Message::Start), @@ -125,26 +121,19 @@ fn view(k_state: &KiraState) -> Element<'_, Message> { fn update(k_state: &mut KiraState, message: Message) -> Task { match message { - Message::Start => match load_kira_config(CONFIG_PATH_STR) { - Ok(conf) => { - log::info!("Config loaded!"); - k_state.toml_config = conf; - k_state.current_view = Views::Welcome(WelcomeStage::new()); + Message::Start => { + log::info!("Starting!"); + k_state.current_view = Views::Welcome(WelcomeStage::new(k_state.k_config.clone())); Task::none() - } - Err(ex) => { - log::error!("Error reading config {}: {}", CONFIG_PATH_STR, ex); - iced::exit() - } }, Message::Welcome(wlc_msg) => { if let Views::Welcome(wlc_view) = &mut k_state.current_view { match wlc_view.update(wlc_msg) { StageAction::Next(welcome_res) => { - k_state.config.config_trail.push(welcome_res); + k_state.k_config = welcome_res; let s_state = std::mem::replace( &mut k_state.current_view, - Views::License(license::LicenseStage {}), + Views::License(license::LicenseStage::new(k_state.k_config.clone())), ); k_state.stages_save.push(s_state); Task::none() @@ -161,10 +150,10 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { let action = license_view.update(license_message); match action { StageAction::Next(license_res) => { - k_state.config.config_trail.push(license_res); + k_state.k_config = license_res; let s_state = std::mem::replace( &mut k_state.current_view, - Views::Network(network::NetworkStage::new(&k_state.toml_config)), + Views::Network(network::NetworkStage::new(k_state.k_config.clone())), ); k_state.stages_save.push(s_state); Task::done(Message::Network(network::Message::CheckNetwork)) @@ -172,7 +161,6 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { StageAction::Abort => iced::exit(), StageAction::Back => { k_state.current_view = k_state.stages_save.pop().unwrap(); - k_state.config.config_trail.pop(); Task::none() } StageAction::None => Task::none(), @@ -188,17 +176,16 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { network::UpdateResult::Task(t) => t.map(Message::Network), network::UpdateResult::StageAction(action) => match action { StageAction::Next(network_res) => { - k_state.config.config_trail.push(network_res); + k_state.k_config = network_res; let s_state = std::mem::replace( &mut k_state.current_view, - Views::TimeZone(stages::timezone::TimeZoneStage::new()), + Views::TimeZone(stages::timezone::TimeZoneStage::new(k_state.k_config.clone())), ); k_state.stages_save.push(s_state); Task::none() } StageAction::Back => { k_state.current_view = k_state.stages_save.pop().unwrap(); - k_state.config.config_trail.pop(); Task::none() } _ => Task::none(), @@ -213,17 +200,16 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { let action = timezone_view.update(timezone_message); match action { StageAction::Next(tz_res) => { - k_state.config.config_trail.push(tz_res); + k_state.k_config = tz_res; let s_state = std::mem::replace( &mut k_state.current_view, - Views::Locale(stages::locale::LocaleStage::new(&k_state.config)), + Views::Locale(stages::locale::LocaleStage::new(k_state.k_config.clone())), ); k_state.stages_save.push(s_state); Task::none() } StageAction::Abort => iced::exit(), StageAction::Back => { - k_state.config.config_trail.pop(); k_state.current_view = k_state.stages_save.pop().unwrap(); Task::none() } @@ -237,16 +223,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { if let Views::Locale(locale_view) = &mut k_state.current_view { match locale_view.update(locale_msg) { StageAction::Next(locale_res) => { - k_state.config.config_trail.push(locale_res); + k_state.k_config = locale_res; let s_state = std::mem::replace( &mut k_state.current_view, - Views::Keyboard(stages::keyboard::KeyboardStage::new()), + Views::Keyboard(stages::keyboard::KeyboardStage::new(k_state.k_config.clone())), ); k_state.stages_save.push(s_state); Task::none() } StageAction::Back => { - k_state.config.config_trail.pop(); k_state.current_view = k_state.stages_save.pop().unwrap(); Task::none() } @@ -260,9 +245,9 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { if let Views::Keyboard(keyboard_view) = &mut k_state.current_view { match keyboard_view.update(keyboard_msg) { StageAction::Next(keyboard_res) => { - match stages::partition::PartitionStage::new(&k_state.toml_config) { + match stages::partition::PartitionStage::new(k_state.k_config.clone()) { Ok(part_stage) => { - k_state.config.config_trail.push(keyboard_res); + k_state.k_config = keyboard_res; let s_state = std::mem::replace( &mut k_state.current_view, Views::Partition(part_stage), @@ -276,7 +261,6 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { Task::none() } StageAction::Back => { - k_state.config.config_trail.pop(); k_state.current_view = k_state.stages_save.pop().unwrap(); Task::none() } @@ -290,16 +274,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { if let Views::Partition(partition_view) = &mut k_state.current_view { match partition_view.update(partition_msg) { StageAction::Next(partition_res) => { - k_state.config.config_trail.push(partition_res); + k_state.k_config = partition_res; let s_state = std::mem::replace( &mut k_state.current_view, - Views::Security(stages::security::SecurityStage::new()), + Views::Security(stages::security::SecurityStage::new(k_state.k_config.clone())), ); k_state.stages_save.push(s_state); Task::none() } StageAction::Back => { - k_state.config.config_trail.pop(); k_state.current_view = k_state.stages_save.pop().unwrap(); Task::none() } @@ -313,16 +296,15 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { if let Views::Security(security_view) = &mut k_state.current_view { match security_view.update(security_msg) { StageAction::Next(security_res) => { - k_state.config.config_trail.push(security_res); + k_state.k_config = security_res; let s_state = std::mem::replace( &mut k_state.current_view, - Views::Install(stages::install::InstallStage::new(&k_state.config)), + Views::Install(stages::install::InstallStage::new(k_state.k_config.clone())), ); k_state.stages_save.push(s_state); Task::none() } StageAction::Back => { - k_state.config.config_trail.pop(); k_state.current_view = k_state.stages_save.pop().unwrap(); Task::none() } @@ -339,7 +321,6 @@ fn update(k_state: &mut KiraState, message: Message) -> Task { stages::install::Update::Task(t) => t.map(Message::Install), stages::install::Update::StgAct(stage_action) => match stage_action { StageAction::Back => { - k_state.config.config_trail.pop(); k_state.current_view = k_state.stages_save.pop().unwrap(); Task::none() } diff --git a/src/stage.rs b/src/stage.rs index c7f9bf9..7ca0705 100644 --- a/src/stage.rs +++ b/src/stage.rs @@ -18,47 +18,38 @@ This file contains basic enums and structs to be used with stages. */ +use iced::wgpu::naga::compact::KeepUnused::No; + use crate::stages; + // #[derive(Debug, Clone)] -// pub enum ConfigValue { -// String(String), -// I64(i64), -// U64(u64), -// F64(f64), -// Bool(bool), -// PartLayout(PartLayout), -// KiraSize(KiraSize), -// Vector(Vec), -// Dictionary(HashMap), +// pub enum StageResult { +// WelcomeStageResult(stages::welcome::WelcomeStageResult), +// NetworkStageResult(stages::network::NetworkStageResult), +// LocaleStageResult(stages::locale::LocaleStageResult), +// TimeZoneStageResult(stages::timezone::TimeZoneStageResult), +// KeyboardStageResult(stages::keyboard::KeyboardStageResult), +// SecurityStageResult(stages::security::SecurityStageResult), +// PartitionStageResult(stages::partition::PartitionStageResult), +// None, // } -#[derive(Debug, Clone)] -pub enum StageResult { - WelcomeStageResult(stages::welcome::WelcomeStageResult), - NetworkStageResult(stages::network::NetworkStageResult), - LocaleStageResult(stages::locale::LocaleStageResult), - TimeZoneStageResult(stages::timezone::TimeZoneStageResult), - KeyboardStageResult(stages::keyboard::KeyboardStageResult), - SecurityStageResult(stages::security::SecurityStageResult), - PartitionStageResult(stages::partition::PartitionStageResult), - None, -} +// impl StageResult { +// pub fn name(&self) -> String { +// match self { +// Self::LocaleStageResult(_) => "locale".into(), +// Self::WelcomeStageResult(_) => "welcome".into(), +// Self::NetworkStageResult(_) => "network".into(), +// Self::TimeZoneStageResult(_) => "timezone".into(), +// Self::KeyboardStageResult(_) => "keyboard".into(), +// Self::PartitionStageResult(_) => "partition".into(), +// Self::SecurityStageResult(_) => "security".into(), +// Self::None => "none".into(), +// } +// } +// } -impl StageResult { - pub fn name(&self) -> String { - match self { - Self::LocaleStageResult(_) => "locale".into(), - Self::WelcomeStageResult(_) => "welcome".into(), - Self::NetworkStageResult(_) => "network".into(), - Self::TimeZoneStageResult(_) => "timezone".into(), - Self::KeyboardStageResult(_) => "keyboard".into(), - Self::PartitionStageResult(_) => "partition".into(), - Self::SecurityStageResult(_) => "security".into(), - Self::None => "none".into(), - } - } -} // impl StageResult { // pub fn new(name: &str) -> Self { // Self { @@ -129,36 +120,52 @@ impl StageResult { #[derive(Debug, Clone)] pub struct KiraConfig { - pub config_trail: Vec, + pub res_welcome: Option, + pub res_license: bool, + pub res_network: Option, + pub res_timezone: Option, + pub res_locale: Option, + pub res_keyboard: Option, + pub res_partition: Option, + pub res_security: Option, + pub res_install: bool, } impl Default for KiraConfig { fn default() -> Self { Self { - config_trail: Vec::new(), + res_welcome: None, + res_license: false, + res_network: None, + res_timezone: None, + res_locale: None, + res_keyboard: None, + res_partition: None, + res_security: None, + res_install: false, } } } -impl KiraConfig { - pub fn get_stage(&self, name: &str) -> Option { - self.config_trail - .iter() - .find(|v| v.name() == name) - .and_then(|v| Some(v.clone())) - } - pub fn pop_last(&mut self) -> Option { - self.config_trail.pop() - } - pub fn push(&mut self, stage_result: StageResult) { - self.config_trail.push(stage_result); - } -} +// impl KiraConfig { +// pub fn get_stage(&self, name: &str) -> Option { +// self.config_trail +// .iter() +// .find(|v| v.name() == name) +// .and_then(|v| Some(v.clone())) +// } +// pub fn pop_last(&mut self) -> Option { +// self.config_trail.pop() +// } +// pub fn push(&mut self, stage_result: StageResult) { +// self.config_trail.push(stage_result); +// } +// } #[derive(Debug, Clone)] pub enum StageAction { Back, None, - Next(StageResult), + Next(KiraConfig), Abort, } diff --git a/src/stages/install/mod.rs b/src/stages/install/mod.rs index c116bc3..4d64896 100644 --- a/src/stages/install/mod.rs +++ b/src/stages/install/mod.rs @@ -19,30 +19,32 @@ */ use crate::{ - kira_disk_layout::{self, BlkDev, PartLayout, PartRole}, - kira_system::{self, ExecCommandError}, + kira_disk_layout::{self, BlkDev, FSType, PartLayout, PartRole}, kira_size::KiraSize, + kira_system::{self, ExecCommandError}, kira_theming, - stage::{KiraConfig, StageAction, StageResult}, + stage::{KiraConfig, StageAction}, stages::partition::PartitionStageResult, }; use iced::{ - Alignment, Task, futures::{self, SinkExt, StreamExt, TryStreamExt, channel::mpsc::SendError}, widget, + Alignment, Task, + futures::{self, SinkExt, StreamExt, TryStreamExt, channel::mpsc::SendError}, + widget, }; use iced::{Color, Length, futures::channel::mpsc::Sender, widget::container}; -/// -/// So. I am goind to make dir structure lile this -/// /bzz/root -/// /bzz/home -/// Mount root from it and binmount home -/// + use log; use rust_i18n::t; +const EFI_BOOT_MOUNT_POINT: &str = "/beefi"; + /// Creates new GPT table and partitions from PartLayout pub fn create_partitions(part_layout: &PartLayout) -> Result<(), ExecCommandError> { + log::info!("Creating GPT part table..."); kira_system::parted_init_gpt_part_table(&part_layout.dev)?; + log::info!("Start to create partitions..."); for part in &part_layout.part_list { + log::info!("Creating partition: {}", part); kira_system::parted_mkpart(&part_layout.dev, part)?; } Ok(()) @@ -55,13 +57,12 @@ pub fn create_partitions(part_layout: &PartLayout) -> Result<(), ExecCommandErro /// creates subvolumes bzz/root bzz/home pub fn bcachefs_init( dev_name: &str, - compression: Option, - password: Option, mnt_dir: &str, + password: Option, + comp_alg: Option, ) -> Result<(), ExecCommandError> { - // format device - kira_system::bcachefs_format(dev_name, compression, password.clone())?; + kira_system::bcachefs_format(dev_name, comp_alg, password.clone())?; // if encryption used - unlock drive if let Some(pass) = password { @@ -71,17 +72,14 @@ pub fn bcachefs_init( //mount drive kira_system::bcachefs_mount(dev_name, mnt_dir)?; - // Creating bzz_snaps directory for root snapshoots - std::fs::create_dir(format!("{}{}", mnt_dir, "/bzz_snaps"))?; - - // We want /var to bee simple dir so snapshoting root capture it - std::fs::create_dir(format!("{}{}", mnt_dir, "/var"))?; + // Creating bzz-snaps directory for root snapshoots + std::fs::create_dir(format!("{}{}", mnt_dir, "/bzz-snaps"))?; // Creating boot directory for efi mounting - std::fs::create_dir_all(format!("{}{}", mnt_dir, "/bzz-boot/uefi"))?; - + std::fs::create_dir_all(format!("{}{}", mnt_dir, EFI_BOOT_MOUNT_POINT))?; + // create subvolumes - for vol_name in ["/home", "/tmp", "/var/tmp"] { + for vol_name in ["/home", "/usr", "/var", "/var/tmp"] { let vol_path = format!("{}{}", mnt_dir, vol_name); kira_system::bcachefs_create_subvolume(vol_path.as_str())?; } @@ -89,10 +87,11 @@ pub fn bcachefs_init( Ok(()) } -pub fn init_disk(part_layout: &PartLayout) -> Result<(), ExecCommandError> { +pub fn init_disk(part_layout: &PartLayout, mnt_dir: &str) -> Result<(), ExecCommandError> { // use parted to create partition gpt layout create_partitions(part_layout)?; + // format partitions for part in &part_layout.part_list { match part.role { Some(PartRole::EFI) => { @@ -100,6 +99,22 @@ pub fn init_disk(part_layout: &PartLayout) -> Result<(), ExecCommandError> { kira_system::mkfs_esp(&part_l)?; } } + Some(PartRole::ROOT) => { + if let Some(part_l) = part.partlabel_dev() { + if let FSType::BCACHEFS(bc_par) = &part.fs_type { + bcachefs_init( + &part_l, + mnt_dir, + bc_par.password.clone(), + bc_par.comp_alg.clone(), + )?; + } else { + return Err(ExecCommandError::Other( + "ROOT partition is not BCACHEFS type!".into(), + )); + } + } + } Some(PartRole::SWAP) => { if let Some(part_l) = part.partlabel_dev() { kira_system::mkswap(&part_l)?; @@ -127,6 +142,7 @@ pub struct InstallStage { progress_message: String, part_config: PartitionStageResult, modal_backgroud: Color, + k_config: KiraConfig, } #[derive(Debug, Clone)] @@ -146,27 +162,16 @@ pub enum Update { Task(Task), } -async fn init_disk_async(part_layout: PartLayout) -> Result<(f32, String), ExecCommandError> { +async fn init_disk_async(part_layout: PartLayout, mnt_dir: String) -> Result<(), ExecCommandError> { use blocking; - blocking::unblock(move || init_disk(&part_layout)).await?; - Ok((1.1f32, "Preparing bcachefs filesystem...".into())) -} - -async fn bcachefs_init_async( - dev_name: String, - compression: Option, - password: Option, - mnt_dir: String, -) -> Result<(f32, String), ExecCommandError> { - use blocking; - blocking::unblock(move || bcachefs_init(&dev_name, compression, password, &mnt_dir)).await?; - Ok((2.2f32, "Something next...".into())) + blocking::unblock(move || init_disk(&part_layout, &mnt_dir)).await } fn partition_disk( disk_layout: PartLayout, password: Option, compression: Option, + mnt_dir: String, ) -> impl futures::Stream> { use blocking; @@ -175,14 +180,25 @@ fn partition_disk( |mut output: Sender>| async move { //sleep(Duration::from_millis(10)).await; let disk_layout_cloned = disk_layout.clone(); + // creating gpt partition table - match output.send(init_disk_async(disk_layout_cloned).await).await { - Err(ex) => { - log::error!("Error creating GPT partition table: {}", ex.to_string()); - return; - } - _ => (), - }; + let res = init_disk_async(disk_layout_cloned, mnt_dir).await; + output + .send(res.map(|_| (1.1f32, "Formatting bcachefs".into()))) + .await + .unwrap(); + if res.is_err() { + return; + } + + let res = init_disk_async(disk_layout_cloned).await; + output + .send(res.map(|_| (1.1f32, "Formatting bcachefs".into()))) + .await + .unwrap(); + if res.is_err() { + return; + } // creating partitions let dev = disk_layout.dev.clone(); @@ -252,7 +268,7 @@ fn partition_disk( } impl InstallStage { - pub fn new(config: &KiraConfig) -> Self { + pub fn new(k_config: KiraConfig) -> Self { let mut modal_backgroud = kira_theming::main_theme().palette().background; modal_backgroud.a = 0.5; Self { @@ -260,19 +276,14 @@ impl InstallStage { state: InstallationState::UserConfirmDialog, progress: 0.0, progress_message: String::new(), - part_config: config - .config_trail - .iter() - .find_map(|v| match v { - StageResult::PartitionStageResult(res) => Some(res.clone()), - _ => None, - }) - .expect("Partition stage result should be present in KiraConfig!"), + part_config: k_config.res_partition.clone().expect("Partition stage result should be present in KiraConfig!"), + k_config: k_config, } } - fn gen_result(&self) -> StageResult { - StageResult::None + fn gen_result(&mut self) -> KiraConfig { + self.k_config.res_install = true; + self.k_config.clone() } pub fn update(&mut self, message: Message) -> Update { @@ -287,7 +298,8 @@ impl InstallStage { let disk_password = self.part_config.password.clone(); let disk_compression = Some("lz4".to_string()); Update::Task(Task::run( - partition_disk(disk_layout, disk_password, disk_compression).map_err(|ex|ex.to_string()), + partition_disk(disk_layout, disk_password, disk_compression) + .map_err(|ex| ex.to_string()), Message::UpdateProgress, )) //Update::Task(Task::perform(, Message::PartitioningFinish)) diff --git a/src/stages/keyboard/mod.rs b/src/stages/keyboard/mod.rs index deb2221..dc0c399 100644 --- a/src/stages/keyboard/mod.rs +++ b/src/stages/keyboard/mod.rs @@ -19,7 +19,7 @@ */ use crate::kira_scroll_list::{self, ListViewMessage}; -use crate::stage::{StageAction, StageResult}; +use crate::stage::{KiraConfig, StageAction}; use iced::{Alignment, Length, widget}; use log; use rust_i18n::t; @@ -119,9 +119,9 @@ pub struct KeyboardStage { variants_map: HashMap>, variants: Vec, variant: Option, - keyboard_layout: Option, // selected_kbd_layout_id: Option, + k_config: KiraConfig, } #[derive(Debug, Clone, PartialEq)] @@ -230,7 +230,7 @@ fn get_layouts_blocking() -> std::io::Result<( } impl KeyboardStage { - pub fn new() -> Self { + pub fn new(k_config: KiraConfig) -> Self { match get_layouts_blocking() { Ok((models, layouts, variants_map)) => { let def_layout = layouts @@ -258,6 +258,7 @@ impl KeyboardStage { layout: def_layout, variant: Some(0), keyboard_layout: keyboard_layout, + k_config: k_config, } } Err(ex) => { @@ -274,19 +275,21 @@ impl KeyboardStage { layout: None, variant: None, keyboard_layout: None, + k_config: k_config, } } } } - fn gen_result(&self) -> StageResult { - StageResult::KeyboardStageResult(KeyboardStageResult { + fn gen_result(&mut self) -> KiraConfig { + self.k_config.res_keyboard = Some(KeyboardStageResult { keyboard_model: self.model.clone().expect("Keyboard model must be choosed!"), keyboard_layout: self .keyboard_layout .clone() .expect("Keyboard layout must be choosed!"), - }) + }); + self.k_config.clone() } pub fn update(&mut self, message: Message) -> StageAction { diff --git a/src/stages/license/mod.rs b/src/stages/license/mod.rs index 6c9cea6..89cc2d7 100644 --- a/src/stages/license/mod.rs +++ b/src/stages/license/mod.rs @@ -23,10 +23,12 @@ use iced::{Alignment, widget}; use rust_i18n::t; use crate::stage; -use crate::stage::StageResult; +use crate::stage::KiraConfig; #[derive(Debug, Clone)] -pub struct LicenseStage {} +pub struct LicenseStage { + k_config: KiraConfig, +} #[derive(Debug, Clone)] pub enum Message { @@ -42,13 +44,18 @@ pub enum Message { //const LICENSE_TEXT: &str = include_str!("gpl-3.0.txt"); impl LicenseStage { - fn accepted() -> StageResult { - StageResult::None + pub fn new(k_config: KiraConfig) -> Self { + Self { k_config: k_config } + } + + fn accepted(&mut self) -> KiraConfig { + self.k_config.res_license = true; + self.k_config.clone() } pub fn update(&mut self, message: Message) -> stage::StageAction { match message { - Message::Accept => stage::StageAction::Next(Self::accepted()), + Message::Accept => stage::StageAction::Next(self.accepted()), Message::Back => stage::StageAction::Back, Message::Decline => stage::StageAction::Abort, } diff --git a/src/stages/locale/mod.rs b/src/stages/locale/mod.rs index 471dc4d..cc4983f 100644 --- a/src/stages/locale/mod.rs +++ b/src/stages/locale/mod.rs @@ -20,7 +20,7 @@ use crate::{ kira_theming, - stage::{KiraConfig, StageAction, StageResult}, + stage::{KiraConfig, StageAction}, }; use iced::{Alignment, widget}; use rust_i18n::t; @@ -136,6 +136,7 @@ pub struct LocaleStage { locales: Vec, lang_locale_text: String, all_locale_text: String, + k_config: KiraConfig, } #[derive(Debug, Clone, PartialEq)] @@ -153,12 +154,12 @@ pub enum Message { } impl LocaleStage { - pub fn new(kira_config: &KiraConfig) -> Self { + pub fn new(k_config: KiraConfig) -> Self { // get seelctet language code from welcome stage - let maybe_lang = kira_config.config_trail.iter().find_map(|v| match v { - StageResult::WelcomeStageResult(res) => Some(res.loc_code.clone()), - _ => None, - }); + let maybe_lang = k_config + .res_welcome + .as_ref() + .and_then(|rw| Some(rw.loc_code.clone())); let raw_loc_codes = get_locales_codes_list_blocking().unwrap(); let raw_loc_descr = get_locales_description_blocking().unwrap(); @@ -210,24 +211,26 @@ impl LocaleStage { locales: locales, lang_locale_text: lang_locale_text, all_locale_text: all_locale_text, + k_config: k_config, } } - fn gen_result(&self) -> StageResult { - if let Some(lang_locale) = &self.lang_locale + fn gen_result(&mut self) -> KiraConfig { + self.k_config.res_locale = if let Some(lang_locale) = &self.lang_locale && let Some(formats_locale) = &self.formats_locale { - StageResult::LocaleStageResult(LocaleStageResult { + Some(LocaleStageResult { lang_locale: lang_locale.clone(), formats_locale: formats_locale.clone(), }) } else { let loc = LocaleData::default(); - StageResult::LocaleStageResult(LocaleStageResult { + Some(LocaleStageResult { lang_locale: loc.clone(), formats_locale: loc, }) - } + }; + self.k_config.clone() } pub fn update(&mut self, message: Message) -> StageAction { diff --git a/src/stages/network/mod.rs b/src/stages/network/mod.rs index 765431c..44593f8 100644 --- a/src/stages/network/mod.rs +++ b/src/stages/network/mod.rs @@ -23,10 +23,10 @@ use iced::{Alignment, Task, widget}; use iced_moving_picture::widget::apng; use log; use rust_i18n::t; -use toml::Table; -use crate::stage; -use crate::stage::StageResult; +use crate::stage::{self, KiraConfig}; + +const REQIRE_NETWORK: bool = false; #[derive(Debug, Clone, PartialEq, Eq)] pub enum State { @@ -41,21 +41,21 @@ pub enum CheckResult { CheckError, } +#[derive(Debug, Clone, PartialEq)] +pub struct NetworkStageResult { + pub internet_active: bool, + pub use_net_settings: bool, +} + #[derive(Debug, Clone)] pub struct NetworkStage { internet_active: bool, state: State, use_net_settings: bool, - reqire_network: bool, spinner_frames: apng::Frames, logo_handle: widget::image::Handle, status_message: String, -} - -#[derive(Debug, Clone, PartialEq)] -pub struct NetworkStageResult { - pub internet_active: bool, - pub use_net_settings: bool, + k_config: KiraConfig, } #[derive(Debug, Clone)] @@ -100,21 +100,7 @@ async fn check_connected() -> CheckResult { } impl NetworkStage { - pub fn new(toml_config: &Table) -> Self { - let mut reqire_network = false; - - if let Some(reqire_network_conf) = toml_config - .get("network") - .and_then(|v| v.as_table()) - .and_then(|v| v.get("reqire_network")) - .and_then(|v| v.as_bool()) - { - log::debug!("Config value reqire_network read {}", reqire_network_conf); - reqire_network = reqire_network_conf; - } else { - log::error!("Error parsing network config. Using default values."); - } - + pub fn new(k_config: KiraConfig) -> Self { let spinner_frames = apng::Frames::from_bytes(crate::kira_theming::get_spiner_bytes()).unwrap(); @@ -125,17 +111,19 @@ impl NetworkStage { internet_active: false, state: State::Cheking, use_net_settings: true, - reqire_network: reqire_network, spinner_frames: spinner_frames, status_message: t!("network.checking").into(), + k_config: k_config, } } - fn gen_result(&self) -> StageResult { - StageResult::NetworkStageResult(NetworkStageResult { + fn gen_result(&self) -> KiraConfig { + let mut k_config = self.k_config.clone(); + k_config.res_network = Some(NetworkStageResult { internet_active: self.internet_active, use_net_settings: self.use_net_settings, - }) + }); + k_config } pub fn update(&mut self, message: Message) -> UpdateResult { @@ -176,7 +164,7 @@ impl NetworkStage { pub fn view(&self) -> iced::Element<'_, Message> { let next_button = - if (self.state == State::Cheking) || (!self.internet_active && self.reqire_network) { + if (self.state == State::Cheking) || (!self.internet_active && REQIRE_NETWORK) { widget::button(widget::text(t!("button.next"))) } else { widget::button(widget::text(t!("button.next"))).on_press(Message::Next) diff --git a/src/stages/partition/mod.rs b/src/stages/partition/mod.rs index ef28927..146640d 100644 --- a/src/stages/partition/mod.rs +++ b/src/stages/partition/mod.rs @@ -24,11 +24,13 @@ use crate::kira_color_bar; use crate::kira_disk_layout::{BlkDev, FSType, PartInfo, PartLayout}; use crate::kira_size::KiraSize; use crate::kira_sysinfo; -use crate::stage::{StageAction, StageResult}; +use crate::stage::{KiraConfig, StageAction}; use iced::{Alignment, Color, Element, Length, widget}; use log; use rust_i18n::t; -use toml::Table; + +const MIN_DISK_SIZE_MB: u64 = 8192; +const EFI_SIZE_MB: u64 = 128; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum SwapMode { @@ -69,7 +71,7 @@ fn part_type_to_color(t: &FSType) -> Color { } /// Converts PartInfo into data for ColorBar widget -/// +/// fn part_to_ct_params(part: &PartInfo, dev_size: KiraSize) -> (String, u16, Color) { let fill_ratio: u16 = ((part.size.b() as f32 / dev_size.b() as f32) * 11.0) as u16; let fill_ratio = fill_ratio.max(1); @@ -77,8 +79,6 @@ fn part_to_ct_params(part: &PartInfo, dev_size: KiraSize) -> (String, u16, Color (part.to_string(), fill_ratio, part_color) } - - #[derive(Debug, Clone, PartialEq)] pub struct PartitionStageResult { pub swap_mode: SwapMode, @@ -91,8 +91,6 @@ pub struct PartitionStageResult { pub part_layout: PartLayout, } - - #[derive(Debug, Clone)] pub struct PartitionStage { device: Option, @@ -110,10 +108,9 @@ pub struct PartitionStage { generated_part_layout: Option, system_ram_size: KiraSize, vram_of_all_gpus_size: KiraSize, + k_config: KiraConfig, } - - #[derive(Debug, Clone)] pub enum Message { SelectDevice(BlkDev), @@ -129,27 +126,12 @@ pub enum Message { } impl PartitionStage { - pub fn new(toml_config: &Table) -> Result { + pub fn new(k_config: KiraConfig) -> Result { let maybe_dev_list = BlkDev::list_sys_blk_dev(); log::info!("hiii from partition"); - let mut min_disk_size_mb = 8192; - let mut efi_size_mb = 128; - if let Some(part_table) = toml_config - .get("partition") - .and_then(|v| v.as_table()) { - min_disk_size_mb = part_table.get("min_disk_size_mb") - .and_then(|v| v.as_integer()) - .unwrap_or(8192); - - efi_size_mb = part_table.get("efi_size_mb") - .and_then(|v| v.as_integer()) - .unwrap_or(128); - - } - - let min_disk_size: KiraSize = KiraSize::new_mb(min_disk_size_mb.try_into().unwrap_or(8192)); - let efi_size: KiraSize = KiraSize::new_mb(efi_size_mb.try_into().unwrap_or(128)); + let min_disk_size: KiraSize = KiraSize::new_mb(MIN_DISK_SIZE_MB); + let efi_size: KiraSize = KiraSize::new_mb(EFI_SIZE_MB); let sec_boot_setup = match kira_sysinfo::get_secure_boot_status() { Ok(sb_status) => sb_status.setup_mode, @@ -192,9 +174,10 @@ impl PartitionStage { efi_size: efi_size, selected_disk_parts: None, generated_disk_parts: None, - generated_part_layout:None, + generated_part_layout: None, system_ram_size: system_ram_size, vram_of_all_gpus_size: vram_of_all_gpus_size, + k_config: k_config, }) } Err(ex) => Err(ex), @@ -240,8 +223,16 @@ impl PartitionStage { fn gen_layout(&mut self) { if let Some(dev) = self.device.clone() { let swap_size: KiraSize = self.get_swap_size(); - let patr_layout = PartLayout::gen_kira_layout(dev.clone(), self.efi_size, swap_size); - self.generated_disk_parts = Some(patr_layout.part_list + let patr_layout = PartLayout::gen_kira_layout( + dev.clone(), + self.efi_size, + swap_size, + None, + Some("lz4".into()), + ); + self.generated_disk_parts = Some( + patr_layout + .part_list .iter() .map(|part_info| part_to_ct_params(part_info, dev.size)) .collect(), @@ -250,14 +241,24 @@ impl PartitionStage { } } - fn gen_result(&self) -> StageResult { - let disk_layout = self.generated_part_layout.clone().expect("Layout must be generated!"); + fn gen_result(&mut self) -> KiraConfig { + let disk_layout = self + .generated_part_layout + .clone() + .expect("Layout must be generated!"); - StageResult::PartitionStageResult(PartitionStageResult { swap_mode: self.swap_mode.clone().unwrap(), - swap_size: self.get_swap_size(), efi_size: self.efi_size, - use_zram: self.use_zram, secure_boot: self.secure_boot, encrypt_drive: true, - password: Some("123456".to_string()), part_layout: disk_layout }) - + self.k_config.res_partition = Some(PartitionStageResult { + swap_mode: self.swap_mode.clone().unwrap(), + swap_size: self.get_swap_size(), + efi_size: self.efi_size, + use_zram: self.use_zram, + secure_boot: self.secure_boot, + encrypt_drive: true, + password: Some("123456".to_string()), + part_layout: disk_layout, + }); + + self.k_config.clone() } pub fn update(&mut self, message: Message) -> StageAction { @@ -290,25 +291,25 @@ impl PartitionStage { self.device = Some(dev); self.gen_layout(); StageAction::None - }, + } Message::SelectSwapMode(sm) => { self.swap_mode = Some(sm); self.gen_layout(); StageAction::None - }, + } Message::ToggleSecureBoot(t) => { self.secure_boot = t; StageAction::None - }, + } Message::ToggleEncrypDrive(t) => { self.encrypt_drive = t; StageAction::None - }, + } Message::ToggleZram(t) => { self.use_zram = t; self.gen_layout(); StageAction::None - }, + } Message::SwapSizeIncrement => { self.custom_swap_size_mb = (self.custom_swap_size_mb / 1024u32) .strict_mul(1024u32) @@ -316,7 +317,7 @@ impl PartitionStage { self.custom_swap_size_str = format!("{}MB", self.custom_swap_size_mb); self.gen_layout(); StageAction::None - }, + } Message::SwapSizeDecrement => { self.custom_swap_size_mb = (self.custom_swap_size_mb / 1024u32) .strict_mul(1024u32) @@ -324,7 +325,7 @@ impl PartitionStage { self.custom_swap_size_str = format!("{}MB", self.custom_swap_size_mb); self.gen_layout(); StageAction::None - }, + } Message::SwapSizeFieldChange(f_v) => { let mut only_num = f_v.trim().to_string(); only_num.retain(char::is_numeric); @@ -332,7 +333,7 @@ impl PartitionStage { self.custom_swap_size_str = format!("{}MB", self.custom_swap_size_mb); self.gen_layout(); StageAction::None - }, + } Message::Back => StageAction::Back, Message::Next => StageAction::Next(self.gen_result()), } @@ -374,10 +375,12 @@ impl PartitionStage { let selected_dev_content = widget::column![selected_dev_text, selected_dev_content]; let use_sec_boot_checkbox = if self.secure_boot_in_setup_mode { + widget::checkbox(self.secure_boot) + .label(t!("partition.use_secure_boot")) + .on_toggle(Message::ToggleSecureBoot) + } else { widget::checkbox(self.secure_boot).label(t!("partition.use_secure_boot")) - .on_toggle(Message::ToggleSecureBoot) - } - else {widget::checkbox(self.secure_boot).label(t!("partition.use_secure_boot"))}; + }; widget::column![ widget::container( diff --git a/src/stages/security/mod.rs b/src/stages/security/mod.rs index 98d26f8..a4392e0 100644 --- a/src/stages/security/mod.rs +++ b/src/stages/security/mod.rs @@ -18,7 +18,7 @@ This is Security stage, setup users logins and such */ -use crate::stage::{StageAction, StageResult}; +use crate::stage::{StageAction, KiraConfig}; use iced::{Alignment, Color, widget}; use rust_i18n::t; @@ -69,6 +69,7 @@ pub struct SecurityStage { root_pass_is_secure: bool, user_password_strenght: PasswordStrenght, root_password_strenght: PasswordStrenght, + k_config: KiraConfig, } #[derive(Debug, Clone)] @@ -101,7 +102,7 @@ fn retain_first_n(s: &str, n: usize) -> &str { } impl SecurityStage { - pub fn new() -> Self { + pub fn new(k_config: KiraConfig) -> Self { Self { user_name: "".into(), user_full_name: "".into(), @@ -112,16 +113,18 @@ impl SecurityStage { root_pass_is_secure: true, user_password_strenght: PasswordStrenght::Low, root_password_strenght: PasswordStrenght::Low, + k_config: k_config, } } - fn gen_result(&self) -> StageResult { - StageResult::SecurityStageResult(SecurityStageResult { + fn gen_result(&mut self) -> KiraConfig { + self.k_config.res_security = Some(SecurityStageResult { user_name: self.user_name.clone(), user_full_name: self.user_full_name.clone(), user_password: self.user_password.clone(), root_password: self.root_password.clone(), - }) + }); + self.k_config.clone() } pub fn update(&mut self, message: Message) -> StageAction { diff --git a/src/stages/timezone/mod.rs b/src/stages/timezone/mod.rs index c196fc4..8d9a7b1 100644 --- a/src/stages/timezone/mod.rs +++ b/src/stages/timezone/mod.rs @@ -18,7 +18,7 @@ This is TimeZone stage, used to select timezone */ -use crate::stage::{StageAction, StageResult}; +use crate::stage::{KiraConfig, StageAction}; use iced::{Alignment, Length, widget}; use log; use rust_i18n::t; @@ -58,6 +58,7 @@ pub struct TimeZoneStage { zone_id: Option, selected_zone: Option, selected_zone_text: String, + k_config: KiraConfig, } #[derive(Debug, Clone)] @@ -105,7 +106,7 @@ fn get_timezones_blocking() -> Result, String> { } impl TimeZoneStage { - pub fn new() -> Self { + pub fn new(k_config: KiraConfig) -> Self { match get_timezones_blocking() { Ok(time_zones_data_list) => { let mut time_zones_map: HashMap> = HashMap::new(); @@ -130,6 +131,7 @@ impl TimeZoneStage { zone_id: None, selected_zone: None, selected_zone_text: String::new(), + k_config: k_config, } } Err(ex) => { @@ -145,18 +147,20 @@ impl TimeZoneStage { zone_id: None, selected_zone: None, selected_zone_text: String::new(), + k_config: k_config, } } } } - fn gen_result(&self) -> StageResult { - StageResult::TimeZoneStageResult(TimeZoneStageResult { + fn gen_result(&mut self) -> KiraConfig { + self.k_config.res_timezone = Some(TimeZoneStageResult { time_zone: self .selected_zone .clone() .expect("Timezone must be selected!"), - }) + }); + self.k_config.clone() } pub fn update(&mut self, message: Message) -> StageAction { diff --git a/src/stages/welcome/mod.rs b/src/stages/welcome/mod.rs index adf2853..c619324 100644 --- a/src/stages/welcome/mod.rs +++ b/src/stages/welcome/mod.rs @@ -20,7 +20,7 @@ use crate::{ kira_theming, - stage::{StageAction, StageResult}, + stage::{KiraConfig, StageAction}, }; use iced::{Alignment, widget}; use rust_i18n::t; @@ -37,18 +37,19 @@ impl std::fmt::Display for LocData { } } -#[derive(Debug, Clone)] -pub struct WelcomeStage { - locale: Option, - locales: Vec, -} - #[derive(Debug, Clone, PartialEq)] pub struct WelcomeStageResult { pub loc_code: String, pub loc_name: String, } +#[derive(Debug, Clone)] +pub struct WelcomeStage { + locale: Option, + locales: Vec, + k_config: KiraConfig, +} + #[derive(Debug, Clone)] pub enum Message { SelectLocale(LocData), @@ -57,7 +58,7 @@ pub enum Message { } impl WelcomeStage { - pub fn new() -> Self { + pub fn new(k_config: KiraConfig) -> Self { Self { locale: Some(LocData { name: "English".into(), @@ -70,21 +71,23 @@ impl WelcomeStage { code: s.to_string(), }) .collect(), + k_config: k_config, } } - fn gen_result(&self) -> StageResult { - if let Some(loc) = &self.locale { - StageResult::WelcomeStageResult(WelcomeStageResult { + fn gen_result(&mut self) -> KiraConfig { + self.k_config.res_welcome = Some(if let Some(loc) = &self.locale { + WelcomeStageResult { loc_code: loc.code.clone(), loc_name: loc.name.clone(), - }) + } } else { - StageResult::WelcomeStageResult(WelcomeStageResult { + WelcomeStageResult { loc_code: "en".to_string(), loc_name: "English".to_string(), - }) - } + } + }); + self.k_config.clone() } pub fn update(&mut self, message: Message) -> StageAction {