Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

33 changes: 25 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
name: CI

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
name: CI
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
lfs: true
- uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
- uses: Swatinem/rust-cache@v2

- name: cargo build
run: cargo build
Expand All @@ -25,3 +33,12 @@ jobs:

- name: cargo clippy
run: cargo clippy -- -D warnings

typos:
name: Typos
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
lfs: true
- uses: crate-ci/typos@master
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ Cargo.lock
**/*.rs.bk
*.pdb
.DS_Store
**/tests/snapshots/**/*.diff.png
**/tests/snapshots/**/*.new.png
**/tests/snapshots/**/*.old.png
88 changes: 58 additions & 30 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "awtrix-gui"
version = "0.1.0-beta.1"
edition = "2021"
version = "0.1.0"
edition = "2024"
description = "A GUI for the awtrix clock."
authors = ["bircni"]
readme = "README.md"
Expand All @@ -24,7 +24,7 @@ icon = [
]
version = "0.1.0"
resources = ["./../res/mac-icons/icon*.png"]
copyright = "© 2024 bircni"
copyright = "© 2025 bircni"
short_description = "A GUI for the awtrix clock."

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -34,36 +34,64 @@ short_description = "A GUI for the awtrix clock."

[dependencies]
# Error handling
anyhow = "1.0.95"
# Networking
reqwest = { version = "0.12.11", features = ["blocking"] }
anyhow = "1"
# Parsing
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.134"
semver = "1.0.24"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
# GUI
eframe = "0.30.0"
egui = "0.30.0"
egui-notify = "0.18.0"
egui_extras = { version = "0.30.0", features = ["syntect", "image"] }
image = "0.25.5"
open = "5.3.1"
parking_lot = "0.12.3"
eframe = "0.33"
egui = "0.33"
egui-notify = "0.21"
egui_extras = { version = "0.33", features = ["syntect", "image"] }
image = "0.25"
open = "5.3"
parking_lot = "0.12"
ureq = "3.1.4"

[dev-dependencies]
egui_kittest = { version = "0.33", features = ["wgpu", "snapshot"] }
eframe = { version = "0.33", features = ["wgpu"] }
tokio = { version = "1", features = ["time", "rt", "macros"] }
wgpu = "27"


[lints.rust]
unsafe_code = "forbid"
deprecated = "deny"
unsafe_code = "deny"
deprecated = "warn"
elided_lifetimes_in_paths = "warn"
rust_2021_prelude_collisions = "warn"
semicolon_in_expressions_from_macros = "warn"
trivial_numeric_casts = "warn"
unsafe_op_in_unsafe_fn = "warn" # `unsafe_op_in_unsafe_fn` may become the default in future Rust versions: https://github.com/rust-lang/rust/issues/71668
unused_extern_crates = "warn"
unused_import_braces = "warn"
unused_lifetimes = "warn"

[lints.rustdoc]
all = "warn"
missing_crate_level_docs = "warn"

[lints.clippy]
nursery = { level = "deny", priority = 0 }
pedantic = { level = "deny", priority = 1 }
enum_glob_use = { level = "deny", priority = 2 }
perf = { level = "deny", priority = 3 }
style = { level = "deny", priority = 4 }
unwrap_used = { level = "deny", priority = 5 }
expect_used = { level = "deny", priority = 6 }
module_name_repetitions = { level = "allow", priority = 7 }
cast_precision_loss = { level = "allow", priority = 8 }
cast_possible_truncation = { level = "allow", priority = 9 }
cast_sign_loss = { level = "allow", priority = 10 }
out_of_bounds_indexing = { level = "allow", priority = 11 }
all = "warn"
correctness = "warn"
suspicious = "warn"
style = "warn"
complexity = "warn"
perf = "warn"
pedantic = "warn"
nursery = "warn"

# Additional lints from https://rust-lang.github.io/rust-clippy/master/index.html?groups=restriction
allow_attributes = "warn"
allow_attributes_without_reason = "warn"
assertions_on_result_states = "warn"
create_dir = "warn"
clone_on_ref_ptr = "warn"
expect_used = "warn"
missing_assert_message = "warn"
panic_in_result_fn = "warn"
str_to_string = "warn"
todo = "warn"
unwrap_used = "warn"
unimplemented = "warn"
wildcard_enum_match_arm = "warn"
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 bircni
Copyright (c) 2025 bircni

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
29 changes: 18 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::Context;
use core::str;
use serde::{Deserialize, Serialize};
use std::{env, fs, io::Write};
use std::{fs, io::Write};

