From e2ec6ddceb22ba29cbc64b5cb716ffe4a0faaf21 Mon Sep 17 00:00:00 2001 From: jamesbt365 Date: Wed, 14 Aug 2024 21:55:47 +0100 Subject: [PATCH 1/3] Fix udev and dumb time crate issue --- Cargo.lock | 8 ++++---- src/commands/udev.rs | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e201d81..b6495cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1789,9 +1789,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", @@ -1810,9 +1810,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", diff --git a/src/commands/udev.rs b/src/commands/udev.rs index 2f7b9de..bcfd8e5 100644 --- a/src/commands/udev.rs +++ b/src/commands/udev.rs @@ -23,8 +23,10 @@ pub async fn generate_udev( let attachment = CreateAttachment::bytes(udev, "70-opentabletdriver.rules"); ctx.send( CreateReply::default() - .content("place this file in `/etc/udev/rules.d/70-opentabletdriver.rules` then run the following:\n \ - ```\nsudo udevadm control --reload-rules && sudo udevadm trigger\n```") + .content( + "place this file in `/etc/udev/rules.d/70-opentabletdriver.rules` then run the \ + following: \n```sudo udevadm control --reload-rules && sudo udevadm trigger\n```", + ) .attachment(attachment), ) .await?; @@ -39,15 +41,19 @@ KERNEL=="js[0-9]*", SUBSYSTEM=="input", ATTRS{name}=="OpenTabletDriver Virtual T fn gen_udev(id_vendor: u64, id_product: u64, libinput_override: bool) -> String { let mut udev_rules = format!( - "KERNEL==\"hidraw*\", ATTRS{{idVendor}}==\"{id_vendor:X}\", ATTRS{{idProduct}}==\"{id_product:X}\", TAG+=\"uaccess\", TAG+=\"udev-acl\"\n\ - SUBSYSTEM==\"usb\", ATTRS{{idVendor}}==\"{id_vendor:X}\", ATTRS{{idProduct}}==\"{id_product:X}\", TAG+=\"uaccess\", TAG+=\"udev-acl\"" + "KERNEL==\"hidraw*\", ATTRS{{idVendor}}==\"{id_vendor:04x}\", \ + ATTRS{{idProduct}}==\"{id_product:04x}\", TAG+=\"uaccess\", \ + TAG+=\"udev-acl\"\nSUBSYSTEM==\"usb\", ATTRS{{idVendor}}==\"{id_vendor:04x}\", \ + ATTRS{{idProduct}}==\"{id_product:04x}\", TAG+=\"uaccess\", TAG+=\"udev-acl\"" ); if libinput_override { write!( udev_rules, - "\nSUBSYSTEM==\"input\", ATTRS{{idVendor}}==\"{id_vendor:X}\", ATTRS{{idProduct}}==\"{id_product:X}\"" - ).unwrap(); + "\nSUBSYSTEM==\"input\", ATTRS{{idVendor}}==\"{id_vendor:04x}\", \ + ATTRS{{idProduct}}==\"{id_product:04x}\", ENV{{LIBINPUT_IGNORE_DEVICE}}=\"1\"" + ) + .unwrap(); } format!("{REQUIRED_UDEV_STR}\n# Generated by TabletBot\n{udev_rules}") From a752043163b562b857aac071dc3211a6c9880ccc Mon Sep 17 00:00:00 2001 From: jamesbt365 Date: Wed, 14 Aug 2024 22:12:23 +0100 Subject: [PATCH 2/3] Use embed for udev command --- src/commands/udev.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/commands/udev.rs b/src/commands/udev.rs index bcfd8e5..c3a0634 100644 --- a/src/commands/udev.rs +++ b/src/commands/udev.rs @@ -1,8 +1,9 @@ +use crate::commands::OK_COLOUR; use crate::{Context, Error}; use std::fmt::Write; -use poise::serenity_prelude::CreateAttachment; +use poise::serenity_prelude::{CreateAttachment, CreateEmbed}; use poise::CreateReply; /// Generates udev rules for the given vendor and product Ids. @@ -21,15 +22,17 @@ pub async fn generate_udev( let udev = gen_udev(vendor_id, product_id, libinput_override.unwrap_or(true)); let attachment = CreateAttachment::bytes(udev, "70-opentabletdriver.rules"); - ctx.send( - CreateReply::default() - .content( - "place this file in `/etc/udev/rules.d/70-opentabletdriver.rules` then run the \ - following: \n```sudo udevadm control --reload-rules && sudo udevadm trigger\n```", - ) - .attachment(attachment), - ) - .await?; + let embed = CreateEmbed::new() + .title("Generated Udev rules") + .description( + "Move this file to `/etc/udev/rules.d/70-opentabletdriver.rules` then run the \ + following commands: \n```sudo udevadm control --reload-rules && sudo udevadm \ + trigger\n```", + ) + .color(OK_COLOUR); + + ctx.send(CreateReply::default().embed(embed).attachment(attachment)) + .await?; Ok(()) } From d271c1068dade417a18476c20433e4117ace2312 Mon Sep 17 00:00:00 2001 From: InfinityGhost Date: Wed, 14 Aug 2024 18:46:46 -0400 Subject: [PATCH 3/3] Change embed title --- src/commands/udev.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/udev.rs b/src/commands/udev.rs index c3a0634..504f44f 100644 --- a/src/commands/udev.rs +++ b/src/commands/udev.rs @@ -23,7 +23,7 @@ pub async fn generate_udev( let attachment = CreateAttachment::bytes(udev, "70-opentabletdriver.rules"); let embed = CreateEmbed::new() - .title("Generated Udev rules") + .title("Generated udev rules") .description( "Move this file to `/etc/udev/rules.d/70-opentabletdriver.rules` then run the \ following commands: \n```sudo udevadm control --reload-rules && sudo udevadm \