diff --git a/app/assets/js/scripts/install.js b/app/assets/js/scripts/install.js index 37a613f..21a9bc3 100644 --- a/app/assets/js/scripts/install.js +++ b/app/assets/js/scripts/install.js @@ -117,16 +117,19 @@ function renderDetailPanel(profile){ installDetailBody.textContent = buildDetailText(profile) installDetailAddButton.disabled = installed || !profile.launchReady installDetailAddButton.textContent = installed ? '이미 라이브러리에 있음' : '라이브러리에 추가' - installDetailAddButton.onclick = async () => { - try { - const installedProfile = await CatalogManager.installProfile(profile.id) - await ProfileAssetManager.prefetchProfileAssets(installedProfile) - if(installedProfile.kind === 'server-pack' && installedProfile.hostReady){ - await ProfileAssetManager.ensureServerBundleInstalled(installedProfile) - } - renderDetailPanel(profile) - await renderInstallView() - if(typeof refreshLibraryView === 'function'){ + installDetailAddButton.onclick = async () => { + try { + const installedProfile = await CatalogManager.installProfile(profile.id) + await ProfileAssetManager.prefetchProfileAssets(installedProfile) + if(installedProfile.kind === 'server-pack' && installedProfile.hostReady){ + await ProfileAssetManager.ensureServerBundleInstalled(installedProfile) + } + if(typeof refreshSelectedProfileButton === 'function'){ + refreshSelectedProfileButton() + } + renderDetailPanel(profile) + await renderInstallView() + if(typeof refreshLibraryView === 'function'){ await refreshLibraryView() } showInstallMessage('추가 완료', `${profile.name} 프로필을 라이브러리에 추가했습니다.`) @@ -242,6 +245,9 @@ async function renderInstallView(){ if(installedProfile.kind === 'server-pack' && installedProfile.hostReady){ await ProfileAssetManager.ensureServerBundleInstalled(installedProfile) } + if(typeof refreshSelectedProfileButton === 'function'){ + refreshSelectedProfileButton() + } selectProfile(profile.id) await renderInstallView() if(typeof refreshLibraryView === 'function'){ diff --git a/app/assets/js/scripts/landing.js b/app/assets/js/scripts/landing.js index b50c8ff..dd18f03 100644 --- a/app/assets/js/scripts/landing.js +++ b/app/assets/js/scripts/landing.js @@ -30,6 +30,7 @@ const { // Internal Requirements const AuthManager = require('./assets/js/authmanager') +const CatalogManager = require('./assets/js/catalogmanager') const DiscordWrapper = require('./assets/js/discordwrapper') const ProcessBuilder = require('./assets/js/processbuilder') @@ -170,11 +171,58 @@ function setLaunchEnabled(val){ document.getElementById('launch_button').disabled = !val } +function refreshSelectedProfileButton(){ + const selectedProfile = CatalogManager.getSelectedProfileSync() + if(selectedProfile == null){ + server_selection_button.innerHTML = '• ' + Lang.queryJS('landing.selectedProfile.noSelection') + setLaunchEnabled(false) + return + } + + const label = selectedProfile.name?.trim().length > 0 + ? selectedProfile.name.trim() + : selectedProfile.id + + server_selection_button.innerHTML = '• ' + label + setLaunchEnabled(selectedProfile.configured !== false) +} + // Bind launch button document.getElementById('launch_button').addEventListener('click', async e => { loggerLanding.info('Launching game..') try { - const server = (await DistroAPI.getDistribution()).getServerById(ConfigManager.getSelectedServer()) + const selectedProfile = CatalogManager.getSelectedProfileSync() + if(selectedProfile == null){ + if(typeof refreshLibraryView === 'function'){ + await refreshLibraryView() + } + switchView(getCurrentView(), VIEWS.library) + return + } + + CatalogManager.applyConfiguredProfile() + const distro = await DistroAPI.refreshDistributionOrFallback() + if(distro == null){ + throw new Error('Distribution refresh returned null.') + } + + let server = distro.getServerById(ConfigManager.getSelectedServer()) + if(server == null && typeof distro.getMainServer === 'function'){ + const mainServer = distro.getMainServer() + if(mainServer != null){ + ConfigManager.setSelectedServer(mainServer.rawServer.id) + ConfigManager.save() + server = mainServer + } + } + + onDistroRefresh(distro) + refreshSelectedProfileButton() + + if(server == null){ + throw new Error('No server available for selected profile.') + } + const jExe = ConfigManager.getJavaExecutable(ConfigManager.getSelectedServer()) if(jExe == null){ await asyncSystemScan(server.effectiveJavaOptions) @@ -267,17 +315,19 @@ function updateSelectedServer(serv){ } ConfigManager.setSelectedServer(serv != null ? serv.rawServer.id : null) ConfigManager.save() - server_selection_button.innerHTML = '• ' + (serv != null ? serv.rawServer.name : Lang.queryJS('landing.noSelection')) if(getCurrentView() === VIEWS.settings){ animateSettingsTabRefresh() } - setLaunchEnabled(serv != null) + refreshSelectedProfileButton() } -// Real text is set in uibinder.js on distributionIndexDone. -server_selection_button.innerHTML = '• ' + Lang.queryJS('landing.selectedServer.loading') +// Real text is set based on the selected library profile. +server_selection_button.innerHTML = '• ' + Lang.queryJS('landing.selectedProfile.loading') server_selection_button.onclick = async e => { e.target.blur() - await toggleServerSelection(true) + if(typeof refreshLibraryView === 'function'){ + await refreshLibraryView() + } + switchView(getCurrentView(), VIEWS.library) } // Update Mojang Status Color @@ -1133,4 +1183,5 @@ window.updateSelectedAccount = updateSelectedAccount window.updateSelectedServer = updateSelectedServer window.refreshServerStatus = refreshServerStatus window.initNews = initNews +window.refreshSelectedProfileButton = refreshSelectedProfileButton })() diff --git a/app/assets/js/scripts/library.js b/app/assets/js/scripts/library.js index 29ced75..9a36c3b 100644 --- a/app/assets/js/scripts/library.js +++ b/app/assets/js/scripts/library.js @@ -112,6 +112,9 @@ async function activateProfile(profile, launchNow = false){ CatalogManager.selectProfile(profile.id) CatalogManager.applyConfiguredProfile() + if(typeof refreshSelectedProfileButton === 'function'){ + refreshSelectedProfileButton() + } try { const distro = await DistroAPI.refreshDistributionOrFallback() @@ -302,6 +305,9 @@ async function renderLibraryView(){ selectButton.addEventListener('click', async () => { CatalogManager.selectProfile(profile.id) CatalogManager.applyConfiguredProfile() + if(typeof refreshSelectedProfileButton === 'function'){ + refreshSelectedProfileButton() + } await renderLibraryView() }) @@ -360,6 +366,9 @@ async function renderLibraryView(){ removeButton.addEventListener('click', async () => { ServerRuntime.stopHostedProfile(profile.id) CatalogManager.removeProfile(profile.id) + if(typeof refreshSelectedProfileButton === 'function'){ + refreshSelectedProfileButton() + } await renderLibraryView() if(typeof refreshInstallView === 'function'){ await refreshInstallView() diff --git a/app/assets/lang/_custom.toml b/app/assets/lang/_custom.toml index a1a10f5..ca4ab89 100644 --- a/app/assets/lang/_custom.toml +++ b/app/assets/lang/_custom.toml @@ -15,6 +15,7 @@ mediaDiscordURL = "https://discord.gg/Z8j6ahF4MJ" accountPreviewLabel = "계정" libraryButton = "라이브러리" installButton = "설치" +launchButtonPlaceholder = "• 라이브러리에서 선택" [ejs.settings] backButton = "메인으로" diff --git a/app/assets/lang/en_US.toml b/app/assets/lang/en_US.toml index 15041ed..994a32d 100644 --- a/app/assets/lang/en_US.toml +++ b/app/assets/lang/en_US.toml @@ -164,6 +164,10 @@ okay = "Okay" noAccountSelected = "No Account Selected" logoutFailed = "Failed to log out of the selected account. Please try again." +[js.landing.selectedProfile] +noSelection = "Select from Library" +loading = "Loading profile.." + [js.landing.selectedServer] noSelection = "No Server Selected" loading = "Loading.." diff --git a/app/assets/lang/ko_KR.toml b/app/assets/lang/ko_KR.toml index f8a600c..5951a2d 100644 --- a/app/assets/lang/ko_KR.toml +++ b/app/assets/lang/ko_KR.toml @@ -164,6 +164,10 @@ okay = "확인" noAccountSelected = "선택된 계정 없음" logoutFailed = "계정을 로그아웃하지 못했습니다. 다시 시도해 주세요." +[js.landing.selectedProfile] +noSelection = "라이브러리에서 선택" +loading = "프로필 불러오는 중.." + [js.landing.selectedServer] noSelection = "선택된 서버 없음" loading = "로딩 중.."