/** * Script for landing.ejs */ // Requirements const cp = require('child_process') const crypto = require('crypto') const { URL } = require('url') // Internal Requirements const DiscordWrapper = require('./assets/js/discordwrapper') const Mojang = require('./assets/js/mojang') const ProcessBuilder = require('./assets/js/processbuilder') const ServerStatus = require('./assets/js/serverstatus') // Launch Elements const launch_content = document.getElementById('launch_content') const launch_details = document.getElementById('launch_details') const launch_progress = document.getElementById('launch_progress') const launch_progress_label = document.getElementById('launch_progress_label') const launch_details_text = document.getElementById('launch_details_text') const server_selection_button = document.getElementById('server_selection_button') const user_text = document.getElementById('user_text') const loggerLanding = LoggerUtil('%c[Landing]', 'color: #000668; font-weight: bold') /* 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) } /** * Enable or disable the launch button. * * @param {boolean} val True to enable, false to disable. */ function setLaunchEnabled(val) { document.getElementById('launch_button').disabled = !val } // Bind launch button document.getElementById('launch_button').addEventListener('click', function (e) { loggerLanding.log('Launching game..') const mcVersion = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer()).getMinecraftVersion() const jExe = ConfigManager.getJavaExecutable() if (jExe == null) { asyncSystemScan(mcVersion) } else { setLaunchDetails(Lang.queryJS('landing.launch.pleaseWait')) toggleLaunchArea(true) setLaunchPercentage(0, 100) const jg = new JavaGuard(mcVersion) jg._validateJavaBinary(jExe).then((v) => { loggerLanding.log('Java version meta', v) if (v.valid) { dlAsync() } else { asyncSystemScan(mcVersion) } }) } }) // Bind settings button document.getElementById('settingsMediaButton').onclick = (e) => { prepareSettings() switchView(getCurrentView(), VIEWS.settings) } // Bind avatar overlay button. document.getElementById('avatarOverlay').onclick = (e) => { prepareSettings() switchView(getCurrentView(), VIEWS.settings, 500, 500, () => { settingsNavItemListener(document.getElementById('settingsNavAccount'), false) }) } // Bind selected account function updateSelectedAccount(authUser) { let username = 'No Account Selected' if (authUser != null) { if (authUser.displayName != null) { username = authUser.displayName } if (authUser.uuid != null) { document.getElementById('avatarContainer').style.backgroundImage = `url('https://mc-heads.net/body/${authUser.uuid}/right')` } } user_text.innerHTML = username } updateSelectedAccount(ConfigManager.getSelectedAccount()) // Bind selected server function updateSelectedServer(serv) { if (getCurrentView() === VIEWS.settings) { saveAllModConfigurations() } ConfigManager.setSelectedServer(serv != null ? serv.getID() : null) ConfigManager.save() server_selection_button.innerHTML = '\u2022 ' + (serv != null ? serv.getName() : 'No Server Selected') if (getCurrentView() === VIEWS.settings) { animateModsTabRefresh() } setLaunchEnabled(serv != null) } // Real text is set in uibinder.js on distributionIndexDone. server_selection_button.innerHTML = '\u2022 Loading..' server_selection_button.onclick = (e) => { e.target.blur() toggleServerSelection(true) } // Update Mojang Status Color const refreshMojangStatuses = async function () { loggerLanding.log('Refreshing Mojang Statuses..') let status = 'grey' let tooltipEssentialHTML = '' let tooltipNonEssentialHTML = '' try { const statuses = await Mojang.status() greenCount = 0 greyCount = 0 for (let i = 0; i < statuses.length; i++) { const service = statuses[i] if (service.essential) { tooltipEssentialHTML += `