Skip to content

Commit cba410b

Browse files
committed
feat(pages/installationtype): tpm checkbox
1 parent 2886a10 commit cba410b

2 files changed

Lines changed: 40 additions & 30 deletions

File tree

‎src/backend/install.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub struct InstallationState {
4747
pub mounttags: Option<crate::backend::custom::MountTargets>,
4848
pub postinstall: Vec<crate::backend::postinstall::Module>,
4949
pub encrypt: bool,
50+
pub tpm: bool,
5051
}
5152

5253
// TODO: remove this after have support for anything other than chromebook
@@ -326,12 +327,14 @@ impl InstallationState {
326327
})
327328
}
328329

329-
fn set_encrypt_to_file(f: &str) -> String {
330+
fn set_encrypt_to_file(f: &str, tpm: bool) -> String {
330331
let mut f = serde_systemd_unit::parse(f).expect("cannot parse templates");
331-
f.sections.get_mut("Partition").unwrap().insert(
332-
"Encrypt".to_owned(),
333-
serde_systemd_unit::Value::String("key-file".to_owned()),
334-
);
332+
let mut v = "key-file".to_owned();
333+
if tpm {
334+
v += "+tpm2";
335+
}
336+
(f.sections.get_mut("Partition").unwrap())
337+
.insert("Encrypt".to_owned(), serde_systemd_unit::Value::String(v));
335338
f.to_string()
336339
}
337340

@@ -343,7 +346,7 @@ impl InstallationState {
343346
}
344347
let root_file = cfgdir.join("50-root.conf");
345348
let f = std::fs::read_to_string(&root_file)?;
346-
let f = Self::set_encrypt_to_file(&f);
349+
let f = Self::set_encrypt_to_file(&f, self.tpm);
347350
std::fs::write(root_file, f)?;
348351
Ok(())
349352
}
@@ -434,7 +437,7 @@ mod tests {
434437
#[test]
435438
fn test_set_encrypt_to_file() {
436439
assert_eq!(
437-
super::InstallationState::set_encrypt_to_file("[Partition]\nType=root"),
440+
super::InstallationState::set_encrypt_to_file("[Partition]\nType=root", false),
438441
"[Partition]\nType=\"root\"\nEncrypt=\"key-file\"\n"
439442
);
440443
}

‎src/pages/installationtype.rs‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub enum InstallationTypePageMsg {
1313
#[doc(hidden)]
1414
Navigate(NavigationAction),
1515
InstallationTypeSelected(InstallationType),
16+
Next,
1617
}
1718

1819
#[derive(Debug)]
@@ -115,6 +116,12 @@ impl SimpleComponent for InstallationTypePage {
115116
set_sensitive: model.can_encrypt,
116117
connect_toggled => |btn| INSTALLATION_STATE.write().encrypt = btn.is_active(),
117118
},
119+
gtk::CheckButton {
120+
set_label: Some(&gettext("Enable TPM")),
121+
#[watch]
122+
set_sensitive: INSTALLATION_STATE.read().encrypt && model.can_encrypt,
123+
connect_toggled => |btn| INSTALLATION_STATE.write().tpm = btn.is_active(),
124+
},
118125
},
119126

120127
gtk::Box {
@@ -128,8 +135,14 @@ impl SimpleComponent for InstallationTypePage {
128135
connect_clicked => InstallationTypePageMsg::Navigate(NavigationAction::GoTo(crate::Page::Destination))
129136
},
130137

131-
gtk::Box {
132-
set_hexpand: true,
138+
libhelium::Button {
139+
set_is_pill: true,
140+
#[watch]
141+
set_label: &gettext("Next"),
142+
add_css_class: "large-button",
143+
connect_clicked => InstallationTypePageMsg::Next,
144+
#[watch]
145+
set_sensitive: crate::INSTALLATION_STATE.read().installation_type.is_some(),
133146
}
134147
}
135148
}
@@ -154,46 +167,40 @@ impl SimpleComponent for InstallationTypePage {
154167
match message {
155168
InstallationTypePageMsg::InstallationTypeSelected(InstallationType::WholeDisk) => {
156169
INSTALLATION_STATE.write().installation_type = Some(InstallationType::WholeDisk);
157-
sender
158-
.output(InstallationTypePageOutput::Navigate(
159-
NavigationAction::GoTo(Page::Confirmation),
160-
))
161-
.unwrap();
162170
self.can_encrypt = true;
171+
INSTALLATION_STATE.write().encrypt = true;
163172
}
164173
InstallationTypePageMsg::InstallationTypeSelected(InstallationType::DualBoot(_)) => {
165-
sender
166-
.output(InstallationTypePageOutput::Navigate(
167-
NavigationAction::GoTo(Page::InstallDual),
168-
))
169-
.unwrap();
170174
self.can_encrypt = true;
175+
INSTALLATION_STATE.write().encrypt = true;
171176
}
172177
InstallationTypePageMsg::InstallationTypeSelected(InstallationType::Custom) => {
173178
INSTALLATION_STATE.write().installation_type = Some(InstallationType::Custom);
174-
sender
175-
.output(InstallationTypePageOutput::Navigate(
176-
NavigationAction::GoTo(Page::InstallCustom),
177-
))
178-
.unwrap();
179179
self.can_encrypt = false;
180+
INSTALLATION_STATE.write().encrypt = false;
180181
}
181182
InstallationTypePageMsg::InstallationTypeSelected(
182183
InstallationType::ChromebookInstall,
183184
) => {
184185
INSTALLATION_STATE.write().installation_type =
185186
Some(InstallationType::ChromebookInstall);
186-
sender
187-
.output(InstallationTypePageOutput::Navigate(
188-
NavigationAction::GoTo(Page::Confirmation),
189-
))
190-
.unwrap();
187+
INSTALLATION_STATE.write().encrypt = true;
191188
self.can_encrypt = true;
192189
}
193190
InstallationTypePageMsg::Navigate(action) => sender
194191
.output(InstallationTypePageOutput::Navigate(action))
195192
.unwrap(),
196-
InstallationTypePageMsg::Update => {}
193+
InstallationTypePageMsg::Next => {
194+
sender.input(InstallationTypePageMsg::Navigate(NavigationAction::GoTo(
195+
match INSTALLATION_STATE.read().installation_type.unwrap() {
196+
InstallationType::WholeDisk => Page::Confirmation,
197+
InstallationType::DualBoot(_) => Page::InstallDual,
198+
InstallationType::ChromebookInstall => Page::Confirmation,
199+
InstallationType::Custom => Page::InstallCustom,
200+
},
201+
)))
202+
}
203+
InstallationTypePageMsg::Update => {},
197204
}
198205
}
199206
}

0 commit comments

Comments
 (0)