walfie / streamdeck-youtube-emotes

Generate Stream Deck profiles with YouTube membership emote keys
3 stars 0 forks source link

Support `--restart` flag on Windows #1

Open walfie opened 3 years ago

walfie commented 3 years ago

I originally tried to implement this on Windows but wasn't able to get it working well. Closing the Stream Deck application works fine with Command::new("taskkill").args(&["/f", "/im", "StreamDeck.exe"]).status(), but reopening it had issues.


Doing it this way causes the CLI command to hang since it waits for StreamDeck.exe to return: https://github.com/walfie/streamdeck-youtube-emotes/blob/3e527e567a1f4ed0ae835b63bd48e53c06217361/src/main.rs#L242

Doing it this way causes the error Windows cannot find 'C:\Program': https://github.com/walfie/streamdeck-youtube-emotes/blob/106f0f77b55a662c7ea7e12e16a6e42fc391f370/src/main.rs#L199-L201

Adding quotes around it doesn't work either (I guess it includes the quotes as part of the path?) https://github.com/walfie/streamdeck-youtube-emotes/blob/2a60a0c1ba4840b19aea19c8d96230921df50d1a/src/main.rs#L241-L243

Looks like it's related to a longstanding issue regarding escaping in Windows commands: https://github.com/rust-lang/rust/issues/29494 (The fix is only available on nightly)

A proposed workaround (that works on stable rust) is to use some Windows-specific functions, but I don't have a Windows device to test on, and this flag is just a "nice to have" (the user can just close and reopen the application themselves) so I'll leave this one to someone else who wants to send a PR for it.

walfie commented 3 years ago

Another workaround is to have the CLI tool write a batch script that has the appropriate stop/start commands, and then execute that instead, but it feels very hacky