mirror of
https://github.com/ilya-zlobintsev/LACT.git
synced 2026-08-19 01:14:43 -05:00
feat: add css loader (#891)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn main() {
|
||||
generate_combined_css();
|
||||
}
|
||||
|
||||
fn generate_combined_css() {
|
||||
let out_dir = env::var_os("OUT_DIR").unwrap();
|
||||
let dest_path = Path::new(&out_dir).join("combined.css");
|
||||
|
||||
let mut css_files = Vec::new();
|
||||
collect_css_files(Path::new("src"), &mut css_files);
|
||||
|
||||
// Sort files to ensure deterministic output
|
||||
css_files.sort();
|
||||
|
||||
let mut combined_css = String::new();
|
||||
for file in css_files {
|
||||
let content = fs::read_to_string(&file).expect("Could not read CSS file");
|
||||
combined_css.push_str(&format!("/* Source: {} */\n", file.display()));
|
||||
combined_css.push_str(&content);
|
||||
combined_css.push('\n');
|
||||
|
||||
println!("cargo:rerun-if-changed={}", file.display());
|
||||
}
|
||||
|
||||
fs::write(dest_path, combined_css).expect("Could not write combined CSS file");
|
||||
}
|
||||
|
||||
fn collect_css_files(dir: &Path, files: &mut Vec<PathBuf>) {
|
||||
if let Ok(entries) = fs::read_dir(dir) {
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
collect_css_files(&path, files);
|
||||
} else if path.extension().and_then(|s| s.to_str()) == Some("css") {
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/* currently used for tests */
|
||||
.app {
|
||||
|
||||
}
|
||||
+2
-3
@@ -11,6 +11,7 @@ mod overdrive_dialog;
|
||||
mod page_section;
|
||||
pub(crate) mod pages;
|
||||
mod process_monitor;
|
||||
pub(crate) mod styles;
|
||||
|
||||
use crate::{
|
||||
APP_ID, CONFIG, GUI_VERSION, I18N,
|
||||
@@ -187,9 +188,7 @@ impl AsyncComponent for AppModel {
|
||||
root: Self::Root,
|
||||
sender: AsyncComponentSender<Self>,
|
||||
) -> AsyncComponentParts<Self> {
|
||||
if !cfg!(feature = "adw") {
|
||||
relm4::set_global_css(include_str!("../res/style.css"));
|
||||
}
|
||||
relm4::set_global_css(styles::COMBINED_CSS);
|
||||
|
||||
let (daemon_client, conn_err) = match args.tcp_address {
|
||||
Some(remote_addr) => {
|
||||
|
||||
@@ -5,8 +5,4 @@
|
||||
|
||||
.clickable-info-row:hover {
|
||||
background-color: rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.page-section-content {
|
||||
border-radius: 5px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
.page-section-content {
|
||||
border-radius: 5px;
|
||||
}
|
||||
@@ -95,11 +95,7 @@ mod imp {
|
||||
#[local_ref]
|
||||
append = content_box {
|
||||
set_orientation: gtk::Orientation::Vertical,
|
||||
add_css_class: if cfg!(feature = "adw") {
|
||||
css::CARD
|
||||
} else {
|
||||
"page-section-content"
|
||||
},
|
||||
add_css_class: if cfg!(feature = "adw") { css::CARD } else { "page-section-content" },
|
||||
#[watch]
|
||||
add_css_class: if cfg!(feature = "adw") { "" } else { css::FRAME },
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
pub const COMBINED_CSS: &str = include_str!(concat!(env!("OUT_DIR"), "/combined.css"));
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_css_is_loaded() {
|
||||
assert!(!COMBINED_CSS.is_empty(), "Combined CSS should not be empty");
|
||||
assert!(
|
||||
COMBINED_CSS.contains(".app"),
|
||||
"Combined CSS should contain the .app class"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user