2018-04-25 14:40:46 -07:00
|
|
|
// Requirements
|
|
|
|
const path = require('path')
|
2017-12-02 21:38:22 -08:00
|
|
|
const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js'))
|
2018-01-18 20:45:50 -08:00
|
|
|
|
2017-12-03 04:05:13 -08:00
|
|
|
// Synchronous Listener
|
2017-11-30 00:00:06 -08:00
|
|
|
document.addEventListener('readystatechange', function(){
|
2018-04-02 13:05:48 -07:00
|
|
|
|
|
|
|
if (document.readyState === 'complete'){
|
|
|
|
if(ConfigManager.isFirstLaunch()){
|
|
|
|
$('#welcomeContainer').fadeIn(500)
|
|
|
|
} else {
|
|
|
|
$('#landingContainer').fadeIn(500)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-25 14:51:10 -07:00
|
|
|
/*if (document.readyState === 'interactive'){
|
2018-04-25 14:40:46 -07:00
|
|
|
|
2018-04-25 14:51:10 -07:00
|
|
|
}*/
|
2017-11-30 00:00:06 -08:00
|
|
|
}, false)
|
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
/* Overlay Wrapper Functions */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle the visibility of the overlay.
|
|
|
|
*
|
|
|
|
* @param {boolean} toggleState True to display, false to hide.
|
2018-04-14 19:20:59 -07:00
|
|
|
* @param {boolean} dismissable Optional. True to show the dismiss option, otherwise false.
|
2018-04-25 14:06:10 -07:00
|
|
|
* @param {string} content Optional. The content div to be shown.
|
2018-04-06 09:33:20 -07:00
|
|
|
*/
|
2018-04-25 14:06:10 -07:00
|
|
|
function toggleOverlay(toggleState, dismissable = false, content = 'overlayContent'){
|
2018-04-06 09:33:20 -07:00
|
|
|
if(toggleState == null){
|
|
|
|
toggleState = !document.getElementById('main').hasAttribute('overlay')
|
|
|
|
}
|
2018-04-25 14:06:10 -07:00
|
|
|
if(typeof dismissable === 'string'){
|
|
|
|
content = dismissable
|
|
|
|
}
|
2018-04-06 09:33:20 -07:00
|
|
|
if(toggleState){
|
|
|
|
document.getElementById('main').setAttribute('overlay', true)
|
2018-04-25 14:06:10 -07:00
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
|
|
|
$('#overlayContainer').fadeIn(250)
|
2018-04-06 09:33:20 -07:00
|
|
|
} else {
|
|
|
|
document.getElementById('main').removeAttribute('overlay')
|
2018-04-25 14:06:10 -07:00
|
|
|
$('#overlayContainer').fadeOut(250, () => {
|
|
|
|
$('#' + content).parent().children().hide()
|
|
|
|
$('#' + content).show()
|
|
|
|
if(dismissable){
|
|
|
|
$('#overlayDismiss').show()
|
|
|
|
} else {
|
|
|
|
$('#overlayDismiss').hide()
|
|
|
|
}
|
2018-04-14 19:20:59 -07:00
|
|
|
})
|
2018-04-07 10:29:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the content of the overlay.
|
|
|
|
*
|
|
|
|
* @param {string} title Overlay title text.
|
|
|
|
* @param {string} description Overlay description text.
|
|
|
|
* @param {string} acknowledge Acknowledge button text.
|
2018-04-14 19:20:59 -07:00
|
|
|
* @param {string} dismiss Dismiss button text.
|
2018-04-07 10:29:40 -07:00
|
|
|
*/
|
2018-04-14 19:20:59 -07:00
|
|
|
function setOverlayContent(title, description, acknowledge, dismiss = 'Dismiss'){
|
2018-04-07 10:29:40 -07:00
|
|
|
document.getElementById('overlayTitle').innerHTML = title
|
|
|
|
document.getElementById('overlayDesc').innerHTML = description
|
|
|
|
document.getElementById('overlayAcknowledge').innerHTML = acknowledge
|
2018-04-14 19:20:59 -07:00
|
|
|
document.getElementById('overlayDismiss').innerHTML = dismiss
|
2018-04-07 10:29:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the onclick handler of the overlay acknowledge button.
|
|
|
|
* If the handler is null, a default handler will be added.
|
|
|
|
*
|
|
|
|
* @param {function} handler
|
|
|
|
*/
|
|
|
|
function setOverlayHandler(handler){
|
|
|
|
if(handler == null){
|
|
|
|
document.getElementById('overlayAcknowledge').onclick = () => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById('overlayAcknowledge').onclick = handler
|
2018-04-06 09:33:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 19:20:59 -07:00
|
|
|
/**
|
|
|
|
* Set the onclick handler of the overlay dismiss button.
|
|
|
|
* If the handler is null, a default handler will be added.
|
|
|
|
*
|
|
|
|
* @param {function} handler
|
|
|
|
*/
|
|
|
|
function setDismissHandler(handler){
|
|
|
|
if(handler == null){
|
|
|
|
document.getElementById('overlayDismiss').onclick = () => {
|
|
|
|
toggleOverlay(false)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document.getElementById('overlayDismiss').onclick = handler
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-02 15:40:32 -07:00
|
|
|
/* Launch Progress Wrapper Functions */
|
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
/**
|
|
|
|
* Show/hide the loading area.
|
|
|
|
*
|
|
|
|
* @param {boolean} loading True if the loading area should be shown, otherwise false.
|
|
|
|
*/
|
2018-04-02 15:40:32 -07:00
|
|
|
function toggleLaunchArea(loading){
|
|
|
|
if(loading){
|
|
|
|
launch_details.style.display = 'flex'
|
|
|
|
launch_content.style.display = 'none'
|
|
|
|
} else {
|
|
|
|
launch_details.style.display = 'none'
|
|
|
|
launch_content.style.display = 'inline-flex'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
/**
|
|
|
|
* Set the details text of the loading area.
|
|
|
|
*
|
|
|
|
* @param {string} details The new text for the loading details.
|
|
|
|
*/
|
2018-04-02 15:40:32 -07:00
|
|
|
function setLaunchDetails(details){
|
|
|
|
launch_details_text.innerHTML = details
|
|
|
|
}
|
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
/**
|
|
|
|
* Set the value of the loading progress bar and display that value.
|
|
|
|
*
|
|
|
|
* @param {number} value The progress value.
|
|
|
|
* @param {number} max The total size.
|
|
|
|
* @param {number|string} percent Optional. The percentage to display on the progress label.
|
|
|
|
*/
|
2018-04-02 15:40:32 -07:00
|
|
|
function setLaunchPercentage(value, max, percent = ((value/max)*100)){
|
|
|
|
launch_progress.setAttribute('max', max)
|
|
|
|
launch_progress.setAttribute('value', value)
|
|
|
|
launch_progress_label.innerHTML = percent + '%'
|
|
|
|
}
|
|
|
|
|
2018-04-06 09:33:20 -07:00
|
|
|
/**
|
|
|
|
* Set the value of the OS progress bar and display that on the UI.
|
|
|
|
*
|
|
|
|
* @param {number} value The progress value.
|
|
|
|
* @param {number} max The total download size.
|
|
|
|
* @param {number|string} percent Optional. The percentage to display on the progress label.
|
|
|
|
*/
|
2018-04-02 15:40:32 -07:00
|
|
|
function setDownloadPercentage(value, max, percent = ((value/max)*100)){
|
|
|
|
remote.getCurrentWindow().setProgressBar(value/max)
|
|
|
|
setLaunchPercentage(value, max, percent)
|
|
|
|
}
|
|
|
|
|