creyD
creyD

Reputation: 2126

Detect internet connection in Electron

Our Electron app needs some configuration files and usually downloads them from our server. In case the client is offline, we don't want him to see any error messages. We are using Electron Download Manager to get the files.

This is how we request the files

try{
    DownloadManager.bulkDownload({
        urls: links
    }, function (error, finished, errors) {
        if (error) {
            console.log("ERROR: Encountered error during config file download!");
            console.log("Finished Files: " + finished);
            console.log("Errors: " + errors);
            return;
        }
        console.log("Finished loading all configuration files.");
    });
} catch (err){
    online_status = false;
    console.log("Couldn't get online configuration. Starting app as offline.");
}

With this code the error Uncaught Exception: Error: net::ERR_ADDRESS_UNREACHABLE is thrown, when not connected to the internet.

I tried implementing the official event detection from Electron but as they state:

Such as in cases where the computer is running a virtualization software that has virtual ethernet adapters that are always “connected.” Therefore, if you really want to determine the internet access status of Electron, you should develop additional means for checking.

Then I went on trying just to ping the server like in this thread but this doesn't work at all for me, it's possible that it doesn't work anymore.

Upvotes: 1

Views: 2176

Answers (1)

Rodigor
Rodigor

Reputation: 26

This is a bug in Electron Download Manager, documented in an GitHub Issue like @JeffRSon stated. A pull request is ready for a merge but not merged yet (posted 06.06.2019).

I hope this helps you. I will update this question if it get's merged and works.

Upvotes: 1

Related Questions