Skip to content

Commit

Permalink
Merge pull request #83 from WootingKb/enhancement/release-conf
Browse files Browse the repository at this point in the history
1.0 release finish touches
  • Loading branch information
simon-wh authored Jan 18, 2023
2 parents f078c8d + 1579548 commit 1d89d1b
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 62 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wooting-macros",
"private": true,
"version": "0.8.1",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "wooting-macros"
version = "0.9.0"
version = "1.0.0"
description = "Macro software made by Wooting."
authors = ["Jeroen N, Erik S, Simon W, David M, Khang N"]
authors = ["Jeroen N", "Erik S", "Simon W", "David M", "Khang N"]
license = "GPL-3.0-only"
repository = "https://github.com/WootingKb/wooting-macros"
edition = "2021"
Expand All @@ -15,7 +15,7 @@ tauri-build = { version = "1.2", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive", "rc"] }
tauri = { version = "1.2", features = ["api-all", "icon-png", "system-tray", "updater"] }
tauri = { version = "1.2", features = ["app-hide", "app-show", "clipboard-read-text", "clipboard-write-text", "dialog-open", "icon-png", "os-all", "shell-open", "system-tray", "updater"] }
tokio = { version = "1.23", features = ["full"] }
tokio-serde = { version = "0.8", features = ["json"] }
wooting-macro-backend = { path = "../wooting-macro-backend" }
Expand Down
Binary file added src-tauri/icons/dialog-image-493x312.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src-tauri/icons/icon.icns
Binary file not shown.
Binary file added src-tauri/icons/install-banner-493x58.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ async fn control_grabbing(
state: tauri::State<'_, MacroBackend>,
frontend_bool: bool,
) -> Result<(), ()> {
set_macro_listening(state, frontend_bool);
state.set_is_listening(frontend_bool);
// set_macro_listening(state, frontend_bool);
Ok(())
}

Expand Down
45 changes: 35 additions & 10 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,66 @@
},
"package": {
"productName": "Wootomation",
"version": "0.9.0"
"version": "1.0.0"
},
"tauri": {
"allowlist": {
"all": true
"app": {
"hide": true,
"show": true
},
"clipboard": {
"readText": true,
"writeText": true
},
"dialog": {
"open": true
},
"os": {
"all": true
},
"shell": {
"open": true
}
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"category": "Utility",
"copyright": "GPL-v3, Wooting 2023",
"icon": ["icons/icon.png", "icons/icon.ico"],
"deb": {
"depends": ["xserver-xorg-input-evdev", "libevdev2"]
},
"appimage": {
"bundleMediaFramework": false
},
"publisher": "Wooting",
"externalBin": [],
"identifier": "com.wooting.macros",
"longDescription": "",
"longDescription": "Wooting's cross platform macro application for any keyboard or mouse.",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"wix": {
"bannerPath": "icons/install-banner-493x58.png",
"dialogImagePath": "icons/dialog-image-493x312.png",
"license": "../LICENSE"
},
"certificateThumbprint": "641751C7EF318C8D5F908AB7DDD34161375BB34B",
"digestAlgorithm": "sha256",
"timestampUrl": "http://timestamp.sectigo.com"
}
},
"resources": [],
"shortDescription": "A macro application by Wooting",
"targets": "all"
},
"security": {
"csp": null
"csp": "default-src 'self'"
},
"systemTray": {
"iconPath": "icon.png",
Expand Down
2 changes: 1 addition & 1 deletion wooting-macro-backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions wooting-macro-backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "wooting-macro-backend"
version = "0.9.0"
version = "1.0.0"
edition = "2021"
description = "Macro software backend made by Wooting."
authors = ["Jeroen N, Erik S, Simon W, David M, Khang N"]
authors = ["Jeroen N", "Erik S", "Simon W", "David M", "Khang N"]
license = "GPL-3.0-only"


Expand Down
3 changes: 2 additions & 1 deletion wooting-macro-backend/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use wooting_macro_backend::MacroBackend;

#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
/// This main function serves only for running the backend. Backend can be run without frontend parts as most things are separated.
async fn main() {
println!("Eyo");
println!("Running only backend");
let backend = MacroBackend::default();
backend.init().await;
}
12 changes: 10 additions & 2 deletions wooting-macro-backend/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub trait ConfigFile: Default + serde::Serialize + for<'de> serde::Deserialize<'
fn file_name() -> PathBuf;

/// Reads the data from the file and returns it.
/// If it errors out, it replaces and writes a default config
///
/// If it errors out, it replaces and writes a default config.
fn read_data() -> Self {
let default = Self::default();

Expand All @@ -35,6 +36,8 @@ pub trait ConfigFile: Default + serde::Serialize + for<'de> serde::Deserialize<'
}

/// Writes the config file to the config directory.
///
/// If it fails, it uses only in-memory defaults and won't save anything to disk.
fn write_to_file(&self) {
match std::fs::write(
Self::file_name().as_path(),
Expand Down Expand Up @@ -99,15 +102,20 @@ impl Default for ApplicationConfig {
}
}

//Has to be allowed to suppress warnings. Required for release builds.
#[cfg(not(debug_assertions))]
/// Has to be allowed to suppress warnings.
///
/// Required for release builds which save configs to %appdata%
pub const CONFIG_DIR: &str = "wooting-macro-app";

#[cfg(debug_assertions)]
/// Debug builds save configs to the working parent directory.
pub const CONFIG_DIR: &str = "..";

/// Config file name
const CONFIG_FILE: &str = "config.json";

/// Macro data file name
const DATA_FILE: &str = "data_json.json";

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
Expand Down
60 changes: 32 additions & 28 deletions wooting-macro-backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,20 @@ use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::{thread, time};

use tokio::sync::RwLock;

use halfbrown::HashMap;

use tokio::sync::mpsc::{Receiver, Sender};
use tokio::sync::RwLock;
use tokio::task;

//This has to be imported for release build
#[allow(unused_imports)]
use crate::config::CONFIG_DIR;
use halfbrown::HashMap;

use config::{ApplicationConfig, ConfigFile};
#[cfg(not(debug_assertions))]
use dirs;
use tauri::State;

// This has to be imported for release build
#[allow(unused_imports)]
use crate::config::CONFIG_DIR;
use crate::hid_table::*;

//Plugin imports
Expand All @@ -42,7 +40,9 @@ use crate::plugin::phillips_hue;
use crate::plugin::system_event;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
///Type of a macro. Currently only Single is implemented. Others have been postponed for now.
/// Type of a macro. Currently only Single is implemented. Others have been postponed for now.
///
/// ! **UNIMPLEMENTED** - Only the `Single` macro type is implemented for now. Feel free to contribute ideas.
pub enum MacroType {
Single,
// Single macro fire
Expand All @@ -53,7 +53,7 @@ pub enum MacroType {

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type")]
///This enum is the registry for all actions that can be executed
/// This enum is the registry for all actions that can be executed.
pub enum ActionEventType {
KeyPressEventAction {
data: key_press::KeyPress,
Expand Down Expand Up @@ -84,7 +84,8 @@ pub enum ActionEventType {
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type")]
/// This enum is the registry for all incoming actions that can be analyzed for macro execution.
/// Allow while other keys has not been implemented yet.
///
/// ! **UNIMPLEMENTED** - Allow while other keys has not been implemented yet. This is WIP already.
pub enum TriggerEventType {
KeyPressEvent {
data: Vec<u32>,
Expand All @@ -98,7 +99,7 @@ pub enum TriggerEventType {
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
///This is a macro struct. Includes all information a macro needs to run
/// This is a macro struct. Includes all information a macro needs to run.
pub struct Macro {
pub name: String,
pub icon: String,
Expand All @@ -111,6 +112,7 @@ pub struct Macro {
impl Macro {
/// This function is used to execute a macro. It is called by the macro checker.
/// It spawns async tasks to execute said events specifically.
/// Make sure to expand this if you implement new action types.
async fn execute(&self, send_channel: Sender<rdev::EventType>) {
for action in &self.sequence {
match action {
Expand Down Expand Up @@ -173,7 +175,7 @@ type Collections = Vec<Collection>;
/// Hashmap to check the first trigger key of each macro.
type MacroTriggerLookup = HashMap<u32, Vec<Macro>>;

/// State of the application in RAM (rwlock).
/// State of the application in RAM (RWlock).
#[derive(Debug)]
pub struct MacroBackend {
pub data: Arc<RwLock<MacroData>>,
Expand Down Expand Up @@ -242,8 +244,6 @@ impl MacroData {
}
}



output_hashmap
}
}
Expand All @@ -257,7 +257,9 @@ pub struct Collection {
pub active: bool,
}

///Executes a given macro (according to its type).
/// Executes a given macro (according to its type).
///
/// ! **UNIMPLEMENTED** - Only Single macro type is implemented for now.
async fn execute_macro(macros: Macro, channel: Sender<rdev::EventType>) {
match macros.macro_type {
MacroType::Single => {
Expand Down Expand Up @@ -297,6 +299,12 @@ fn keypress_executor_sender(mut rchan_execute: Receiver<rdev::EventType>) {
}

/// A more efficient way using hashtable to check whether the trigger keys match the macro.
///
/// `pressed_events` - the keys pressed in HID format (use the conversion HID hashtable to get the number).
///
/// `trigger_overview` - Macros that need to be checked. Should be picked by matching the hashtable of triggers, and those should be checked here.
///
/// `channel_sender` - a copy of the channel sender to use later when executing various macros.
fn check_macro_execution_efficiently(
pressed_events: Vec<u32>,
trigger_overview: Vec<Macro>,
Expand Down Expand Up @@ -376,42 +384,38 @@ fn check_macro_execution_efficiently(

impl MacroBackend {
#[cfg(not(debug_assertions))]
/// Creates the data directory if not present. (only in release)
/// Creates the data directory if not present in %appdata% (only in release build).
pub fn generate_directories() {
match std::fs::create_dir_all(dirs::config_dir().unwrap().join(CONFIG_DIR).as_path()) {
Ok(x) => x,
Err(error) => error!("Directory creation failed, OS error: {}", error),
};
}

/// Sets whether the backend should process keys that it listens to. Disabling disables the processing logic, but the app still grabs the keys.
pub fn set_is_listening(&self, is_listening: bool) {
self.is_listening.store(is_listening, Ordering::Relaxed);
}

/// Sets the macros from the frontend to the files. This function is here to completely split the frontend off.
pub async fn set_macros(&self, macros: MacroData) {
macros.write_to_file();
*self.triggers.write().await = macros.extract_triggers();
*self.data.write().await = macros;
}

/// Sets the config from the frontend to the files. This function is here to completely split the frontend off.
pub async fn set_config(&self, config: ApplicationConfig) {
config.write_to_file();
*self.config.write().await = config;
}

#[inline(always)]
/// Initializes the entire backend and gets the whole grabbing system running.
pub async fn init(&self) {
//let config = ApplicationConfig::read_data().minimize_to_tray;

//? : io-uring async read files and write files
//TODO: implement drop when the application ends to clean up the downed keys

//==================================================

// Spawn the grabbing. Deactivate the grabbing on macOS by keeping the thread busy for now
// #[cfg(target_os = "macos")]
// loop{}

let inner_triggers = self.triggers.clone();
let inner_is_listening = self.is_listening.clone();

Expand Down Expand Up @@ -486,7 +490,6 @@ impl MacroBackend {
Some(data_found) => data_found.to_vec(),
};


// ? up the pressed keys here immidiately?

let should_grab = {
Expand Down Expand Up @@ -593,9 +596,10 @@ impl Default for MacroBackend {
}
}

pub fn set_macro_listening(state: State<MacroBackend>, frontend_bool: bool) {
state.is_listening.store(frontend_bool, Ordering::Relaxed);
}
// /// Sets whether the macro listening processing is happening.
// pub fn set_macro_listening(state: State<MacroBackend>, frontend_bool: bool) {
// state.is_listening.store(frontend_bool, Ordering::Relaxed);
// }

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion wooting-macro-backend/src/plugin/delay.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/// Delay for the sequence
/// Delay for the sequence in milliseconds
pub type Delay = u64;
Loading

0 comments on commit 1d89d1b

Please sign in to comment.