settings.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  1. // Requirements
  2. const os = require('os')
  3. const semver = require('semver')
  4. const { AssetGuard } = require('./assets/js/assetguard')
  5. const DropinModUtil = require('./assets/js/dropinmodutil')
  6. const settingsState = {
  7. invalid: new Set()
  8. }
  9. function bindSettingsSelect(){
  10. for(let ele of document.getElementsByClassName('settingsSelectContainer')) {
  11. const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0]
  12. selectedDiv.onclick = (e) => {
  13. e.stopPropagation()
  14. closeSettingsSelect(e.target)
  15. e.target.nextElementSibling.toggleAttribute('hidden')
  16. e.target.classList.toggle('select-arrow-active')
  17. }
  18. }
  19. }
  20. function closeSettingsSelect(el){
  21. for(let ele of document.getElementsByClassName('settingsSelectContainer')) {
  22. const selectedDiv = ele.getElementsByClassName('settingsSelectSelected')[0]
  23. const optionsDiv = ele.getElementsByClassName('settingsSelectOptions')[0]
  24. if(!(selectedDiv === el)) {
  25. selectedDiv.classList.remove('select-arrow-active')
  26. optionsDiv.setAttribute('hidden', '')
  27. }
  28. }
  29. }
  30. /* If the user clicks anywhere outside the select box,
  31. then close all select boxes: */
  32. document.addEventListener('click', closeSettingsSelect)
  33. bindSettingsSelect()
  34. /**
  35. * General Settings Functions
  36. */
  37. /**
  38. * Bind value validators to the settings UI elements. These will
  39. * validate against the criteria defined in the ConfigManager (if
  40. * and). If the value is invalid, the UI will reflect this and saving
  41. * will be disabled until the value is corrected. This is an automated
  42. * process. More complex UI may need to be bound separately.
  43. */
  44. function initSettingsValidators(){
  45. const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
  46. Array.from(sEls).map((v, index, arr) => {
  47. const vFn = ConfigManager['validate' + v.getAttribute('cValue')]
  48. if(typeof vFn === 'function'){
  49. if(v.tagName === 'INPUT'){
  50. if(v.type === 'number' || v.type === 'text'){
  51. v.addEventListener('keyup', (e) => {
  52. const v = e.target
  53. if(!vFn(v.value)){
  54. settingsState.invalid.add(v.id)
  55. v.setAttribute('error', '')
  56. settingsSaveDisabled(true)
  57. } else {
  58. if(v.hasAttribute('error')){
  59. v.removeAttribute('error')
  60. settingsState.invalid.delete(v.id)
  61. if(settingsState.invalid.size === 0){
  62. settingsSaveDisabled(false)
  63. }
  64. }
  65. }
  66. })
  67. }
  68. }
  69. }
  70. })
  71. }
  72. /**
  73. * Load configuration values onto the UI. This is an automated process.
  74. */
  75. function initSettingsValues(){
  76. const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
  77. Array.from(sEls).map((v, index, arr) => {
  78. const cVal = v.getAttribute('cValue')
  79. const gFn = ConfigManager['get' + cVal]
  80. if(typeof gFn === 'function'){
  81. if(v.tagName === 'INPUT'){
  82. if(v.type === 'number' || v.type === 'text'){
  83. // Special Conditions
  84. if(cVal === 'JavaExecutable'){
  85. populateJavaExecDetails(v.value)
  86. v.value = gFn()
  87. } else if(cVal === 'JVMOptions'){
  88. v.value = gFn().join(' ')
  89. } else {
  90. v.value = gFn()
  91. }
  92. } else if(v.type === 'checkbox'){
  93. v.checked = gFn()
  94. }
  95. } else if(v.tagName === 'DIV'){
  96. if(v.classList.contains('rangeSlider')){
  97. // Special Conditions
  98. if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
  99. let val = gFn()
  100. if(val.endsWith('M')){
  101. val = Number(val.substring(0, val.length-1))/1000
  102. } else {
  103. val = Number.parseFloat(val)
  104. }
  105. v.setAttribute('value', val)
  106. } else {
  107. v.setAttribute('value', Number.parseFloat(gFn()))
  108. }
  109. }
  110. }
  111. }
  112. })
  113. }
  114. /**
  115. * Save the settings values.
  116. */
  117. function saveSettingsValues(){
  118. const sEls = document.getElementById('settingsContainer').querySelectorAll('[cValue]')
  119. Array.from(sEls).map((v, index, arr) => {
  120. const cVal = v.getAttribute('cValue')
  121. const sFn = ConfigManager['set' + cVal]
  122. if(typeof sFn === 'function'){
  123. if(v.tagName === 'INPUT'){
  124. if(v.type === 'number' || v.type === 'text'){
  125. // Special Conditions
  126. if(cVal === 'JVMOptions'){
  127. sFn(v.value.split(' '))
  128. } else {
  129. sFn(v.value)
  130. }
  131. } else if(v.type === 'checkbox'){
  132. sFn(v.checked)
  133. // Special Conditions
  134. if(cVal === 'AllowPrerelease'){
  135. changeAllowPrerelease(v.checked)
  136. }
  137. }
  138. } else if(v.tagName === 'DIV'){
  139. if(v.classList.contains('rangeSlider')){
  140. // Special Conditions
  141. if(cVal === 'MinRAM' || cVal === 'MaxRAM'){
  142. let val = Number(v.getAttribute('value'))
  143. if(val%1 > 0){
  144. val = val*1000 + 'M'
  145. } else {
  146. val = val + 'G'
  147. }
  148. sFn(val)
  149. } else {
  150. sFn(v.getAttribute('value'))
  151. }
  152. }
  153. }
  154. }
  155. })
  156. }
  157. let selectedSettingsTab = 'settingsTabAccount'
  158. /**
  159. * Modify the settings container UI when the scroll threshold reaches
  160. * a certain poin.
  161. *
  162. * @param {UIEvent} e The scroll event.
  163. */
  164. function settingsTabScrollListener(e){
  165. if(e.target.scrollTop > Number.parseFloat(getComputedStyle(e.target.firstElementChild).marginTop)){
  166. document.getElementById('settingsContainer').setAttribute('scrolled', '')
  167. } else {
  168. document.getElementById('settingsContainer').removeAttribute('scrolled')
  169. }
  170. }
  171. /**
  172. * Bind functionality for the settings navigation items.
  173. */
  174. function setupSettingsTabs(){
  175. Array.from(document.getElementsByClassName('settingsNavItem')).map((val) => {
  176. if(val.hasAttribute('rSc')){
  177. val.onclick = () => {
  178. settingsNavItemListener(val)
  179. }
  180. }
  181. })
  182. }
  183. /**
  184. * Settings nav item onclick lisener. Function is exposed so that
  185. * other UI elements can quickly toggle to a certain tab from other views.
  186. *
  187. * @param {Element} ele The nav item which has been clicked.
  188. * @param {boolean} fade Optional. True to fade transition.
  189. */
  190. function settingsNavItemListener(ele, fade = true){
  191. if(ele.hasAttribute('selected')){
  192. return
  193. }
  194. const navItems = document.getElementsByClassName('settingsNavItem')
  195. for(let i=0; i<navItems.length; i++){
  196. if(navItems[i].hasAttribute('selected')){
  197. navItems[i].removeAttribute('selected')
  198. }
  199. }
  200. ele.setAttribute('selected', '')
  201. let prevTab = selectedSettingsTab
  202. selectedSettingsTab = ele.getAttribute('rSc')
  203. document.getElementById(prevTab).onscroll = null
  204. document.getElementById(selectedSettingsTab).onscroll = settingsTabScrollListener
  205. if(fade){
  206. $(`#${prevTab}`).fadeOut(250, () => {
  207. $(`#${selectedSettingsTab}`).fadeIn({
  208. duration: 250,
  209. start: () => {
  210. settingsTabScrollListener({
  211. target: document.getElementById(selectedSettingsTab)
  212. })
  213. }
  214. })
  215. })
  216. } else {
  217. $(`#${prevTab}`).hide(0, () => {
  218. $(`#${selectedSettingsTab}`).show({
  219. duration: 0,
  220. start: () => {
  221. settingsTabScrollListener({
  222. target: document.getElementById(selectedSettingsTab)
  223. })
  224. }
  225. })
  226. })
  227. }
  228. }
  229. const settingsNavDone = document.getElementById('settingsNavDone')
  230. /**
  231. * Set if the settings save (done) button is disabled.
  232. *
  233. * @param {boolean} v True to disable, false to enable.
  234. */
  235. function settingsSaveDisabled(v){
  236. settingsNavDone.disabled = v
  237. }
  238. /* Closes the settings view and saves all data. */
  239. settingsNavDone.onclick = () => {
  240. saveSettingsValues()
  241. saveModConfiguration()
  242. ConfigManager.save()
  243. saveDropinModConfiguration()
  244. switchView(getCurrentView(), VIEWS.landing)
  245. }
  246. /**
  247. * Account Management Tab
  248. */
  249. // Bind the add account button.
  250. document.getElementById('settingsAddAccount').onclick = (e) => {
  251. switchView(getCurrentView(), VIEWS.login, 500, 500, () => {
  252. loginViewOnCancel = VIEWS.settings
  253. loginViewOnSuccess = VIEWS.settings
  254. loginCancelEnabled(true)
  255. })
  256. }
  257. /**
  258. * Bind functionality for the account selection buttons. If another account
  259. * is selected, the UI of the previously selected account will be updated.
  260. */
  261. function bindAuthAccountSelect(){
  262. Array.from(document.getElementsByClassName('settingsAuthAccountSelect')).map((val) => {
  263. val.onclick = (e) => {
  264. if(val.hasAttribute('selected')){
  265. return
  266. }
  267. const selectBtns = document.getElementsByClassName('settingsAuthAccountSelect')
  268. for(let i=0; i<selectBtns.length; i++){
  269. if(selectBtns[i].hasAttribute('selected')){
  270. selectBtns[i].removeAttribute('selected')
  271. selectBtns[i].innerHTML = 'Select Account'
  272. }
  273. }
  274. val.setAttribute('selected', '')
  275. val.innerHTML = 'Selected Account &#10004;'
  276. setSelectedAccount(val.closest('.settingsAuthAccount').getAttribute('uuid'))
  277. }
  278. })
  279. }
  280. /**
  281. * Bind functionality for the log out button. If the logged out account was
  282. * the selected account, another account will be selected and the UI will
  283. * be updated accordingly.
  284. */
  285. function bindAuthAccountLogOut(){
  286. Array.from(document.getElementsByClassName('settingsAuthAccountLogOut')).map((val) => {
  287. val.onclick = (e) => {
  288. let isLastAccount = false
  289. if(Object.keys(ConfigManager.getAuthAccounts()).length === 1){
  290. isLastAccount = true
  291. setOverlayContent(
  292. 'Warning<br>This is Your Last Account',
  293. 'In order to use the launcher you must be logged into at least one account. You will need to login again after.<br><br>Are you sure you want to log out?',
  294. 'I\'m Sure',
  295. 'Cancel'
  296. )
  297. setOverlayHandler(() => {
  298. processLogOut(val, isLastAccount)
  299. toggleOverlay(false)
  300. switchView(getCurrentView(), VIEWS.login)
  301. })
  302. setDismissHandler(() => {
  303. toggleOverlay(false)
  304. })
  305. toggleOverlay(true, true)
  306. } else {
  307. processLogOut(val, isLastAccount)
  308. }
  309. }
  310. })
  311. }
  312. /**
  313. * Process a log out.
  314. *
  315. * @param {Element} val The log out button element.
  316. * @param {boolean} isLastAccount If this logout is on the last added account.
  317. */
  318. function processLogOut(val, isLastAccount){
  319. const parent = val.closest('.settingsAuthAccount')
  320. const uuid = parent.getAttribute('uuid')
  321. const prevSelAcc = ConfigManager.getSelectedAccount()
  322. AuthManager.removeAccount(uuid).then(() => {
  323. if(!isLastAccount && uuid === prevSelAcc.uuid){
  324. const selAcc = ConfigManager.getSelectedAccount()
  325. refreshAuthAccountSelected(selAcc.uuid)
  326. updateSelectedAccount(selAcc)
  327. validateSelectedAccount()
  328. }
  329. })
  330. $(parent).fadeOut(250, () => {
  331. parent.remove()
  332. })
  333. }
  334. /**
  335. * Refreshes the status of the selected account on the auth account
  336. * elements.
  337. *
  338. * @param {string} uuid The UUID of the new selected account.
  339. */
  340. function refreshAuthAccountSelected(uuid){
  341. Array.from(document.getElementsByClassName('settingsAuthAccount')).map((val) => {
  342. const selBtn = val.getElementsByClassName('settingsAuthAccountSelect')[0]
  343. if(uuid === val.getAttribute('uuid')){
  344. selBtn.setAttribute('selected', '')
  345. selBtn.innerHTML = 'Selected Account &#10004;'
  346. } else {
  347. if(selBtn.hasAttribute('selected')){
  348. selBtn.removeAttribute('selected')
  349. }
  350. selBtn.innerHTML = 'Select Account'
  351. }
  352. })
  353. }
  354. const settingsCurrentAccounts = document.getElementById('settingsCurrentAccounts')
  355. /**
  356. * Add auth account elements for each one stored in the authentication database.
  357. */
  358. function populateAuthAccounts(){
  359. const authAccounts = ConfigManager.getAuthAccounts()
  360. const authKeys = Object.keys(authAccounts)
  361. if(authKeys.length === 0){
  362. return
  363. }
  364. const selectedUUID = ConfigManager.getSelectedAccount().uuid
  365. let authAccountStr = ''
  366. authKeys.map((val) => {
  367. const acc = authAccounts[val]
  368. authAccountStr += `<div class="settingsAuthAccount" uuid="${acc.uuid}">
  369. <div class="settingsAuthAccountLeft">
  370. <img class="settingsAuthAccountImage" alt="${acc.displayName}" src="https://crafatar.com/renders/body/${acc.uuid}?scale=3&default=MHF_Steve&overlay">
  371. </div>
  372. <div class="settingsAuthAccountRight">
  373. <div class="settingsAuthAccountDetails">
  374. <div class="settingsAuthAccountDetailPane">
  375. <div class="settingsAuthAccountDetailTitle">Username</div>
  376. <div class="settingsAuthAccountDetailValue">${acc.displayName}</div>
  377. </div>
  378. <div class="settingsAuthAccountDetailPane">
  379. <div class="settingsAuthAccountDetailTitle">UUID</div>
  380. <div class="settingsAuthAccountDetailValue">${acc.uuid}</div>
  381. </div>
  382. </div>
  383. <div class="settingsAuthAccountActions">
  384. <button class="settingsAuthAccountSelect" ${selectedUUID === acc.uuid ? 'selected>Selected Account &#10004;' : '>Select Account'}</button>
  385. <div class="settingsAuthAccountWrapper">
  386. <button class="settingsAuthAccountLogOut">Log Out</button>
  387. </div>
  388. </div>
  389. </div>
  390. </div>`
  391. })
  392. settingsCurrentAccounts.innerHTML = authAccountStr
  393. }
  394. /**
  395. * Prepare the accounts tab for display.
  396. */
  397. function prepareAccountsTab() {
  398. populateAuthAccounts()
  399. bindAuthAccountSelect()
  400. bindAuthAccountLogOut()
  401. }
  402. /**
  403. * Minecraft Tab
  404. */
  405. /**
  406. * Disable decimals, negative signs, and scientific notation.
  407. */
  408. document.getElementById('settingsGameWidth').addEventListener('keydown', (e) => {
  409. if(/^[-.eE]$/.test(e.key)){
  410. e.preventDefault()
  411. }
  412. })
  413. document.getElementById('settingsGameHeight').addEventListener('keydown', (e) => {
  414. if(/^[-.eE]$/.test(e.key)){
  415. e.preventDefault()
  416. }
  417. })
  418. /**
  419. * Mods Tab
  420. */
  421. const settingsModsContainer = document.getElementById('settingsModsContainer')
  422. /**
  423. * Resolve and update the mods on the UI.
  424. */
  425. function resolveModsForUI(){
  426. const serv = ConfigManager.getSelectedServer()
  427. const distro = DistroManager.getDistribution()
  428. const servConf = ConfigManager.getModConfiguration(serv)
  429. const modStr = parseModulesForUI(distro.getServer(serv).getModules(), false, servConf.mods)
  430. document.getElementById('settingsReqModsContent').innerHTML = modStr.reqMods
  431. document.getElementById('settingsOptModsContent').innerHTML = modStr.optMods
  432. }
  433. /**
  434. * Recursively build the mod UI elements.
  435. *
  436. * @param {Object[]} mdls An array of modules to parse.
  437. * @param {boolean} submodules Whether or not we are parsing submodules.
  438. * @param {Object} servConf The server configuration object for this module level.
  439. */
  440. function parseModulesForUI(mdls, submodules, servConf){
  441. let reqMods = ''
  442. let optMods = ''
  443. for(const mdl of mdls){
  444. if(mdl.getType() === DistroManager.Types.ForgeMod || mdl.getType() === DistroManager.Types.LiteMod || mdl.getType() === DistroManager.Types.LiteLoader){
  445. if(mdl.getRequired().isRequired()){
  446. reqMods += `<div id="${mdl.getVersionlessID()}" class="settingsBaseMod settings${submodules ? 'Sub' : ''}Mod" enabled>
  447. <div class="settingsModContent">
  448. <div class="settingsModMainWrapper">
  449. <div class="settingsModStatus"></div>
  450. <div class="settingsModDetails">
  451. <span class="settingsModName">${mdl.getName()}</span>
  452. <span class="settingsModVersion">v${mdl.getVersion()}</span>
  453. </div>
  454. </div>
  455. <label class="toggleSwitch" reqmod>
  456. <input type="checkbox" checked>
  457. <span class="toggleSwitchSlider"></span>
  458. </label>
  459. </div>
  460. ${mdl.hasSubModules() ? `<div class="settingsSubModContainer">
  461. ${Object.values(parseModulesForUI(mdl.getSubModules(), true, servConf[mdl.getVersionlessID()])).join('')}
  462. </div>` : ''}
  463. </div>`
  464. } else {
  465. const conf = servConf[mdl.getVersionlessID()]
  466. const val = typeof conf === 'object' ? conf.value : conf
  467. optMods += `<div id="${mdl.getVersionlessID()}" class="settingsBaseMod settings${submodules ? 'Sub' : ''}Mod" ${val ? 'enabled' : ''}>
  468. <div class="settingsModContent">
  469. <div class="settingsModMainWrapper">
  470. <div class="settingsModStatus"></div>
  471. <div class="settingsModDetails">
  472. <span class="settingsModName">${mdl.getName()}</span>
  473. <span class="settingsModVersion">v${mdl.getVersion()}</span>
  474. </div>
  475. </div>
  476. <label class="toggleSwitch">
  477. <input type="checkbox" formod="${mdl.getVersionlessID()}" ${val ? 'checked' : ''}>
  478. <span class="toggleSwitchSlider"></span>
  479. </label>
  480. </div>
  481. ${mdl.hasSubModules() ? `<div class="settingsSubModContainer">
  482. ${Object.values(parseModulesForUI(mdl.getSubModules(), true, conf.mods)).join('')}
  483. </div>` : ''}
  484. </div>`
  485. }
  486. }
  487. }
  488. return {
  489. reqMods,
  490. optMods
  491. }
  492. }
  493. /**
  494. * Bind functionality to mod config toggle switches. Switching the value
  495. * will also switch the status color on the left of the mod UI.
  496. */
  497. function bindModsToggleSwitch(){
  498. const sEls = settingsModsContainer.querySelectorAll('[formod]')
  499. Array.from(sEls).map((v, index, arr) => {
  500. v.onchange = () => {
  501. if(v.checked) {
  502. document.getElementById(v.getAttribute('formod')).setAttribute('enabled', '')
  503. } else {
  504. document.getElementById(v.getAttribute('formod')).removeAttribute('enabled')
  505. }
  506. }
  507. })
  508. }
  509. /**
  510. * Save the mod configuration based on the UI values.
  511. */
  512. function saveModConfiguration(){
  513. const serv = ConfigManager.getSelectedServer()
  514. const modConf = ConfigManager.getModConfiguration(serv)
  515. modConf.mods = _saveModConfiguration(modConf.mods)
  516. ConfigManager.setModConfiguration(serv, modConf)
  517. }
  518. /**
  519. * Recursively save mod config with submods.
  520. *
  521. * @param {Object} modConf Mod config object to save.
  522. */
  523. function _saveModConfiguration(modConf){
  524. for(let m of Object.entries(modConf)){
  525. const tSwitch = settingsModsContainer.querySelectorAll(`[formod='${m[0]}']`)
  526. if(!tSwitch[0].hasAttribute('dropin')){
  527. if(typeof m[1] === 'boolean'){
  528. modConf[m[0]] = tSwitch[0].checked
  529. } else {
  530. if(m[1] != null){
  531. if(tSwitch.length > 0){
  532. modConf[m[0]].value = tSwitch[0].checked
  533. }
  534. modConf[m[0]].mods = _saveModConfiguration(modConf[m[0]].mods)
  535. }
  536. }
  537. }
  538. }
  539. return modConf
  540. }
  541. // Drop-in mod elements.
  542. let CACHE_SETTINGS_MODS_DIR
  543. let CACHE_DROPIN_MODS
  544. /**
  545. * Resolve any located drop-in mods for this server and
  546. * populate the results onto the UI.
  547. */
  548. function resolveDropinModsForUI(){
  549. const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
  550. CACHE_SETTINGS_MODS_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID(), 'mods')
  551. CACHE_DROPIN_MODS = DropinModUtil.scanForDropinMods(CACHE_SETTINGS_MODS_DIR, serv.getMinecraftVersion())
  552. let dropinMods = ''
  553. for(dropin of CACHE_DROPIN_MODS){
  554. dropinMods += `<div id="${dropin.fullName}" class="settingsBaseMod settingsDropinMod" ${!dropin.disabled ? 'enabled' : ''}>
  555. <div class="settingsModContent">
  556. <div class="settingsModMainWrapper">
  557. <div class="settingsModStatus"></div>
  558. <div class="settingsModDetails">
  559. <span class="settingsModName">${dropin.name}</span>
  560. <div class="settingsDropinRemoveWrapper">
  561. <button class="settingsDropinRemoveButton" remmod="${dropin.fullName}">Remove</button>
  562. </div>
  563. </div>
  564. </div>
  565. <label class="toggleSwitch">
  566. <input type="checkbox" formod="${dropin.fullName}" dropin ${!dropin.disabled ? 'checked' : ''}>
  567. <span class="toggleSwitchSlider"></span>
  568. </label>
  569. </div>
  570. </div>`
  571. }
  572. document.getElementById('settingsDropinModsContent').innerHTML = dropinMods
  573. }
  574. /**
  575. * Bind the remove button for each loaded drop-in mod.
  576. */
  577. function bindDropinModsRemoveButton(){
  578. const sEls = settingsModsContainer.querySelectorAll('[remmod]')
  579. Array.from(sEls).map((v, index, arr) => {
  580. v.onclick = () => {
  581. const fullName = v.getAttribute('remmod')
  582. const res = DropinModUtil.deleteDropinMod(CACHE_SETTINGS_MODS_DIR, fullName)
  583. if(res){
  584. document.getElementById(fullName).remove()
  585. } else {
  586. setOverlayContent(
  587. `Failed to Delete<br>Drop-in Mod ${fullName}`,
  588. 'Make sure the file is not in use and try again.',
  589. 'Okay'
  590. )
  591. setOverlayHandler(null)
  592. toggleOverlay(true)
  593. }
  594. }
  595. })
  596. }
  597. /**
  598. * Bind functionality to the file system button for the selected
  599. * server configuration.
  600. */
  601. function bindDropinModFileSystemButton(){
  602. const fsBtn = document.getElementById('settingsDropinFileSystemButton')
  603. fsBtn.onclick = () => {
  604. DropinModUtil.validateDir(CACHE_SETTINGS_MODS_DIR)
  605. shell.openItem(CACHE_SETTINGS_MODS_DIR)
  606. }
  607. fsBtn.ondragenter = e => {
  608. e.dataTransfer.dropEffect = 'move'
  609. fsBtn.setAttribute('drag', '')
  610. e.preventDefault()
  611. }
  612. fsBtn.ondragover = e => {
  613. e.preventDefault()
  614. }
  615. fsBtn.ondragleave = e => {
  616. fsBtn.removeAttribute('drag')
  617. }
  618. fsBtn.ondrop = e => {
  619. fsBtn.removeAttribute('drag')
  620. e.preventDefault()
  621. DropinModUtil.addDropinMods(e.dataTransfer.files, CACHE_SETTINGS_MODS_DIR)
  622. reloadDropinMods()
  623. }
  624. }
  625. /**
  626. * Save drop-in mod states. Enabling and disabling is just a matter
  627. * of adding/removing the .disabled extension.
  628. */
  629. function saveDropinModConfiguration(){
  630. for(dropin of CACHE_DROPIN_MODS){
  631. const dropinUI = document.getElementById(dropin.fullName)
  632. if(dropinUI != null){
  633. const dropinUIEnabled = dropinUI.hasAttribute('enabled')
  634. if(DropinModUtil.isDropinModEnabled(dropin.fullName) != dropinUIEnabled){
  635. DropinModUtil.toggleDropinMod(CACHE_SETTINGS_MODS_DIR, dropin.fullName, dropinUIEnabled).catch(err => {
  636. if(!isOverlayVisible()){
  637. setOverlayContent(
  638. 'Failed to Toggle<br>One or More Drop-in Mods',
  639. err.message,
  640. 'Okay'
  641. )
  642. setOverlayHandler(null)
  643. toggleOverlay(true)
  644. }
  645. })
  646. }
  647. }
  648. }
  649. }
  650. // Refresh the drop-in mods when F5 is pressed.
  651. // Only active on the mods tab.
  652. document.addEventListener('keydown', (e) => {
  653. if(getCurrentView() === VIEWS.settings && selectedSettingsTab === 'settingsTabMods'){
  654. if(e.key === 'F5'){
  655. reloadDropinMods()
  656. }
  657. }
  658. })
  659. function reloadDropinMods(){
  660. resolveDropinModsForUI()
  661. bindDropinModsRemoveButton()
  662. bindDropinModFileSystemButton()
  663. bindModsToggleSwitch()
  664. }
  665. // Shaderpack
  666. let CACHE_SETTINGS_INSTANCE_DIR
  667. let CACHE_SHADERPACKS
  668. let CACHE_SELECTED_SHADERPACK
  669. /**
  670. * Load shaderpack information.
  671. */
  672. function resolveShaderpacksForUI(){
  673. const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
  674. CACHE_SETTINGS_INSTANCE_DIR = path.join(ConfigManager.getInstanceDirectory(), serv.getID())
  675. CACHE_SHADERPACKS = DropinModUtil.scanForShaderpacks(CACHE_SETTINGS_INSTANCE_DIR)
  676. CACHE_SELECTED_SHADERPACK = DropinModUtil.getEnabledShaderpack(CACHE_SETTINGS_INSTANCE_DIR)
  677. setShadersOptions(CACHE_SHADERPACKS, CACHE_SELECTED_SHADERPACK)
  678. }
  679. function setShadersOptions(arr, selected){
  680. const cont = document.getElementById('settingsShadersOptions')
  681. cont.innerHTML = ''
  682. for(let opt of arr) {
  683. const d = document.createElement('DIV')
  684. d.innerHTML = opt.name
  685. d.setAttribute('value', opt.fullName)
  686. if(opt.fullName === selected) {
  687. d.setAttribute('selected', '')
  688. document.getElementById('settingsShadersSelected').innerHTML = opt.name
  689. }
  690. d.addEventListener('click', function(e) {
  691. this.parentNode.previousElementSibling.innerHTML = this.innerHTML
  692. for(let sib of this.parentNode.children){
  693. sib.removeAttribute('selected')
  694. }
  695. this.setAttribute('selected', '')
  696. closeSettingsSelect()
  697. })
  698. cont.appendChild(d)
  699. }
  700. }
  701. // Server status bar functions.
  702. /**
  703. * Load the currently selected server information onto the mods tab.
  704. */
  705. function loadSelectedServerOnModsTab(){
  706. const serv = DistroManager.getDistribution().getServer(ConfigManager.getSelectedServer())
  707. document.getElementById('settingsSelServContent').innerHTML = `
  708. <img class="serverListingImg" src="${serv.getIcon()}"/>
  709. <div class="serverListingDetails">
  710. <span class="serverListingName">${serv.getName()}</span>
  711. <span class="serverListingDescription">${serv.getDescription()}</span>
  712. <div class="serverListingInfo">
  713. <div class="serverListingVersion">${serv.getMinecraftVersion()}</div>
  714. <div class="serverListingRevision">${serv.getVersion()}</div>
  715. ${serv.isMainServer() ? `<div class="serverListingStarWrapper">
  716. <svg id="Layer_1" viewBox="0 0 107.45 104.74" width="20px" height="20px">
  717. <defs>
  718. <style>.cls-1{fill:#fff;}.cls-2{fill:none;stroke:#fff;stroke-miterlimit:10;}</style>
  719. </defs>
  720. <path class="cls-1" d="M100.93,65.54C89,62,68.18,55.65,63.54,52.13c2.7-5.23,18.8-19.2,28-27.55C81.36,31.74,63.74,43.87,58.09,45.3c-2.41-5.37-3.61-26.52-4.37-39-.77,12.46-2,33.64-4.36,39-5.7-1.46-23.3-13.57-33.49-20.72,9.26,8.37,25.39,22.36,28,27.55C39.21,55.68,18.47,62,6.52,65.55c12.32-2,33.63-6.06,39.34-4.9-.16,5.87-8.41,26.16-13.11,37.69,6.1-10.89,16.52-30.16,21-33.9,4.5,3.79,14.93,23.09,21,34C70,86.84,61.73,66.48,61.59,60.65,67.36,59.49,88.64,63.52,100.93,65.54Z"/>
  721. <circle class="cls-2" cx="53.73" cy="53.9" r="38"/>
  722. </svg>
  723. <span class="serverListingStarTooltip">Main Server</span>
  724. </div>` : ''}
  725. </div>
  726. </div>
  727. `
  728. }
  729. // Bind functionality to the server switch button.
  730. document.getElementById('settingsSwitchServerButton').addEventListener('click', (e) => {
  731. e.target.blur()
  732. toggleServerSelection(true)
  733. })
  734. /**
  735. * Save mod configuration for the current selected server.
  736. */
  737. function saveAllModConfigurations(){
  738. saveModConfiguration()
  739. ConfigManager.save()
  740. saveDropinModConfiguration()
  741. }
  742. /**
  743. * Function to refresh the mods tab whenever the selected
  744. * server is changed.
  745. */
  746. function animateModsTabRefresh(){
  747. $('#settingsTabMods').fadeOut(500, () => {
  748. prepareModsTab()
  749. $('#settingsTabMods').fadeIn(500)
  750. })
  751. }
  752. /**
  753. * Prepare the Mods tab for display.
  754. */
  755. function prepareModsTab(first){
  756. resolveModsForUI()
  757. resolveDropinModsForUI()
  758. resolveShaderpacksForUI()
  759. bindDropinModsRemoveButton()
  760. bindDropinModFileSystemButton()
  761. bindModsToggleSwitch()
  762. loadSelectedServerOnModsTab()
  763. }
  764. /**
  765. * Java Tab
  766. */
  767. // DOM Cache
  768. const settingsMaxRAMRange = document.getElementById('settingsMaxRAMRange')
  769. const settingsMinRAMRange = document.getElementById('settingsMinRAMRange')
  770. const settingsMaxRAMLabel = document.getElementById('settingsMaxRAMLabel')
  771. const settingsMinRAMLabel = document.getElementById('settingsMinRAMLabel')
  772. const settingsMemoryTotal = document.getElementById('settingsMemoryTotal')
  773. const settingsMemoryAvail = document.getElementById('settingsMemoryAvail')
  774. const settingsJavaExecDetails = document.getElementById('settingsJavaExecDetails')
  775. const settingsJavaExecVal = document.getElementById('settingsJavaExecVal')
  776. const settingsJavaExecSel = document.getElementById('settingsJavaExecSel')
  777. // Store maximum memory values.
  778. const SETTINGS_MAX_MEMORY = ConfigManager.getAbsoluteMaxRAM()
  779. const SETTINGS_MIN_MEMORY = ConfigManager.getAbsoluteMinRAM()
  780. // Set the max and min values for the ranged sliders.
  781. settingsMaxRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
  782. settingsMaxRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY)
  783. settingsMinRAMRange.setAttribute('max', SETTINGS_MAX_MEMORY)
  784. settingsMinRAMRange.setAttribute('min', SETTINGS_MIN_MEMORY )
  785. // Bind on change event for min memory container.
  786. settingsMinRAMRange.onchange = (e) => {
  787. // Current range values
  788. const sMaxV = Number(settingsMaxRAMRange.getAttribute('value'))
  789. const sMinV = Number(settingsMinRAMRange.getAttribute('value'))
  790. // Get reference to range bar.
  791. const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
  792. // Calculate effective total memory.
  793. const max = (os.totalmem()-1000000000)/1000000000
  794. // Change range bar color based on the selected value.
  795. if(sMinV >= max/2){
  796. bar.style.background = '#e86060'
  797. } else if(sMinV >= max/4) {
  798. bar.style.background = '#e8e18b'
  799. } else {
  800. bar.style.background = null
  801. }
  802. // Increase maximum memory if the minimum exceeds its value.
  803. if(sMaxV < sMinV){
  804. const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
  805. updateRangedSlider(settingsMaxRAMRange, sMinV,
  806. ((sMinV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
  807. settingsMaxRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
  808. }
  809. // Update label
  810. settingsMinRAMLabel.innerHTML = sMinV.toFixed(1) + 'G'
  811. }
  812. // Bind on change event for max memory container.
  813. settingsMaxRAMRange.onchange = (e) => {
  814. // Current range values
  815. const sMaxV = Number(settingsMaxRAMRange.getAttribute('value'))
  816. const sMinV = Number(settingsMinRAMRange.getAttribute('value'))
  817. // Get reference to range bar.
  818. const bar = e.target.getElementsByClassName('rangeSliderBar')[0]
  819. // Calculate effective total memory.
  820. const max = (os.totalmem()-1000000000)/1000000000
  821. // Change range bar color based on the selected value.
  822. if(sMaxV >= max/2){
  823. bar.style.background = '#e86060'
  824. } else if(sMaxV >= max/4) {
  825. bar.style.background = '#e8e18b'
  826. } else {
  827. bar.style.background = null
  828. }
  829. // Decrease the minimum memory if the maximum value is less.
  830. if(sMaxV < sMinV){
  831. const sliderMeta = calculateRangeSliderMeta(settingsMaxRAMRange)
  832. updateRangedSlider(settingsMinRAMRange, sMaxV,
  833. ((sMaxV-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
  834. settingsMinRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
  835. }
  836. settingsMaxRAMLabel.innerHTML = sMaxV.toFixed(1) + 'G'
  837. }
  838. /**
  839. * Calculate common values for a ranged slider.
  840. *
  841. * @param {Element} v The range slider to calculate against.
  842. * @returns {Object} An object with meta values for the provided ranged slider.
  843. */
  844. function calculateRangeSliderMeta(v){
  845. const val = {
  846. max: Number(v.getAttribute('max')),
  847. min: Number(v.getAttribute('min')),
  848. step: Number(v.getAttribute('step')),
  849. }
  850. val.ticks = (val.max-val.min)/val.step
  851. val.inc = 100/val.ticks
  852. return val
  853. }
  854. /**
  855. * Binds functionality to the ranged sliders. They're more than
  856. * just divs now :').
  857. */
  858. function bindRangeSlider(){
  859. Array.from(document.getElementsByClassName('rangeSlider')).map((v) => {
  860. // Reference the track (thumb).
  861. const track = v.getElementsByClassName('rangeSliderTrack')[0]
  862. // Set the initial slider value.
  863. const value = v.getAttribute('value')
  864. const sliderMeta = calculateRangeSliderMeta(v)
  865. updateRangedSlider(v, value, ((value-sliderMeta.min)/sliderMeta.step)*sliderMeta.inc)
  866. // The magic happens when we click on the track.
  867. track.onmousedown = (e) => {
  868. // Stop moving the track on mouse up.
  869. document.onmouseup = (e) => {
  870. document.onmousemove = null
  871. document.onmouseup = null
  872. }
  873. // Move slider according to the mouse position.
  874. document.onmousemove = (e) => {
  875. // Distance from the beginning of the bar in pixels.
  876. const diff = e.pageX - v.offsetLeft - track.offsetWidth/2
  877. // Don't move the track off the bar.
  878. if(diff >= 0 && diff <= v.offsetWidth-track.offsetWidth/2){
  879. // Convert the difference to a percentage.
  880. const perc = (diff/v.offsetWidth)*100
  881. // Calculate the percentage of the closest notch.
  882. const notch = Number(perc/sliderMeta.inc).toFixed(0)*sliderMeta.inc
  883. // If we're close to that notch, stick to it.
  884. if(Math.abs(perc-notch) < sliderMeta.inc/2){
  885. updateRangedSlider(v, sliderMeta.min+(sliderMeta.step*(notch/sliderMeta.inc)), notch)
  886. }
  887. }
  888. }
  889. }
  890. })
  891. }
  892. /**
  893. * Update a ranged slider's value and position.
  894. *
  895. * @param {Element} element The ranged slider to update.
  896. * @param {string | number} value The new value for the ranged slider.
  897. * @param {number} notch The notch that the slider should now be at.
  898. */
  899. function updateRangedSlider(element, value, notch){
  900. const oldVal = element.getAttribute('value')
  901. const bar = element.getElementsByClassName('rangeSliderBar')[0]
  902. const track = element.getElementsByClassName('rangeSliderTrack')[0]
  903. element.setAttribute('value', value)
  904. if(notch < 0){
  905. notch = 0
  906. } else if(notch > 100) {
  907. notch = 100
  908. }
  909. const event = new MouseEvent('change', {
  910. target: element,
  911. type: 'change',
  912. bubbles: false,
  913. cancelable: true
  914. })
  915. let cancelled = !element.dispatchEvent(event)
  916. if(!cancelled){
  917. track.style.left = notch + '%'
  918. bar.style.width = notch + '%'
  919. } else {
  920. element.setAttribute('value', oldVal)
  921. }
  922. }
  923. /**
  924. * Display the total and available RAM.
  925. */
  926. function populateMemoryStatus(){
  927. settingsMemoryTotal.innerHTML = Number((os.totalmem()-1000000000)/1000000000).toFixed(1) + 'G'
  928. settingsMemoryAvail.innerHTML = Number(os.freemem()/1000000000).toFixed(1) + 'G'
  929. }
  930. // Bind the executable file input to the display text input.
  931. settingsJavaExecSel.onchange = (e) => {
  932. settingsJavaExecVal.value = settingsJavaExecSel.files[0].path
  933. populateJavaExecDetails(settingsJavaExecVal.value)
  934. }
  935. /**
  936. * Validate the provided executable path and display the data on
  937. * the UI.
  938. *
  939. * @param {string} execPath The executable path to populate against.
  940. */
  941. function populateJavaExecDetails(execPath){
  942. AssetGuard._validateJavaBinary(execPath).then(v => {
  943. if(v.valid){
  944. settingsJavaExecDetails.innerHTML = `Selected: Java ${v.version.major} Update ${v.version.update} (x${v.arch})`
  945. } else {
  946. settingsJavaExecDetails.innerHTML = 'Invalid Selection'
  947. }
  948. })
  949. }
  950. /**
  951. * Prepare the Java tab for display.
  952. */
  953. function prepareJavaTab(){
  954. bindRangeSlider()
  955. populateMemoryStatus()
  956. }
  957. /**
  958. * About Tab
  959. */
  960. const settingsTabAbout = document.getElementById('settingsTabAbout')
  961. const settingsAboutChangelogTitle = settingsTabAbout.getElementsByClassName('settingsChangelogTitle')[0]
  962. const settingsAboutChangelogText = settingsTabAbout.getElementsByClassName('settingsChangelogText')[0]
  963. const settingsAboutChangelogButton = settingsTabAbout.getElementsByClassName('settingsChangelogButton')[0]
  964. // Bind the devtools toggle button.
  965. document.getElementById('settingsAboutDevToolsButton').onclick = (e) => {
  966. let window = remote.getCurrentWindow()
  967. window.toggleDevTools()
  968. }
  969. /**
  970. * Return whether or not the provided version is a prerelease.
  971. *
  972. * @param {string} version The semver version to test.
  973. * @returns {boolean} True if the version is a prerelease, otherwise false.
  974. */
  975. function isPrerelease(version){
  976. const preRelComp = semver.prerelease(version)
  977. return preRelComp != null && preRelComp.length > 0
  978. }
  979. /**
  980. * Utility method to display version information on the
  981. * About and Update settings tabs.
  982. *
  983. * @param {string} version The semver version to display.
  984. * @param {Element} valueElement The value element.
  985. * @param {Element} titleElement The title element.
  986. * @param {Element} checkElement The check mark element.
  987. */
  988. function populateVersionInformation(version, valueElement, titleElement, checkElement){
  989. valueElement.innerHTML = version
  990. if(isPrerelease(version)){
  991. titleElement.innerHTML = 'Pre-release'
  992. titleElement.style.color = '#ff886d'
  993. checkElement.style.background = '#ff886d'
  994. } else {
  995. titleElement.innerHTML = 'Stable Release'
  996. titleElement.style.color = null
  997. checkElement.style.background = null
  998. }
  999. }
  1000. /**
  1001. * Retrieve the version information and display it on the UI.
  1002. */
  1003. function populateAboutVersionInformation(){
  1004. populateVersionInformation(remote.app.getVersion(), document.getElementById('settingsAboutCurrentVersionValue'), document.getElementById('settingsAboutCurrentVersionTitle'), document.getElementById('settingsAboutCurrentVersionCheck'))
  1005. }
  1006. /**
  1007. * Fetches the GitHub atom release feed and parses it for the release notes
  1008. * of the current version. This value is displayed on the UI.
  1009. */
  1010. function populateReleaseNotes(){
  1011. $.ajax({
  1012. url: 'https://github.com/WesterosCraftCode/ElectronLauncher/releases.atom',
  1013. success: (data) => {
  1014. const version = 'v' + remote.app.getVersion()
  1015. const entries = $(data).find('entry')
  1016. for(let i=0; i<entries.length; i++){
  1017. const entry = $(entries[i])
  1018. let id = entry.find('id').text()
  1019. id = id.substring(id.lastIndexOf('/')+1)
  1020. if(id === version){
  1021. settingsAboutChangelogTitle.innerHTML = entry.find('title').text()
  1022. settingsAboutChangelogText.innerHTML = entry.find('content').text()
  1023. settingsAboutChangelogButton.href = entry.find('link').attr('href')
  1024. }
  1025. }
  1026. },
  1027. timeout: 2500
  1028. }).catch(err => {
  1029. settingsAboutChangelogText.innerHTML = 'Failed to load release notes.'
  1030. })
  1031. }
  1032. /**
  1033. * Prepare account tab for display.
  1034. */
  1035. function prepareAboutTab(){
  1036. populateAboutVersionInformation()
  1037. populateReleaseNotes()
  1038. }
  1039. /**
  1040. * Update Tab
  1041. */
  1042. const settingsTabUpdate = document.getElementById('settingsTabUpdate')
  1043. const settingsUpdateTitle = document.getElementById('settingsUpdateTitle')
  1044. const settingsUpdateVersionCheck = document.getElementById('settingsUpdateVersionCheck')
  1045. const settingsUpdateVersionTitle = document.getElementById('settingsUpdateVersionTitle')
  1046. const settingsUpdateVersionValue = document.getElementById('settingsUpdateVersionValue')
  1047. const settingsUpdateChangelogTitle = settingsTabUpdate.getElementsByClassName('settingsChangelogTitle')[0]
  1048. const settingsUpdateChangelogText = settingsTabUpdate.getElementsByClassName('settingsChangelogText')[0]
  1049. const settingsUpdateChangelogCont = settingsTabUpdate.getElementsByClassName('settingsChangelogContainer')[0]
  1050. const settingsUpdateActionButton = document.getElementById('settingsUpdateActionButton')
  1051. /**
  1052. * Update the properties of the update action button.
  1053. *
  1054. * @param {string} text The new button text.
  1055. * @param {boolean} disabled Optional. Disable or enable the button
  1056. * @param {function} handler Optional. New button event handler.
  1057. */
  1058. function settingsUpdateButtonStatus(text, disabled = false, handler = null){
  1059. settingsUpdateActionButton.innerHTML = text
  1060. settingsUpdateActionButton.disabled = disabled
  1061. if(handler != null){
  1062. settingsUpdateActionButton.onclick = handler
  1063. }
  1064. }
  1065. /**
  1066. * Populate the update tab with relevant information.
  1067. *
  1068. * @param {Object} data The update data.
  1069. */
  1070. function populateSettingsUpdateInformation(data){
  1071. if(data != null){
  1072. settingsUpdateTitle.innerHTML = `New ${isPrerelease(data.version) ? 'Pre-release' : 'Release'} Available`
  1073. settingsUpdateChangelogCont.style.display = null
  1074. settingsUpdateChangelogTitle.innerHTML = data.releaseName
  1075. settingsUpdateChangelogText.innerHTML = data.releaseNotes
  1076. populateVersionInformation(data.version, settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck)
  1077. if(process.platform === 'darwin'){
  1078. settingsUpdateButtonStatus('Download from GitHub<span style="font-size: 10px;color: gray;text-shadow: none !important;">Close the launcher and run the dmg to update.</span>', false, () => {
  1079. shell.openExternal(data.darwindownload)
  1080. })
  1081. } else {
  1082. settingsUpdateButtonStatus('Downloading..', true)
  1083. }
  1084. } else {
  1085. settingsUpdateTitle.innerHTML = 'You Are Running the Latest Version'
  1086. settingsUpdateChangelogCont.style.display = 'none'
  1087. populateVersionInformation(remote.app.getVersion(), settingsUpdateVersionValue, settingsUpdateVersionTitle, settingsUpdateVersionCheck)
  1088. settingsUpdateButtonStatus('Check for Updates', false, () => {
  1089. if(!isDev){
  1090. ipcRenderer.send('autoUpdateAction', 'checkForUpdate')
  1091. settingsUpdateButtonStatus('Checking for Updates..', true)
  1092. }
  1093. })
  1094. }
  1095. }
  1096. /**
  1097. * Prepare update tab for display.
  1098. *
  1099. * @param {Object} data The update data.
  1100. */
  1101. function prepareUpdateTab(data = null){
  1102. populateSettingsUpdateInformation(data)
  1103. }
  1104. /**
  1105. * Settings preparation functions.
  1106. */
  1107. /**
  1108. * Prepare the entire settings UI.
  1109. *
  1110. * @param {boolean} first Whether or not it is the first load.
  1111. */
  1112. function prepareSettings(first = false) {
  1113. if(first){
  1114. setupSettingsTabs()
  1115. initSettingsValidators()
  1116. prepareUpdateTab()
  1117. } else {
  1118. prepareModsTab()
  1119. }
  1120. initSettingsValues()
  1121. prepareAccountsTab()
  1122. prepareJavaTab()
  1123. prepareAboutTab()
  1124. }
  1125. // Prepare the settings UI on startup.
  1126. prepareSettings(true)