Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix udev and dumb time crate issue #43

Merged
merged 3 commits into from
Aug 15, 2024
Merged
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
8 changes: 4 additions & 4 deletions Cargo.lock

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

33 changes: 21 additions & 12 deletions src/commands/udev.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,13 +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 \
```\nsudo 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(())
}
Expand All @@ -39,15 +44,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}")
Expand Down