laurencee / Livestream.Monitor

A windows GUI for livestreamer/streamlink
GNU General Public License v2.0
60 stars 8 forks source link

[QoL] Make chat popout work with any browser? #27

Closed Tharn closed 7 years ago

Tharn commented 7 years ago

Hi again,

Popouts are generally pretty easy to do, all you need is to call the browser with an URL reading https://www.twitch.tv/channel_goes_here/chat?popout= in the case of Twitch, or http://www.hitbox.tv/embedchat/channel_goes_here?autoconnect=true for Hitbox. I don't know the others, but I assume the restriction to Chrome mostly has to do with fancy pop-out resizing and stuff?

It'd be handy to have it just call the default handler for http, if possible. Or having that as a fallback for people not using Chrome.

laurencee commented 7 years ago

Yeah the only reason it was setup for chrome was due to the resizing commands. Something to look into for sure.

laurencee commented 7 years ago

If you just launch the URL directly through the process it'll open in chrome as if it was just another tab and I presume it'll do the same for the other browsers which isn't desirable.

The other reason was being able to tell chrome to open in a separate window without showing the url bar through the --app command.

The "?popout=true" part of the url (the query string) just gives twitch extra information for how chat should function, that's not actually what makes it a popup. The popup is created because of javascript associated with the popout button on the twitch page.

I played around with launching a html file which would create the popup but the problem with that is because the popup doesn't originate from a user action (clicking a button on the page) the browsers block the popup.

const string chatFileName = "chat.html";
string chatFileContents = "<html><head/><body><script>" +
                            $"var win = window.open('{livestreamModel.ChatUrl}', '_blank','height=800,width=400,menubar=no,location=no,toolbar=no,left=100,top=100');" +
                            "if (win != null) window.close()" +
                            "</script></body></html>";
File.WriteAllText(chatFileName, chatFileContents);

Process.Start(chatFileName);
laurencee commented 7 years ago

It might be easier to just support the most common set of browsers people use (Chrome/IE/Firefox/Safari/Edge) and set launch parameters for them like I do with chrome currently. I doubt those launch parameters would have to be updated very often.

Tharn commented 7 years ago

Agreed, that should be fine. I would note though that it's a good idea not to tie these browsers to only one .exe. For Chrome/Chromium it happens to be the same .exe (Iridium?), but for Firefox/Waterfox/Cyberfox/PaleMoon it isn't. IE also has at least one other front-end using the same engine.

laurencee commented 7 years ago

Cheers for the info but it's not really something I'm looking at doing in the near future.

Tharn commented 7 years ago

I'm not seeing the big difference between Browser Path (Firefox) -> Select .exe or Browser Path (Firefox) -> Select firefox.exe... hell, I tried putting palemoon.exe into the input box for the Chrome path and it did -something-. It might just be possible to do this by hand if the user inputs into the text box so that he can select other filenames.

But it's your baby of course. I appreciate the help. ;)

laurencee commented 7 years ago

I need someway to know the type of browser it is so I can apply the correct arguments. Each browser has different switches to do the same thing -app does for chrome.

If I allowed for a *.exe filter on the file selection then an additional option menu would be required to let the app know what type of browser that exe represents.

Tharn commented 7 years ago

Yeah, that's why I meant to suggest something similar to what it is now. You'd basically select Chrome, Firefox, IE or Safari. And then the actual 'Open' dialogue could be accepting any kind of .exe file.

All the different Firefox brands should absolutely accept the same argument passed to them. And if they don't, your ass is covered by the fact that it simply states 'Firefox' in LM. It's just a 'will probably work' for everyone who doesn't use one of these.

laurencee commented 7 years ago

Yeah that'll probably be the plan when I get around to it at some stage :)

Tharn commented 7 years ago

Another thing I noticed. When LM opens Chrome or Chromium, it does not use the command line arguments put into HKEY_CLASSES_ROOT/(browser)/shell/open/command, where .html and various other registered file types link to. Can this be done or does it have to be a custom call?

laurencee commented 7 years ago

There's not much to the chrome args: https://github.com/laurencee/Livestream.Monitor/blob/master/Livestream.Monitor/Model/StreamLauncher.cs#L70

What sort of arguments would come from that registry key that would be useful? Can't say I've seen it before.

Tharn commented 7 years ago

All the commandline args that you can set i.e. for a taskbar shortcut, you can in the ROOT folder to be used when other programs want to open an executable. Such as a mail client pushing an URL to Chrome etc.

Chrome is notoriously tight with customization, which is why some of these can be useful. I use it for custom disk cache & media cache size and location. (http://peter.sh/experiments/chromium-command-line-switches/)

Hmm.. since the chat tab starts its own process anyway, I wonder if there's an easy way to just call it through the .html file association and append the extra arguments for chat sizing.

Anyway, this really would be a comfort feature for me; I don't think a lot of people use command line arguments for Chrome. So if it's at all bothersome to implement, feel free to disregard.

laurencee commented 7 years ago

I'll have to investigate the registry key setup, doesn't sound like that much effort.

Is it just a single registry key with the arguments in it? If so then I'd just read the values and append them to the existing process start call.

Tharn commented 7 years ago

Yeah, it's just the one. But as I understand it they're not identical for Chrome and Chromium. Chromium in my case links to HKEY_CLASSES_ROOT\ChromiumHTM.N6GTCOIMPB7NK2S6RQAOQ3KAFY. HKCR is where various machine and user settings are all gathered together, so it should be the right place to go. Might be easier to go by what .html or the chrome.exe links to rather than figure out the right folder by hand.

The key itself reads by default:

"C:\Users\xxxxxx\AppData\Local\Chromium\Application\chrome.exe" -- "%1"

(https://msdn.microsoft.com/en-us/library/windows/desktop/ms724475(v=vs.85).aspx)

laurencee commented 7 years ago

I was thinking that since this hasn't gone anywhere yet, maybe I can just add support for you to either point at chrome specifically or any other exe and it's up to the user to know that they've pointed to a valid browser that can accept the url as an argument.

This way at least you have chat functionality even if it doesn't resize/fit as nicely as the current chrome app version.

Tharn commented 7 years ago

Yeah, feel free to do that. Like I said, it's a total comfort feature.

laurencee commented 7 years ago

I played around with a few approaches and I think allowing a custom command line entry with some predefined settings for known browsers is a reasonable way to go.

I think it's pretty much good to go, implemented some basic error handling & reporting if the command fails.

If you have the time I would appreciate if you could test it out. (backup your settings.json before using this) Livestream Monitor.2.9.6 (DEBUG).zip

Tharn commented 7 years ago

It seems to work fine; tried with Palemoon Portable and Chromium. Palemoon created a full tab, Chromium created a pop-out. Chromium also created Cache directories, so I assume the HKEY_CLASSES_ROOT thing was a bit too involved after all.

I found "ChatCommandLine": "\"C:\\Users\\XXXXXX\\AppData\\Local\\Chromium\\Application\\chrome.exe\" --app={url} --window-size=350 -height=760", in settings.json. I appended my command line flags manually which solved this for me.

laurencee commented 7 years ago

Cheers, you can actually do that change in the settings page directly. The chat command line text box is freely editable with whatever you want, the buttons are just there to have nice presets for common browsers.

laurencee commented 7 years ago

Thanks for testing, I'll get a release out in the next day or so.

laurencee commented 7 years ago

https://github.com/laurencee/Livestream.Monitor/releases/tag/2.9.6