Skip to content

Instantly share code, notes, and snippets.

@maxkueng
Last active August 29, 2015 14:24
Show Gist options
  • Save maxkueng/5a17b848d152442b9f4d to your computer and use it in GitHub Desktop.
Save maxkueng/5a17b848d152442b9f4d to your computer and use it in GitHub Desktop.
Electron online / offline test

Electron online / offline test

npm install
npm start
var app = require('app');
var BrowserWindow = require('browser-window');
var onlineStatusWindow;
app.on('ready', function() {
onlineStatusWindow = new BrowserWindow({ width: 800, height: 600, show: true });
onlineStatusWindow.loadUrl('file://' + __dirname + '/online-status.html');
});
<!DOCTYPE html>
<html>
<body>
<script>
var alertOnlineStatus = function() {
window.alert(navigator.onLine ? 'online' : 'offline');
};
window.addEventListener('online', alertOnlineStatus);
window.addEventListener('offline', alertOnlineStatus);
alertOnlineStatus();
</script>
</body>
</html>
{
"name": "electron-onlineoffline",
"version": "1.0.0",
"main": "main.js",
"scripts": {
"start": "electron ./"
},
"devDependencies": {
"electron-prebuilt": "0.28.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment