FUNNY MIC!
- 4 Devlogs
- 25 Total hours
A tool to hot swap between a microphone temporarily by holding down a key!
A tool to hot swap between a microphone temporarily by holding down a key!
Wew, I should have probably made a devlog in between my last one!
I have added Windows support! Fun fact, I hate working with the Windows API, and I’ve just learned that!
In fairness, it’s a littleee bit awkward working with an API that is very obviously native to C, even if the Rust library gives it some Rustiness, but still, I dislike it. Greatly. Anyways, the important part is it works! And I had to use an undocumented Windows API to do a basic task (setting the default audio device). Nice. Cool! Awesome.
(i’ve been trying to switch to Linux for a reason)
Thankfully, someone already implemented that in the com-policy-config crate so I don’t have to find and try to convert a header file myself.
After Windows support was done, the rest was relatively easy! Tauri has another plugin that makes it a little bit easier to manage a JSON store file and make it accessible to anything that has an AppHandle. config.json now stores the selected swap device and keybind, and these get automatically reloaded on startup. Lovely!
I use NixOS as my main operating system, so I already made a default.nix and shell.nix for running here. However, it doesn’t seem I can properly compile the regular bundles for .deb., .rpm, and AppImages (easily, anyway), and it would be tedious for every release anyways! Thankfully, tauri-action already exists, too! I made a GitHub Actions workflow that will compile and publish installers for both Windows and Linux when I make a new release. It’s pretty neat stuff, actually!
This also means I finally took the time to make a nice README. It was nice to take a small step back to kind of overview this project.
A fun little over-engineered thing this is, something that could have stayed a CLI app with only Linux support and nobody would have blinked, but here we are!
It’s definitely been good practice for both my backend (Rust!) and frontend skills. I will definitely be using Tauri again in the future!
Hello, from v1.0.0! (and Windows!)
NO IT WON’T BE ASDSFSDGDG
ahem. What I mean to say is that the UI is done and ready! I think it looks relatively nice, simple, and most importantly, is functional.
I, somehow, managed to log 11 HOURS, of which a significiant part of was not doing the UI, actually! It was literally just trying to get the global shortcut functionality to work again!
I use KDE Plasma as my desktop environment, which uses Wayland by default as of Plasma 6. I want to support all systems, and that obviously includes my own, but the Global Shortcut plugin for Tauri, as it turns out, only natively supports X11. Ah.
At first, I tried using this pull request by patching it into my dependencies, so the Tauri plugin would use that instead of the normal crate. This worked actually! Until I tried using unregister_all(), at which point it crashes the xdg-desktop-portal with a SIGABRT, somehow, for some reason.
I have no idea if that’s an issue with my system (I tried updating!) but I couldn’t find a way around it, so I ended up scrapping that plan (using an unreviewed, unmerged PR probably isn’t a great idea anyway…).
After what I said about rdev in the last devlog, I ended up writing a key handler module that would fallback to rdev when detecting Wayland (inspired by how murmur ended up doing this as well).
Except… I wrote all this, spent a couple of hours getting everything working, and then somehow, by having moved the callback function for shortcuts into the Rust code (where I previously was trying it from the frontend in TypeScript), it… WORKS?! With the default Tauri plugin, which is only supposed to work on X11.
This requires some more testing (is this a KDE Plasma specific thing?! or Xwayland??), so I’m keeping the keys module I made around for now just in case.
The good news is that this means it works! The really only last two bits I need are Windows support and saving the config.
Should this have taken this long? Probably not. I attribute that to still wandering my way through Rust and literally never having used Tauri before (lol). A good amount of time was spent getting the UI working in a way that I was happy with, too!
With that said, here’s a quick recording of everything working!
This is my first time using Tauri! As I’ve learned with a previous project, UI and Rust are still a bit iffy, sadly.
Tauri effectively parallels Electron while offering much better performance, especially as you still use Rust for the backend while allowing the ease of use of HTML + CSS + JS/TS for the frontend! It uses native WebViews instead of Chromium, which gets rid of one of my biggest frustrations with Electron, that being including and running a whole browser for what’s often a single page.
Of course, this is, uh, maybe is not the best project to showcase how great those features are considering there is effectively one (1) main feature here (lol), but this is a learning experience and an excuse to continue more Rust!
I’m adding UI because running from the terminal is not the best UX, and this will make it easier to change the config (which you couldn’t do before after starting!) and handle everything more gracefully.
I will say that, so far, the developer experience with Tauri has felt great. Automatic hot reloading is enabled by default on both the TypeScript frontend AND the Rust backend (which will auto-rebuild), super neat! Getting everything set up with Nix was… less great, but not Tauri’s fault.
I also chose to use React for this project, as it’s been quite some time since I’ve really worked with it.
Oh, yeah, also I made a logo in Aseprite! I mainly needed this for a tray icon. Modeled after the one and only Logitech C920 PRO HD Webcam, with its glorious (read as: bad (read as: loud = funny)) microphone.
Now that the project has been refactored for Tauri, I need to port the old code to the new “backend”. I’ll build the config UI around this once that’s done!
Also, Tauri actually has a global shortcut plugin, so I can replace rdev with this for a (hopefully) less janky handling system.
(it’s awfully hard to find info about global key handling, probably because that’s misused for malware more often than not…)
I almost forgot I was going to make this! I made an initial prototype for funnymic, which (for now, at least) is a CLI tool to hot swap to a microphone only when holding down a key (like a very, very bad and comically loud C922 webcam mic, perhaps lol).
This initial prototype only works on Linux. My TODO is to
This also is an excuse for me to learn more Rust! I’m likely going to work on most projects in Rust to continue learning (when it makes sense).