hmlendea / gfn-electron

Linux Desktop client for Nvidia's GeForce NOW game streaming service
GNU General Public License v3.0
500 stars 62 forks source link

Error: Unsupported Device/Browser #70

Closed szarekpl closed 2 years ago

szarekpl commented 2 years ago

The program has stopped working. Probably because of the old version of chromium.

hmlendea commented 2 years ago

I'm on holiday right now and am unable to look into it properly. I tried quickly updating to the latest electron version but it's still broken.

hmlendea commented 2 years ago

I've taken a closer look today and I still haven't figured out what's going on. GFN simply refuses to work when it's run through electron.

I'll hopefully be able to figure it out once I'm back from holiday. In the meantime, anyone is welcome to take a look and submit a fix if they figure it out and I'll review+merge it.

My work so far is on the electron-update branch (#72), but it's not much.

IgorKvasn commented 2 years ago

Hi, I got hooked up on Far Cry 5, so I need this issue to be fixed ASAP :D

After some digging (in uglified JS code :vomiting_face: ) I found out, that GFN is detecting browsers using this code:

 const r = window.speechSynthesis;
let i;
i = r ? (null === (n = r.getVoices) || void 0 === n ? void 0 : n.call(r)) || [] : t;
for (const o of i)
    (t = o.voiceURI || "").startsWith("Chrome OS") ? e.gb = !0 : t.startsWith("Google") ? e.fb = !0 : 
    t.startsWith("Microsoft") ? e.s = !0 : t.includes("moz-tts") ? (t.includes("android") && (e.jb = !0, 
    e.ha = !0), e.ib = !0) : t.startsWith("com.apple") && (e.L = !0), t.includes("Microsoft") ? e.s = !0 : 
    t.includes("com.apple") ? e.L = !0 : "English United States" == t && (e.eb = !0)
}

basically what it does it that it retrieves window.speechSynthesis.getVoices() - the result of this function should look like this (result from Google Chrome in Linux): image Result of this function is then checks for voiceURI and determines if it is Google, Microsoft,.... (no fussing around - simple .startsWith("Google") does the trick)

Then later in the code this is used to determine the browser itself - Chrome, Safari, Android,... (btw there is an explicit check that if you are running Edge, the browser will be unsupported no matter what :)

The problem is that it seems that Electron on one hand supports speechSynthesis API, but it returns an empty array - that means, that GFN is unable to detect underlying OS and browser

The way I see it, there are 2 possibilities to fix it:

  1. it looks like it is possible to make Electron support speechSyntesis by installing espeak package

  2. somehow monkeypatch window.speechSynthesis.getVoices() to make it return the "correct" result:

    // run this code... very soon after page load :) before GFN does its browser detection
    let oiginalVoices = window.speechSynthesis.getVoices();
    window.speechSynthesis.getVoices = function () {
     return [
       {
         voiceURI: "Google US English", //<--------- pretend we are in Google Chrome
         name: "Google US English",
         lang: "en-US",
         localService: false,
         default: false,
       },
     ];
    };
    
    // and then when GFN is done with browser detection, revert our changes
    window.speechSynthesis.getVoices = function () {
     return oiginalVoices;
    };

However first solution may not work at all, because we need to make sure voiceURI contains "Google" string, which I guess espeak won't do... And also forcing people to install any additional packages is not very nice

The problem with second solution is that I am not sure if it's even possible in Electron. I have zero experience with Electron, so I would appreciate your help - is it possible to run JS code right after mainWindow.loadURL("https://play.geforcenow.com");? Yes, I know... I guess I can google it, but it's getting late, I am tired and I spent last hour reading very ugly uglified JS code :D Also you might think of some more elegant solution :)

IgorKvasn commented 2 years ago

disregard my question at the end - I created a PR that fixes this issue

hmlendea commented 2 years ago

This is a great find! Thanks a lot for the help! I'm building the new version right now.