1b38629084
Moved landing.ejs specific scripts to a dedicated file. General cleanup for other script files. Need to examine the remaining code in actionbinder.js to determine the most logical place for it.
159 lines
4.8 KiB
JavaScript
159 lines
4.8 KiB
JavaScript
// Requirements
|
|
const path = require('path')
|
|
const ConfigManager = require(path.join(__dirname, 'assets', 'js', 'configmanager.js'))
|
|
|
|
// Synchronous Listener
|
|
document.addEventListener('readystatechange', function(){
|
|
|
|
if (document.readyState === 'complete'){
|
|
if(ConfigManager.isFirstLaunch()){
|
|
$('#welcomeContainer').fadeIn(500)
|
|
} else {
|
|
$('#landingContainer').fadeIn(500)
|
|
}
|
|
}
|
|
|
|
if (document.readyState === 'interactive'){
|
|
|
|
}
|
|
}, false)
|
|
|
|
/* Overlay Wrapper Functions */
|
|
|
|
/**
|
|
* Toggle the visibility of the overlay.
|
|
*
|
|
* @param {boolean} toggleState True to display, false to hide.
|
|
* @param {boolean} dismissable Optional. True to show the dismiss option, otherwise false.
|
|
* @param {string} content Optional. The content div to be shown.
|
|
*/
|
|
function toggleOverlay(toggleState, dismissable = false, content = 'overlayContent'){
|
|
if(toggleState == null){
|
|
toggleState = !document.getElementById('main').hasAttribute('overlay')
|
|
}
|
|
if(typeof dismissable === 'string'){
|
|
content = dismissable
|
|
}
|
|
if(toggleState){
|
|
document.getElementById('main').setAttribute('overlay', true)
|
|
$('#' + content).parent().children().hide()
|
|
$('#' + content).show()
|
|
if(dismissable){
|
|
$('#overlayDismiss').show()
|
|
} else {
|
|
$('#overlayDismiss').hide()
|
|
}
|
|
$('#overlayContainer').fadeIn(250)
|
|
} else {
|
|
document.getElementById('main').removeAttribute('overlay')
|
|
$('#overlayContainer').fadeOut(250, () => {
|
|
$('#' + content).parent().children().hide()
|
|
$('#' + content).show()
|
|
if(dismissable){
|
|
$('#overlayDismiss').show()
|
|
} else {
|
|
$('#overlayDismiss').hide()
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set the content of the overlay.
|
|
*
|
|
* @param {string} title Overlay title text.
|
|
* @param {string} description Overlay description text.
|
|
* @param {string} acknowledge Acknowledge button text.
|
|
* @param {string} dismiss Dismiss button text.
|
|
*/
|
|
function setOverlayContent(title, description, acknowledge, dismiss = 'Dismiss'){
|
|
document.getElementById('overlayTitle').innerHTML = title
|
|
document.getElementById('overlayDesc').innerHTML = description
|
|
document.getElementById('overlayAcknowledge').innerHTML = acknowledge
|
|
document.getElementById('overlayDismiss').innerHTML = dismiss
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
}
|
|
}
|
|
|
|
/* Launch Progress Wrapper Functions */
|
|
|
|
/**
|
|
* Show/hide the loading area.
|
|
*
|
|
* @param {boolean} loading True if the loading area should be shown, otherwise false.
|
|
*/
|
|
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'
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set the details text of the loading area.
|
|
*
|
|
* @param {string} details The new text for the loading details.
|
|
*/
|
|
function setLaunchDetails(details){
|
|
launch_details_text.innerHTML = details
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
function setLaunchPercentage(value, max, percent = ((value/max)*100)){
|
|
launch_progress.setAttribute('max', max)
|
|
launch_progress.setAttribute('value', value)
|
|
launch_progress_label.innerHTML = percent + '%'
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
function setDownloadPercentage(value, max, percent = ((value/max)*100)){
|
|
remote.getCurrentWindow().setProgressBar(value/max)
|
|
setLaunchPercentage(value, max, percent)
|
|
}
|
|
|