Skip to content

Commit

Permalink
feat: redesign
Browse files Browse the repository at this point in the history
  • Loading branch information
brunostjohn committed Jul 23, 2023
1 parent 07e1eb7 commit 3f3547a
Show file tree
Hide file tree
Showing 22 changed files with 640 additions and 220 deletions.
2 changes: 2 additions & 0 deletions src-tauri/src/rendering/devices/capellix/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ impl<'a> DeviceCreator for Capellix<'a> {
name: "Corsair iCUE Capellix LCD Cooler".to_string(),
manufacturer: "Corsair".to_string(),
conflicting_processes: vec!["iCUE.exe".to_string()],
width: 480,
height: 480,
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions src-tauri/src/rendering/devices/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod thermaltake;

pub struct DeviceContainer {
device: Box<dyn Device>,
device_info: DeviceInfo,
}

impl DeviceContainer {
Expand All @@ -16,6 +17,7 @@ impl DeviceContainer {
Ok(device) => {
return Ok(Self {
device: Box::new(device),
device_info: TTUltra::device_info(),
})
}
Err(_) => None,
Expand All @@ -25,6 +27,7 @@ impl DeviceContainer {
Ok(device) => {
return Ok(Self {
device: Box::new(device),
device_info: Capellix::device_info(),
});
}
Err(_) => None,
Expand Down Expand Up @@ -52,6 +55,10 @@ impl DeviceContainer {
pub fn send_image(&mut self, img: &[u8]) -> Result<(), &'static str> {
self.device.send_image(img)
}

pub fn device_info(&self) -> DeviceInfo {
self.device_info.clone()
}
}

pub trait DeviceCreator {
Expand All @@ -63,10 +70,13 @@ pub trait DeviceCreator {
Self: Sized;
}

#[derive(Clone, Debug)]
pub struct DeviceInfo {
pub name: String,
pub manufacturer: String,
pub conflicting_processes: Vec<String>,
pub width: u32,
pub height: u32,
}

pub trait Device {
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/rendering/devices/thermaltake/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl DeviceCreator for TTUltra {
name: "Thermaltake Toughliquid LCD Cooler".to_string(),
manufacturer: "Thermaltake".to_string(),
conflicting_processes: vec![],
width: 480,
height: 480,
}
}
}
Expand Down
138 changes: 68 additions & 70 deletions src-tauri/src/rendering/threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::fs::{self};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle};
use std::time::{Duration, SystemTime};
use std::time::Duration;
use std::vec;

use crate::rendering::device::DeviceContainer;
Expand Down Expand Up @@ -60,13 +60,6 @@ impl Renderer {
let (tx_port, rx_port) = kanal::unbounded();

let render = thread::spawn(move || {
let mut engine = Ultralight::new(app_folder);

let mut frame_time = EventTicker::new(1000 / fps);
let mut sensor_time = EventTicker::new(3000);
let mut channel_scan = EventTicker::new(250);
let mut gc_time = EventTicker::new(1000 * 30);

let mut device = match DeviceContainer::new() {
Err(error) => {
println!("{:?}", error);
Expand All @@ -75,6 +68,14 @@ impl Renderer {
Ok(result) => result,
};

let info = device.device_info();

let mut engine = Ultralight::new(app_folder, info.width, info.height);

let mut frame_time = EventTicker::new(1000 / fps);
let mut sensor_time = EventTicker::new(3000);
let mut gc_time = EventTicker::new(1000 * 30);

let _ = device
.init()
.map_err(|_| println!("Failed to initialise device."));
Expand Down Expand Up @@ -121,79 +122,76 @@ impl Renderer {

engine.render();

if channel_scan.check_time() {
if gc_time.check_time() {
engine.garbage_collect();
}
if gc_time.check_time() {
engine.garbage_collect();
}

if let Ok(Some(port)) = rx_port.try_recv() {
let _ = engine
.load_url(&format!("http://127.0.0.1:{port}"))
.map_err(|_| println!("Failed to reload theme!"));
}
if let Ok(Some(port)) = rx_port.try_recv() {
let _ = engine
.load_url(&format!("http://127.0.0.1:{port}"))
.map_err(|_| println!("Failed to reload theme!"));
}

if receive_flag(&rx_reload, false) {
let server = server.lock().unwrap();
let now_serving = server.now_serving();
drop(server);
let mut theme_path = themes_path.clone();
theme_path.push(now_serving);
theme_path.push("config.json");

if theme_path.exists() {
let theme_config_unparsed =
fs::read_to_string(theme_path).unwrap_or("".to_owned());

let theme_config_parsed: Vec<ThemeConfigItem> =
serde_json::from_str(&theme_config_unparsed)
.unwrap_or(Vec::new());

let sensors_only: Vec<ThemeConfigItem> = theme_config_parsed
.iter()
.filter(|x| x.r#type == "sensor")
.map(|x| x.to_owned())
.collect::<Vec<ThemeConfigItem>>();

if !sensors_only.is_empty() {
sensor_flag = true;
let sensor_paths: Vec<String> =
sensors_only.iter().map(|x| x.value.clone()).collect();

let sensor_names: Vec<String> =
sensors_only.iter().map(|x| x.name.clone()).collect();

let mut sensors = sensors.lock().unwrap();

if let Ok(vals) = sensors
.subscribe(sensor_paths.clone(), sensor_names.clone())
{
sensor_values = vals;
}

drop(sensors);
} else {
sensor_flag = false;
if receive_flag(&rx_reload, false) {
let server = server.lock().unwrap();
let now_serving = server.now_serving();
drop(server);
let mut theme_path = themes_path.clone();
theme_path.push(now_serving);
theme_path.push("config.json");

if theme_path.exists() {
let theme_config_unparsed =
fs::read_to_string(theme_path).unwrap_or("".to_owned());

let theme_config_parsed: Vec<ThemeConfigItem> =
serde_json::from_str(&theme_config_unparsed).unwrap_or(Vec::new());

let sensors_only: Vec<ThemeConfigItem> = theme_config_parsed
.iter()
.filter(|x| x.r#type == "sensor")
.map(|x| x.to_owned())
.collect::<Vec<ThemeConfigItem>>();

if !sensors_only.is_empty() {
sensor_flag = true;
let sensor_paths: Vec<String> =
sensors_only.iter().map(|x| x.value.clone()).collect();

let sensor_names: Vec<String> =
sensors_only.iter().map(|x| x.name.clone()).collect();

let mut sensors = sensors.lock().unwrap();

if let Ok(vals) =
sensors.subscribe(sensor_paths.clone(), sensor_names.clone())
{
sensor_values = vals;
}

let serialised = theme_config_parsed.custom_serialise();
drop(sensors);
} else {
sensor_flag = false;
}

let serialised = theme_config_parsed.custom_serialise();

engine.call_js_script(
engine.call_js_script(
format!("document.dispatchEvent(new CustomEvent('configLoaded', {{ detail: JSON.parse('{}') }}))", &serialised),
);
}
}
if receive_flag(&rx_end, false) {
println!("Received end signal. Thread: renderer.");
}
if receive_flag(&rx_end, false) {
println!("Received end signal. Thread: renderer.");

let _ = device
.close()
.map_err(|_| println!("Failed to close device!"));
let _ = device
.close()
.map_err(|_| println!("Failed to close device!"));

break;
}

frame_time.change_frequency(&rx_fps);
break;
}

frame_time.change_frequency(&rx_fps);
} else {
thread::sleep(Duration::from_millis(15));
}
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/rendering/ultralight/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Ultralight {

impl Ultralight {
#[allow(unused_mut)]
pub fn new(app_folder: PathBuf) -> Ultralight {
pub fn new(app_folder: PathBuf, width: u32, height: u32) -> Ultralight {
let mut renderer;
let mut view;

Expand Down Expand Up @@ -94,7 +94,7 @@ impl Ultralight {
let view_config = ulCreateViewConfig();
ulViewConfigSetIsAccelerated(view_config, true);

view = ulCreateView(renderer, 480, 480, view_config, null_mut());
view = ulCreateView(renderer, width, height, view_config, null_mut());
ulViewSetFinishLoadingCallback(view, Some(finished_callback), null_mut());
};

Expand Down Expand Up @@ -186,7 +186,7 @@ impl Ultralight {
unsafe {
let context = ulViewLockJSContext(self.view);
JSGarbageCollect(context);
ulViewLockJSContext(self.view);
ulViewUnlockJSContext(self.view);
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/components/FeaturedThemePanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
const onClickPanel = () => {
panel.classList.remove("clicked-panel");
goto(`/themes/fsName?fsName=${encodeURIComponent(theme.fs_name)}`);
panel.classList.add("clicked-panel");
setTimeout(() => {
panel.classList.remove("clicked-panel");
goto(`/themes/fsName?fsName=${encodeURIComponent(theme.fs_name)}`);
}, 150);
};
</script>
Expand Down Expand Up @@ -91,11 +91,13 @@
object-fit: cover;
z-index: -5;
filter: blur(20px) brightness(90%);
filter: blur(20px) brightness(50%);
// background-color: var(--bs-primary);
}
.short-info {
color: white;
z-index: 200;
top: 0;
left: 3%;
Expand All @@ -113,7 +115,9 @@
white-space: nowrap;
}
h4 {
h4,
h3 {
color: white;
}
.preview-img {
Expand Down Expand Up @@ -152,6 +156,8 @@
-webkit-line-clamp: 9;
line-clamp: 9;
-webkit-box-orient: vertical;
color: white;
}
}
</style>
Loading

0 comments on commit 3f3547a

Please sign in to comment.