Skip to content

Commit

Permalink
Removed in app logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mbwilding committed Feb 8, 2024
1 parent 63b1807 commit 26a5974
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 35 deletions.
6 changes: 3 additions & 3 deletions dygma-layer-switcher/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dygma-layer-switcher"
version = "0.3.9"
version = "0.3.10"
edition = "2021"
authors = ["Matthew Wilding <[email protected]>"]
build = "build.rs"
Expand All @@ -13,14 +13,14 @@ eframe = { version = "0.26", default-features = false, features = [
"wgpu",
"persistence",
] }
egui_logger = "0.4"
image = "0.24"
lazy_static = "1.4"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
serialport = "4.3"
single-instance = "0.3"
sysinfo = "0.30"
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] }
windows = { version = "0.52", features = [
"Win32_Foundation",
"Win32_UI_Accessibility",
Expand Down
21 changes: 1 addition & 20 deletions dygma-layer-switcher/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use eframe::egui::{
};
use eframe::{egui, Frame, Storage};
use lazy_static::lazy_static;
use log::{trace, warn};
use std::sync::{Arc, Mutex};
use tracing::{trace, warn};

pub const MAX_LAYERS: u8 = 10;

Expand All @@ -27,15 +27,6 @@ impl DygmaLayerSwitcher {
Default::default()
}

fn logging_control(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.label(verbiage::SETTING_LOGGING)
.on_hover_text(verbiage::SETTING_LOGGING_HINT);
ui.checkbox(&mut self.logging, "")
.on_hover_text(verbiage::SETTING_LOGGING_HINT);
});
}

fn port_control(&mut self, ui: &mut egui::Ui) {
ui.horizontal(|ui| {
ui.label(verbiage::SETTING_PORT)
Expand Down Expand Up @@ -116,7 +107,6 @@ impl DygmaLayerSwitcher {
CollapsingHeader::new(verbiage::SETTINGS)
.default_open(true)
.show(ui, |ui| {
self.logging_control(ui);
self.port_control(ui);
self.base_layer_control(ui);
self.hidden_layer_control(ui);
Expand Down Expand Up @@ -337,15 +327,6 @@ impl eframe::App for DygmaLayerSwitcher {
self.detect_configuration_changes();
self.top_panel(ctx);
self.central_panel(ctx);

egui::Window::new("Log")
.open(&mut self.logging)
.drag_to_scroll(true)
.title_bar(true)
.show(ctx, |ui| {
egui_logger::logger_ui(ui);
ctx.request_repaint();
});
}

fn save(&mut self, storage: &mut dyn Storage) {
Expand Down
2 changes: 1 addition & 1 deletion dygma-layer-switcher/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::app::CONFIGURATION;
use crate::structs::{AppDetails, Configuration, Mode};
use dygma_focus::prelude::*;
use lazy_static::lazy_static;
use log::{debug, error, info};
use std::sync::Mutex;
use sysinfo::System;
use tracing::{debug, error, info};

lazy_static! {
static ref SYSTEM: Mutex<System> = Mutex::new(System::new());
Expand Down
16 changes: 14 additions & 2 deletions dygma-layer-switcher/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// hide console window on Windows
#![windows_subsystem = "windows"]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use crate::structs::DygmaLayerSwitcher;
use anyhow::Result;
use eframe::egui::ViewportBuilder;
use eframe::*;
use std::sync::Arc;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;

mod app;
mod helpers;
Expand All @@ -18,6 +20,17 @@ mod verbiage;
mod windows;

pub fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::builder()
.with_default_directive(LevelFilter::OFF.into())
.from_env_lossy(),
)
.with_target(false)
.without_time()
.compact()
.init();

single::check()?;

run_native(
Expand All @@ -42,7 +55,6 @@ pub fn main() -> Result<()> {
Box::new(move |cc| {
let mut app = DygmaLayerSwitcher::new(cc);
app.configuration_changed = true;
egui_logger::init().unwrap();
windows::start(); // Creates a thread that listens for window focus changes.
Box::new(app)
}),
Expand Down
2 changes: 1 addition & 1 deletion dygma-layer-switcher/src/single.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::verbiage;
use anyhow::Result;
use log::error;
use single_instance::SingleInstance;
use tracing::log::error;

pub fn check() -> Result<()> {
let instance = SingleInstance::new(verbiage::APP_NAME)?;
Expand Down
6 changes: 1 addition & 5 deletions dygma-layer-switcher/src/structs.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use crate::app::MAX_LAYERS;
use crate::verbiage;
use dygma_focus::prelude::*;
use log::error;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};
use tracing::error;

#[derive(Deserialize, Serialize)]
#[serde(default)]
pub struct DygmaLayerSwitcher {
#[serde(skip)]
pub logging: bool,

pub port: String,
pub base_layer: u8,
pub mappings: BTreeMap<u8, Layer>,
Expand Down Expand Up @@ -44,7 +41,6 @@ impl Default for DygmaLayerSwitcher {
});

Self {
logging: false,
port: device.serial_port,
base_layer: 1,
mappings: (0..MAX_LAYERS)
Expand Down
2 changes: 0 additions & 2 deletions dygma-layer-switcher/src/verbiage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ pub const SETTING_BASE_LAYER: &str = "Base Layer";
pub const SETTING_BASE_LAYER_HINT: &str = "The layer to return to.";
pub const SETTING_BASE_LAYER_VALUE_HINT: &str = "Click and drag to change the base layer.";
pub const SETTING_HIDDEN_LAYERS: &str = "Hidden Layers";
pub const SETTING_LOGGING: &str = "Logging";
pub const SETTING_LOGGING_HINT: &str = "Enables the logging window.";
pub const SETTING_PORT: &str = "Port";
pub const SETTING_PORT_HINT: &str = "The serial port to communicate with.";
pub const SETTING_PORT_INPUT_HINT: &str = "Click to edit the port.";
Expand Down
4 changes: 3 additions & 1 deletion dygma-layer-switcher/src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::layer;
use crate::structs::AppDetails;
use log::{error, info, trace};
use std::path::Path;
use std::sync::atomic::AtomicU32;
use std::sync::atomic::Ordering;
use tracing::{error, info, trace};
use windows::core::PCWSTR;
use windows::Win32::Foundation::CloseHandle;
use windows::Win32::{
Foundation::{HWND, MAX_PATH},
System::{
Expand Down Expand Up @@ -139,6 +140,7 @@ unsafe fn get_process(window_handle: HWND) -> String {

let mut exe_path_bytes: Vec<u16> = vec![0; MAX_PATH as usize];
let exe_path_length = K32GetModuleFileNameExW(process_handle, None, &mut exe_path_bytes);
let _ = CloseHandle(process_handle);
let exe_path = String::from_utf16_lossy(&exe_path_bytes[..exe_path_length as usize]);

trace!("Process: {:?}", exe_path);
Expand Down

0 comments on commit 26a5974

Please sign in to comment.