modular socket
This commit is contained in:
parent
796dfcf188
commit
474f633b31
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/project-leoali.iml" filepath="$PROJECT_DIR$/.idea/project-leoali.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
11
.idea/project-leoali.iml
Normal file
11
.idea/project-leoali.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="EMPTY_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
2126
Cargo.lock
generated
Normal file
2126
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
31
Cargo.toml
Normal file
31
Cargo.toml
Normal file
@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "project-leoali"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
[[bin]]
|
||||
name = "gui"
|
||||
path = "src/gui/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "debug_server"
|
||||
path = "src/debug_server/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "apt_update"
|
||||
path = "src/apt_update/main.rs"
|
||||
|
||||
[dependencies]
|
||||
adw = { version = "0.5.3", package = "libadwaita", features = ["v1_4"] }
|
||||
gtk = { version = "0.7.3", package = "gtk4", features = ["v4_12"] }
|
||||
async-channel = "2.1.1"
|
||||
rust-i18n = "3.0.1"
|
||||
rust-apt = { git = "https://gitlab.com/volian/rust-apt" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
tokio-uds = "0.2"
|
||||
serde = { version = "1.0.203", features = ["derive"] }
|
||||
serde_json = "1.0.118"
|
||||
async-trait = "0.1.80"
|
||||
futures = "0.3.30"
|
||||
glib = "0.19.8"
|
@ -10,10 +10,6 @@ use rust_apt::raw::{AcqTextStatus, ItemDesc, ItemState, PkgAcquire};
|
||||
use std::thread;
|
||||
use tokio::runtime::Runtime;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
#[derive(Serialize)]
|
||||
struct AptSendablePackage {
|
||||
@ -22,25 +18,27 @@ struct AptSendablePackage {
|
||||
installed_version: String,
|
||||
candidate_version: String
|
||||
}
|
||||
pub struct AptUpdateProgressSocket {
|
||||
pub struct AptUpdateProgressSocket<'a> {
|
||||
pulse_interval: usize,
|
||||
max: usize,
|
||||
progress: f32
|
||||
progress: f32,
|
||||
socket_path: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> AptUpdateProgressSocket {
|
||||
impl<'a> AptUpdateProgressSocket<'a> {
|
||||
/// Returns a new default progress instance.
|
||||
pub fn new() -> Self {
|
||||
pub fn new(socket_path: &'a str) -> Self {
|
||||
let mut progress = Self {
|
||||
pulse_interval: 0,
|
||||
max: 0,
|
||||
progress: 0.0,
|
||||
socket_path: socket_path
|
||||
};
|
||||
progress
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> DynAcquireProgress for AptUpdateProgressSocket {
|
||||
impl<'a> DynAcquireProgress for AptUpdateProgressSocket<'a> {
|
||||
/// Used to send the pulse interval to the apt progress class.
|
||||
///
|
||||
/// Pulse Interval is in microseconds.
|
||||
@ -107,22 +105,19 @@ impl<'a> DynAcquireProgress for AptUpdateProgressSocket {
|
||||
/// meter along with an overall bandwidth and ETA indicator.
|
||||
fn pulse(&mut self, status: &AcqTextStatus, owner: &PkgAcquire) {
|
||||
let progress_percent: f32 = (status.current_bytes() as f32 * 100.0) / status.total_bytes() as f32;
|
||||
Runtime::new().unwrap().block_on(send_update_progress(progress_percent));
|
||||
Runtime::new().unwrap().block_on(send_progress_percent(progress_percent, self.socket_path));
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let update_cache = new_cache!().unwrap();
|
||||
match update_cache.update(&mut AcquireProgress::new(AptUpdateProgressSocket::new())) {
|
||||
match update_cache.update(&mut AcquireProgress::new(AptUpdateProgressSocket::new("/tmp/pika_apt_update.sock"))) {
|
||||
Ok(_) => {}
|
||||
Err(e) => panic!("{}", e.to_string())
|
||||
};
|
||||
}
|
||||
|
||||
async fn send_update_progress(progress_f32: f32) {
|
||||
// Path to the Unix socket file
|
||||
let socket_path = "/tmp/pika_apt_update.sock";
|
||||
|
||||
async fn send_progress_percent(progress_f32: f32, socket_path: &str) {
|
||||
// Connect to the Unix socket
|
||||
let mut stream = UnixStream::connect(socket_path).await.expect("Could not connect to server");
|
||||
|
||||
|
10
src/gui/apt_update_page/mod.rs
Normal file
10
src/gui/apt_update_page/mod.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use rust_apt::*;
|
||||
use rust_apt::cache::*;
|
||||
use rust_apt::new_cache;
|
||||
pub fn apt_update_page() {
|
||||
let cache = match new_cache!() {
|
||||
Ok(t) => t,
|
||||
Err(_) => panic!("APT CACHE FAIL")
|
||||
};
|
||||
let sort = PackageSort::default().upgradable().names();
|
||||
}
|
34
src/gui/build_ui/mod.rs
Normal file
34
src/gui/build_ui/mod.rs
Normal file
@ -0,0 +1,34 @@
|
||||
use adw::prelude::*;
|
||||
use adw::*;
|
||||
use crate::apt_update_page;
|
||||
use crate::apt_update_page::apt_update_page;
|
||||
use crate::config::{APP_ICON, APP_ID};
|
||||
|
||||
pub fn build_ui(app: &adw::Application) {
|
||||
// setup glib
|
||||
gtk::glib::set_prgname(Some(t!("app_name").to_string()));
|
||||
glib::set_application_name(&t!("app_name").to_string());
|
||||
|
||||
// create the main Application window
|
||||
let window = adw::ApplicationWindow::builder()
|
||||
// The text on the titlebar
|
||||
.title(t!("app_name"))
|
||||
// link it to the application "app"
|
||||
.application(app)
|
||||
// Add the box called "window_box" to it
|
||||
// Application icon
|
||||
.icon_name(APP_ICON)
|
||||
// Minimum Size/Default
|
||||
.width_request(700)
|
||||
.height_request(500)
|
||||
.deletable(false)
|
||||
// Startup
|
||||
.startup_id(APP_ID)
|
||||
// build the window
|
||||
.build();
|
||||
|
||||
apt_update_page::apt_update_page();
|
||||
|
||||
// show the window
|
||||
window.present()
|
||||
}
|
5
src/gui/config.rs
Normal file
5
src/gui/config.rs
Normal file
@ -0,0 +1,5 @@
|
||||
pub const APP_ID: &str = "com.github.pikaos-linux.pikafirstsetup";
|
||||
pub const DISTRO_ICON: &str = "pika-logo";
|
||||
//pub const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||
pub const APP_ICON: &str = "com.github.pikaos-linux.pikawelcome";
|
||||
//pub const APP_GITHUB: &str = "https://github.com/PikaOS-Linux/pkg-pika-welcome";
|
0
src/gui/style.css
Normal file
0
src/gui/style.css
Normal file
Loading…
Reference in New Issue
Block a user