-
-
Save holgersindbaek/68f6db82f507967a51ca75c527faeff6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="./styles.css"> | |
</head> | |
<body> | |
<div id="topbar"> | |
<p>Solitaire</p> | |
</div> | |
<div id="offline_error"> | |
<p>Solitaire is not available offline.</p> | |
</div> | |
<script> | |
// Function to find parameter | |
const getParams = query => { | |
if (!query) { | |
return { }; | |
} | |
return (/^[?#]/.test(query) ? query.slice(1) : query) | |
.split('&') | |
.reduce((params, param) => { | |
let [key, value] = param.split('='); | |
params[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : ''; | |
return params; | |
}, { }); | |
}; | |
// Add webview | |
const webview = document.createElement('webview'); | |
webview.id = 'webview'; | |
webview.preload = './electronPreload.js'; | |
document.body.appendChild(webview); | |
// Detect if online | |
const loadSite = () => { | |
const offlineElement = document.getElementById('offline_error'); | |
if (navigator.onLine) { | |
webview.src = getParams(window.location.search).environment === 'production' ? 'https://solitairegamecenter.com/klondike?platform=desktop' : 'http://localhost:3000/klondike?platform=desktop'; | |
clearTimeout(onlineCheckTimer); | |
offlineElement.style.display = 'none'; | |
} else { | |
offlineElement.style.display = 'block'; | |
} | |
} | |
const onlineCheckTimer = setInterval(loadSite, 1000); | |
loadSite(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment