Update
This commit is contained in:
parent
26817b0e3c
commit
3622c75567
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["Valeria Fadeeva <valeria@fadeeva.me>"]
|
authors = ["Valeria Fadeeva <valeria@fadeeva.me>"]
|
||||||
name = "arch-linux-updater"
|
name = "melawy-linux-updater"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -10,6 +10,6 @@ edition = "2021"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
fltk = { version = "1.5", features = ["fltk-bundled"] }
|
fltk = { version = "1.5", features = ["fltk-bundled"] }
|
||||||
fltk-theme = "0.7"
|
fltk-theme = "0.7"
|
||||||
tokio = { version = "1.42", features = ["full"] }
|
tokio = { version = "^1", features = ["full"] }
|
||||||
# bytes = "1.9"
|
# bytes = "1.9"
|
||||||
dotenv = "0.15"
|
dotenv = "0.15"
|
||||||
|
|
60
src/main.rs
60
src/main.rs
|
@ -2,20 +2,22 @@
|
||||||
|
|
||||||
extern crate dotenv;
|
extern crate dotenv;
|
||||||
|
|
||||||
use fltk::{prelude::*, app, terminal::Terminal, enums::Color, frame, window, /*button,*/ image};
|
use fltk::{app, enums::Color, frame, /*button,*/ image, prelude::*, terminal::Terminal, window,};
|
||||||
use fltk_theme::{/*ColorTheme, color_themes, widget_themes, */WidgetTheme, ThemeType, WidgetScheme, SchemeType};
|
use fltk_theme::{
|
||||||
|
SchemeType, ThemeType, WidgetScheme,
|
||||||
|
/*ColorTheme, color_themes, widget_themes, */ WidgetTheme,
|
||||||
|
};
|
||||||
|
|
||||||
use tokio::io::{self, BufReader, AsyncBufReadExt};
|
use tokio::io::{self, AsyncBufReadExt, BufReader};
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::process::Stdio;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::process::Stdio;
|
||||||
|
|
||||||
async fn run_process() -> tokio::process::Child {
|
async fn run_process() -> tokio::process::Child {
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
let env_path = Path::new("/etc/arch-linux-updater/.env");
|
let env_path = Path::new("/etc/melawy-linux-updater/.env");
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
let env_path = Path::new(".env_debug");
|
let env_path = Path::new(".env_debug");
|
||||||
|
@ -31,48 +33,47 @@ async fn run_process() -> tokio::process::Child {
|
||||||
println!("{cmd_line} {par}");
|
println!("{cmd_line} {par}");
|
||||||
|
|
||||||
let child: tokio::process::Child = Command::new(cmd_line)
|
let child: tokio::process::Child = Command::new(cmd_line)
|
||||||
.args(v)
|
.args(v)
|
||||||
.stderr(Stdio::piped()) // don't care about stderr
|
.stderr(Stdio::piped()) // don't care about stderr
|
||||||
.stdout(Stdio::piped()) // set up stdout so we can read it
|
.stdout(Stdio::piped()) // set up stdout so we can read it
|
||||||
.stdin(Stdio::piped()) // set up stdin so we can write on it
|
.stdin(Stdio::piped()) // set up stdin so we can write on it
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("Could not run the command"); // finally run the command
|
.expect("Could not run the command"); // finally run the command
|
||||||
|
|
||||||
child
|
child
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_stdout() -> tokio::process::ChildStdout {
|
async fn get_stdout() -> tokio::process::ChildStdout {
|
||||||
let mut child: tokio::process::Child = run_process().await;
|
let mut child: tokio::process::Child = run_process().await;
|
||||||
|
|
||||||
let stdout: tokio::process::ChildStdout = child.stdout.take()
|
let stdout: tokio::process::ChildStdout = child
|
||||||
|
.stdout
|
||||||
|
.take()
|
||||||
.expect("child did not have a handle to stdout");
|
.expect("child did not have a handle to stdout");
|
||||||
|
|
||||||
stdout
|
stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_buffer() -> BufReader<tokio::process::ChildStdout> {
|
async fn get_buffer() -> BufReader<tokio::process::ChildStdout> {
|
||||||
let buffer: BufReader<tokio::process::ChildStdout> = BufReader::new(get_stdout().await);
|
let buffer: BufReader<tokio::process::ChildStdout> = BufReader::new(get_stdout().await);
|
||||||
|
|
||||||
buffer
|
buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn get_lines() -> io::Lines<BufReader<tokio::process::ChildStdout>> {
|
async fn get_lines() -> io::Lines<BufReader<tokio::process::ChildStdout>> {
|
||||||
let lines: io::Lines<BufReader<tokio::process::ChildStdout>> = get_buffer().await.lines();
|
let lines: io::Lines<BufReader<tokio::process::ChildStdout>> = get_buffer().await.lines();
|
||||||
|
|
||||||
lines
|
lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_line(
|
||||||
async fn get_line(lines: &mut io::Lines<BufReader<tokio::process::ChildStdout>>) -> io::Result<Option<String>> {
|
lines: &mut io::Lines<BufReader<tokio::process::ChildStdout>>,
|
||||||
|
) -> io::Result<Option<String>> {
|
||||||
let line: Result<Option<String>, io::Error> = lines.next_line().await;
|
let line: Result<Option<String>, io::Error> = lines.next_line().await;
|
||||||
|
|
||||||
line
|
line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn gui() -> io::Result<()> {
|
async fn gui() -> io::Result<()> {
|
||||||
let width = 1100;
|
let width = 1100;
|
||||||
let height = 700;
|
let height = 700;
|
||||||
|
@ -89,23 +90,22 @@ async fn gui() -> io::Result<()> {
|
||||||
let mut wind: fltk::window::DoubleWindow = window::Window::default()
|
let mut wind: fltk::window::DoubleWindow = window::Window::default()
|
||||||
.with_size(width, height)
|
.with_size(width, height)
|
||||||
.center_screen()
|
.center_screen()
|
||||||
.with_label("Arch Linux Updater");
|
.with_label("Melawy Linux Updater");
|
||||||
|
|
||||||
// let image = image::PngImage::load("assets/icons/Melawy.png").unwrap();
|
let image =
|
||||||
// let image = image::PngImage::load("/usr/share/arch-linux-updater/assets/icons/Melawy.png").unwrap();
|
image::SvgImage::load("/usr/share/melawy-linux-updater/assets/icons/Melawy.svg").unwrap();
|
||||||
let image = image::SvgImage::load("/usr/share/arch-linux-updater/assets/icons/Melawy.svg").unwrap();
|
|
||||||
// let image = image::PngImage::load(&std::path::Path::new("assets/icons/Melawy.png")).unwrap();
|
|
||||||
wind.set_icon(Some(image));
|
wind.set_icon(Some(image));
|
||||||
|
|
||||||
let frame = frame::Frame::default_fill()
|
let frame = frame::Frame::default_fill()
|
||||||
.with_size(width, height)
|
.with_size(width, height)
|
||||||
.center_of(&wind);
|
.center_of(&wind);
|
||||||
|
|
||||||
let mut terminal: Terminal = Terminal::default_fill()
|
let mut term: Terminal = Terminal::default_fill()
|
||||||
.with_size(width, height)
|
.with_size(width, height)
|
||||||
.center_of(&frame);
|
.center_of(&frame);
|
||||||
terminal.set_color(Color::Background2);
|
term.set_color(Color::Background2);
|
||||||
terminal.set_text_color(Color::Light2);
|
term.set_text_color(Color::Light2);
|
||||||
|
term.set_history_rows(5000);
|
||||||
|
|
||||||
wind.make_resizable(true);
|
wind.make_resizable(true);
|
||||||
wind.end();
|
wind.end();
|
||||||
|
@ -115,11 +115,10 @@ async fn gui() -> io::Result<()> {
|
||||||
|
|
||||||
let mut lines: io::Lines<BufReader<tokio::process::ChildStdout>> = get_lines().await;
|
let mut lines: io::Lines<BufReader<tokio::process::ChildStdout>> = get_lines().await;
|
||||||
|
|
||||||
|
|
||||||
// app.run().unwrap();
|
// app.run().unwrap();
|
||||||
while app.wait() {
|
while app.wait() {
|
||||||
if let Some(line) = get_line(&mut lines).await? {
|
if let Some(line) = get_line(&mut lines).await? {
|
||||||
terminal.append(format!("{}\n", line).as_str());
|
term.append(format!("{}\n", line).as_str());
|
||||||
} else {
|
} else {
|
||||||
if printed_close_msg == false {
|
if printed_close_msg == false {
|
||||||
let lang_key = "LANG";
|
let lang_key = "LANG";
|
||||||
|
@ -135,7 +134,7 @@ async fn gui() -> io::Result<()> {
|
||||||
"Now this window may close"
|
"Now this window may close"
|
||||||
};
|
};
|
||||||
|
|
||||||
terminal.append(format!("\n{}\n", text_to_close).as_str());
|
term.append(format!("\n{}\n", text_to_close).as_str());
|
||||||
printed_close_msg = true;
|
printed_close_msg = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +143,6 @@ async fn gui() -> io::Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> io::Result<()> {
|
async fn main() -> io::Result<()> {
|
||||||
gui().await
|
gui().await
|
||||||
|
|
Loading…
Reference in New Issue