Skip to content

Commit

Permalink
feat: 0.1.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
brunostjohn committed Jul 19, 2023
1 parent abc143f commit fcabac1
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ strip = true
[profile.release]
lto = true
opt-level= 3
incremental = true
incremental = false
panic = "abort"
codegen-units = 1
strip = true
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ args = ["fmt", "--", "--emit=files"]
[tasks.clean]
dependencies = [
"clean-rust",
"clean-libre-project"
"clean-libre-lib"
]

[tasks.clean-rust]
Expand All @@ -17,7 +17,7 @@ args = ["clean"]
install_crate = "tauri"
command = "cargo"
args = ["tauri", "build"]
dependencies = ["clean"]
dependencies = ["clean", "libre"]

[tasks.clean-libre-lib]
cwd = "../LibreHardwareMonitorNative/"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fn main() {
println!("cargo:rustc-link-search=./static-libs/");
println!("cargo:rustc-link-lib=LibreHardwareMonitorNative");

println!("cargo:rustc-link-search=/Users/bruno/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/7.0.9/sdk");
println!("cargo:rustc-link-search=/Users/bruno/.nuget/packages/runtime.win-x64.microsoft.dotnet.ilcompiler/7.0.8/sdk");
println!("cargo:rustc-link-arg-bins=/INCLUDE:NativeAOT_StaticInitialization");

println!("cargo:rerun-if-changed=build.rs");
Expand Down
93 changes: 35 additions & 58 deletions src-tauri/src/frontend/themes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,67 +539,44 @@ pub fn get_all_themes() -> Result<Vec<Theme>, &'static str> {

let mut themes = vec![];

for dir in themes_iter {
match dir {
Ok(item) => {
let dir_path = item.path();

let mut index_path = dir_path.clone();
index_path.push("index.html");

if index_path.as_path().exists() {
let mut image_path = dir_path.clone();
image_path.push("preview.jpg");

let mut json_path = dir_path.clone();
json_path.push("theme.json");

let loaded = match fs::read_to_string(json_path) {
Ok(st) => st,
Err(_) => "{}".to_string(),
};

let mut manifest = match serde_json::from_str(&loaded) {
Ok(res) => res,
Err(_) => Theme {
name: item.file_name().to_str().unwrap().to_string(),
fs_name: item.file_name().to_str().unwrap().to_string(),
colour: None,
description: "Failed to load theme.json".to_string(),
author: "Failed to load".to_string(),
customisable_parameters: vec![],
version: "0.0.0".to_owned(),
tested_on: None,
},
};

match manifest.colour {
Some(_) => {}
None => {
let image_colour = match image::open(image_path) {
Ok(file) => {
let (buffer, color_type) = get_image_buffer(file);
let colors =
color_thief::get_palette(&buffer, color_type, 10, 10)
.unwrap();

format!(
"#{:02X?}{:02X?}{:02X?}",
255 - colors[0].r,
255 - colors[0].g,
255 - colors[0].b
)
}
Err(_) => "#FFFFFF".to_string(),
};
manifest.colour = Some(image_colour);
for item in themes_iter.flatten() {
let dir_path = item.path();

let mut index_path = dir_path.clone();
index_path.push("index.html");

if index_path.as_path().exists() {
let mut image_path = dir_path.clone();
image_path.push("preview.jpg");

let mut manifest = get_theme_inner(
theme_path.to_path_buf(),
item.file_name().to_string_lossy().to_string(),
)?;

match manifest.colour {
Some(_) => {}
None => {
let image_colour = match image::open(image_path) {
Ok(file) => {
let (buffer, color_type) = get_image_buffer(file);
let colors =
color_thief::get_palette(&buffer, color_type, 10, 10).unwrap();

format!(
"#{:02X?}{:02X?}{:02X?}",
255 - colors[0].r,
255 - colors[0].g,
255 - colors[0].b
)
}
}

themes.push(manifest);
Err(_) => "#FFFFFF".to_string(),
};
manifest.colour = Some(image_colour);
}
}
Err(_) => {}

themes.push(manifest);
}
}

Expand Down
10 changes: 7 additions & 3 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@ fn main() {
api.prevent_exit();
// println!("Exit requested");
}
_ => {
// println!("{:#?}", event);
}
tauri::RunEvent::Exit => {}
tauri::RunEvent::WindowEvent { label, event, .. } => {}
tauri::RunEvent::Ready => {}
tauri::RunEvent::Resumed => {}
tauri::RunEvent::MainEventsCleared => {}
tauri::RunEvent::Updater(_) => {}
_ => {}
});

println!("App exited");
Expand Down
13 changes: 5 additions & 8 deletions src-tauri/src/rendering/threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ use std::fs::{self};
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::thread::{self, JoinHandle};
use std::time::{Duration};
use std::time::{Duration, SystemTime};
use std::vec;



use crate::rendering::device::DeviceContainer;
use crate::rendering::helpers_threading::{ChangeFrequency, EventTicker};
use crate::rendering::traits::CustomSerialise;
Expand Down Expand Up @@ -64,8 +62,6 @@ impl Renderer {
let render = thread::spawn(move || {
let mut engine = Ultralight::new(app_folder);

println!("Received {:?} fps", fps);

let mut frame_time = EventTicker::new(1000 / fps);
let mut sensor_time = EventTicker::new(3000);
let mut channel_scan = EventTicker::new(250);
Expand Down Expand Up @@ -113,7 +109,6 @@ impl Renderer {

engine.call_js_script(script);
}
engine.render();
let image = engine.get_bitmap().unwrap();

if device.send_image(&image).is_err() {
Expand All @@ -123,6 +118,9 @@ impl Renderer {
device.init().unwrap();
}
}

engine.render();

if channel_scan.check_time() {
if gc_time.check_time() {
engine.garbage_collect();
Expand Down Expand Up @@ -184,7 +182,6 @@ impl Renderer {
);
}
}

if receive_flag(&rx_end, false) {
println!("Received end signal. Thread: renderer.");

Expand All @@ -198,7 +195,7 @@ impl Renderer {
frame_time.change_frequency(&rx_fps);
}
} else {
thread::sleep(Duration::from_millis(10));
thread::sleep(Duration::from_millis(15));
}
}
});
Expand Down
54 changes: 44 additions & 10 deletions src-tauri/src/rendering/ultralight/driver.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@

use std::path::PathBuf;

use std::time::Duration;
use std::{borrow::Cow, mem, rc::Rc};
use std::{fs, thread};





use glium::program::{Binary, ProgramCreationInput};
use glium::vertex::AttributeType;



use serde::{Deserialize, Serialize};

use self::gpu::GPUDriver;
Expand Down Expand Up @@ -564,8 +557,48 @@ impl GPUDriverReceiver {
#[inline]
pub fn render(&mut self) -> Result<(), &'static str> {
while let Some(cmd) = unsafe { QUEUE.dequeue() } {
// println!("{:?}", &cmd);
thread::sleep(Duration::from_millis(5));
// println!("{:?}", &cmd);a
// thread::sleep(Duration::from_millis(5));
match cmd {
GPUDriverCommand::CreateTexture(id, bitmap) => {
let tex = self.create_texture(id, bitmap)?;

self.texture_map.insert(id, (tex, None));
}
GPUDriverCommand::UpdateTexture(id, bitmap) => {
self.update_texture(id, bitmap)?;
}
GPUDriverCommand::DestroyTexture(id) => {
self.destroy_texture(id)?;
}
GPUDriverCommand::CreateRenderBuffer(id, render_buffer) => {
self.create_render_buffer(id, render_buffer)?;
}
GPUDriverCommand::DestroyRenderBuffer(id) => {
self.destroy_render_buffer(id)?;
}
GPUDriverCommand::CreateGeometry(id, vertex, index) => {
self.create_geometry(id, vertex, index)?;
}
GPUDriverCommand::UpdateGeometry(id, vertex, index) => {
self.update_geometry(id, vertex, index)?;
}
GPUDriverCommand::DestroyGeometry(id) => {
self.destroy_geometry(id)?;
}
GPUDriverCommand::UpdateCommandList(command_list) => {
self.update_command_list(command_list)?;
}
};
std::thread::yield_now();
}

Ok(())
}

#[inline]
pub fn exec_one(&mut self) -> Result<(), &'static str> {
if let Some(cmd) = unsafe { QUEUE.dequeue() } {
match cmd {
GPUDriverCommand::CreateTexture(id, bitmap) => {
let tex = self.create_texture(id, bitmap)?;
Expand Down Expand Up @@ -782,7 +815,8 @@ impl GPUDriverReceiver {
self.draw_geometry(gpu_state, geometry_id, indices_offset, indices_count)?;
}
}
thread::sleep(Duration::from_millis(5));
// thread::sleep(Duration::from_millis(5));
std::thread::yield_now();
}

Ok(())
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/rendering/ultralight/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use std::{
},
};

use heapless::spsc::{Queue};

use heapless::spsc::Queue;

use rayon::prelude::*;

Expand Down Expand Up @@ -43,13 +42,13 @@ impl Ultralight {
let mut renderer;
let mut view;

// unsafe { GPU_SENDER.set_tx(producer) };

let driver_recv = GPUDriverReceiver::new(app_folder.clone()).unwrap();

unsafe {
let config = ulCreateConfig();

ulConfigSetRecycleDelay(config, 10.0);

ulPlatformSetGPUDriver(ULGPUDriver {
begin_synchronize: Some(begin_sync),
end_synchronize: Some(end_sync),
Expand Down Expand Up @@ -158,10 +157,11 @@ impl Ultralight {
}

#[inline(always)]
pub fn update(&self) {
pub fn update(&mut self) {
unsafe {
ulUpdate(self.renderer);
}
let _ = self.driver_recv.exec_one();
}

#[inline(always)]
Expand Down
4 changes: 2 additions & 2 deletions src/routes/services/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
<ServiceOption href="" name="Sensors" desc="See your CPU's temperature on your cooler."
><SensorIcon /></ServiceOption
>
<ServiceOption
<!-- <ServiceOption
href="/srgb"
name="SignalRGB"
desc="Sync your cooler with your PC's lighting effects."
>
<SrgbIcon />
</ServiceOption>
</ServiceOption> -->
</div>
{#key data.pathname}
<div class="content" in:fly={transitionIn} out:fly={transitionOut}>
Expand Down

0 comments on commit fcabac1

Please sign in to comment.