const ENV: &str = ".awtrix.env";
const CONFIG: &str = "awtrix.conf";

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Config {
Expand All @@ -12,6 +12,7 @@ pub struct Config {
pub last_state: bool,
}

// TODO refactoring to use home dir
impl Config {
pub fn new() -> Self {
Self::read().unwrap_or_else(|_| Self {
Expand All @@ -21,21 +22,27 @@ impl Config {
}

fn read() -> anyhow::Result<Self> {
let curr = env::current_exe()?;
let filepath = curr.parent().context("Failed to gt parent path")?.join(ENV);
let home_dir = std::env::home_dir().context("Failed to get home directory")?;
let config_dir = home_dir.join(".config").join("awtrix-gui");
if !config_dir.exists() {
fs::create_dir_all(&config_dir).context("Failed to create config directory")?;
}
let filepath = config_dir.join(CONFIG);
anyhow::ensure!(filepath.exists(), "Path does not exist");
let content = fs::read_to_string(filepath)?;
serde_json::from_str(&content).context("Failed to deserialize Config")
}

pub fn write(&self) -> anyhow::Result<()> {
if let Some(filepath) = env::current_exe()?.parent().map(|x| x.join(ENV)) {
let mut file = fs::File::create(filepath)?;
file.write_all(serde_json::to_string(self)?.as_bytes())?;
file.flush()?;
Ok(())
} else {
anyhow::bail!("Failed to write to file")
let home_dir = std::env::home_dir().context("Failed to get home directory")?;
let config_dir = home_dir.join(".config").join("awtrix-gui");
if !config_dir.exists() {
fs::create_dir_all(&config_dir).context("Failed to create config directory")?;
}
let filepath = config_dir.join(CONFIG);
let mut file = fs::File::create(filepath)?;
file.write_all(serde_json::to_string_pretty(self)?.as_bytes())?;
file.flush()?;
Ok(())
}
}
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use anyhow::Context;
use eframe::icon_data;
use egui::ViewportBuilder;

mod config;
#[cfg(test)]
mod tests;
mod ui;

fn main() -> anyhow::Result<()> {
Expand All @@ -10,8 +13,7 @@ fn main() -> anyhow::Result<()> {
.with_app_id("awtrix-gui")
.with_inner_size(egui::vec2(900.0, 600.0))
.with_icon(
eframe::icon_data::from_png_bytes(include_bytes!("../res/icon.png"))
.unwrap_or_default(),
icon_data::from_png_bytes(include_bytes!("../res/icon.png")).unwrap_or_default(),
);

eframe::run_native(
Expand All @@ -21,7 +23,7 @@ fn main() -> anyhow::Result<()> {
centered: true,
..Default::default()
},
Box::new(|cc| Ok(Box::new(ui::App::new(cc)))),
Box::new(|cc| Ok(Box::new(ui::App::new(&cc.egui_ctx)))),
)
.map_err(|e| anyhow::anyhow!(e.to_string()))
.context("Failed to run native")
Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod ui_tests;
59 changes: 59 additions & 0 deletions src/tests/ui_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use egui::{ThemePreference, accesskit::Role};
use egui_kittest::{Harness, kittest::Queryable};
use wgpu::InstanceDescriptor;

use crate::ui::App;

pub fn app() -> Harness<'static> {
let mut app = None;

Harness::new(move |ctx| {
let app_instance = app.get_or_insert_with(|| App::new(ctx));
app_instance.show(ctx);
})
}

async fn gpu_available() -> bool {
wgpu::Instance::new(&InstanceDescriptor::default())
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: None,
force_fallback_adapter: false,
})
.await
.is_ok()
}

#[tokio::test]
pub async fn test_main_view() {
if !gpu_available().await {
return;
}

let themes = vec![ThemePreference::Dark, ThemePreference::Light];

for theme in themes {
let mut harness = app();
harness.ctx.set_theme(theme);

harness.run();
harness.snapshot(format!("{theme:?}/main_view"));

let input = harness.get_by_role(Role::TextInput);
input.focus();
input.type_text("192.168.1.1");
harness.run();
harness.snapshot(format!("{theme:?}/ip_entered"));

harness
.get_by_role_and_label(Role::Button, "Settings")
.click();
harness.run();
harness.snapshot(format!("{theme:?}/settings_view"));

harness.get_by_role_and_label(Role::Button, " ? ").click();

harness.run();
harness.snapshot(format!("{theme:?}/about_dialog"));
}
}
Loading
Loading