Use buffers instead of temp files

This commit is contained in:
Ward from fusion-voyager-3 2024-08-14 00:13:09 +03:00
parent ceb4fc3a50
commit cdc1ca25ae
4 changed files with 18 additions and 53 deletions

View File

@ -49,15 +49,20 @@ pub fn build_ui(app: &adw::Application) {
_ => efi_error_page::efi_error_page(&window, &carousel)
}
let language_selection_text_buffer = gtk::TextBuffer::builder().build();
let keymap_base_selection_text_buffer = gtk::TextBuffer::builder().build();
let keymap_varient_selection_text_buffer = gtk::TextBuffer::builder().build();
let timezone_selection_text_buffer = gtk::TextBuffer::builder().build();
let language_changed_action = gio::SimpleAction::new("lang-changed", None);
language_page::language_page(&carousel, &language_changed_action);
language_page::language_page(&carousel, &language_selection_text_buffer, &language_changed_action);
eula_page::eula_page(&carousel, &language_changed_action);
keyboard_page::keyboard_page(&carousel, &language_changed_action);
keyboard_page::keyboard_page(&carousel, &keymap_base_selection_text_buffer, &keymap_varient_selection_text_buffer, &language_changed_action);
timezone_page::timezone_page(&carousel, &language_changed_action);
timezone_page::timezone_page(&carousel, &timezone_selection_text_buffer, &language_changed_action);
partitioning_page::partitioning_page(&carousel, &language_changed_action);

View File

@ -7,6 +7,8 @@ use std::{process::Command, fs, path::Path};
pub fn keyboard_page(
main_carousel: &adw::Carousel,
keymap_base_data_buffer: &gtk::TextBuffer,
keymap_variant_data_buffer: &gtk::TextBuffer,
language_changed_action: &gio::SimpleAction
) {
let keyboard_page = installer_stack_page::InstallerStackPage::new();
@ -70,12 +72,8 @@ pub fn keyboard_page(
let keymap_list = gnome_desktop::XkbInfo::all_layouts(&xkbinfo);
let keymap_base_data_buffer = gtk::TextBuffer::builder().build();
let keymap_base_data_buffer_clone0 = keymap_base_data_buffer.clone();
let keymap_variant_data_buffer = gtk::TextBuffer::builder().build();
let keymap_variant_data_buffer_clone0 = keymap_variant_data_buffer.clone();
for keymap in keymap_list.iter() {
@ -222,35 +220,6 @@ pub fn keyboard_page(
main_carousel,
move |_keyboard_page: installer_stack_page::InstallerStackPage|
{
if Path::new("/tmp/pika-installer-gtk4-keyboard-base.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-keyboard-base.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-keyboard-base.txt");
}
let base_data_text = keymap_base_data_buffer_clone0
.text(
&keymap_base_data_buffer_clone0.bounds().0,
&keymap_base_data_buffer_clone0.bounds().1,
true
)
.to_string();
fs::write(
"/tmp/pika-installer-gtk4-keyboard-base.txt",
base_data_text
).expect("Unable to write file");
if Path::new("/tmp/pika-installer-gtk4-keyboard-variant.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-keyboard-variant.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-keyboard-variant.txt");
}
let varient_data_text = keymap_variant_data_buffer_clone0
.text(
&keymap_variant_data_buffer_clone0.bounds().0,
&keymap_variant_data_buffer_clone0.bounds().1,
true
).to_string();
if !varient_data_text.is_empty() {
fs::write(
"/tmp/pika-installer-gtk4-keyboard-variant.txt",
varient_data_text
).expect("Unable to write file");
}
main_carousel.scroll_to(&main_carousel.nth_page(4), true)
}
)

View File

@ -6,6 +6,7 @@ use std::{process::Command, env, fs, path::Path};
pub fn language_page(
main_carousel: &adw::Carousel,
lang_data_buffer: &gtk::TextBuffer,
language_changed_action: &gio::SimpleAction
) {
let language_page = installer_stack_page::InstallerStackPage::new();
@ -222,8 +223,6 @@ pub fn language_page(
"pt_BR",
"pt_PT",];
let lang_data_buffer = gtk::TextBuffer::builder().build();
let lang_data_buffer_clone0 = lang_data_buffer.clone();
for locale in locale_list.iter() {
@ -323,16 +322,12 @@ pub fn language_page(
language_changed_action,
move |_language_page: installer_stack_page::InstallerStackPage|
{
if Path::new("/tmp/pika-installer-gtk4-lang.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-lang.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-lang.txt");
}
fs::write("/tmp/pika-installer-gtk4-lang.txt", lang_data_buffer_clone0.text(&lang_data_buffer_clone0.bounds().0, &lang_data_buffer_clone0.bounds().1, true).to_string()).expect("Unable to write file");
//Command::new("sudo")
// .arg("localectl")
// .arg("set-locale")
// .arg("LANG=".to_owned() + &lang_data_buffer_clone0.text(&lang_data_buffer_clone0.bounds().0, &lang_data_buffer_clone0.bounds().1, true).to_string() + ".UTF-8")
// .spawn()
// .expect("locale failed to start");
//Command::new("sudo")
// .arg("localectl")
// .arg("set-locale")
// .arg("LANG=".to_owned() + &lang_data_buffer_clone0.text(&lang_data_buffer_clone0.bounds().0, &lang_data_buffer_clone0.bounds().1, true).to_string() + ".UTF-8")
// .spawn()
// .expect("locale failed to start");
rust_i18n::set_locale(&lang_data_buffer_clone0.text(&lang_data_buffer_clone0.bounds().0, &lang_data_buffer_clone0.bounds().1, true).to_string());
language_changed_action.activate(None);
main_carousel.scroll_to(&main_carousel.nth_page(2), true)

View File

@ -7,6 +7,7 @@ use std::io::BufRead;
pub fn timezone_page(
main_carousel: &adw::Carousel,
timezone_data_buffer: &gtk::TextBuffer,
language_changed_action: &gio::SimpleAction
) {
let timezone_page = installer_stack_page::InstallerStackPage::new();
@ -73,7 +74,6 @@ pub fn timezone_page(
let timezone_stdout = timezone_cli.stdout.expect("could not get stdout");
let timezone_reader = std::io::BufReader::new(timezone_stdout);
let timezone_data_buffer = gtk::TextBuffer::builder().build();
let timezone_data_buffer_clone0 = timezone_data_buffer.clone();
for timezone in timezone_reader.lines() {
@ -186,10 +186,6 @@ pub fn timezone_page(
move |_timezone_page: installer_stack_page::InstallerStackPage|
{
let timezone_selection = timezone_data_buffer_clone0.text(&timezone_data_buffer_clone0.bounds().0, &timezone_data_buffer_clone0.bounds().1, true).to_string();
if Path::new("/tmp/pika-installer-gtk4-timezone.txt").exists() {
fs::remove_file("/tmp/pika-installer-gtk4-timezone.txt").expect("Bad permissions on /tmp/pika-installer-gtk4-timezone.txt");
}
fs::write("/tmp/pika-installer-gtk4-timezone.txt", &timezone_selection).expect("Unable to write file");
Command::new("sudo")
.arg("timedatectl")
.arg("set-timezone")