Refactor launcher profiles and port automation
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
(() => {
|
||||
const { clipboard } = require('electron')
|
||||
|
||||
const CatalogManager = require('./assets/js/catalogmanager')
|
||||
const ConfigManager = require('./assets/js/configmanager')
|
||||
const ProfileAssetManager = require('./assets/js/profileassetmanager')
|
||||
@@ -21,16 +19,18 @@ function createBadge(text){
|
||||
return badge
|
||||
}
|
||||
|
||||
function describeProfileKind(kind){
|
||||
switch(kind){
|
||||
case 'map':
|
||||
return '맵'
|
||||
case 'server-pack':
|
||||
return '서버팩'
|
||||
case 'modpack':
|
||||
default:
|
||||
return '모드팩'
|
||||
function describeProfileFeatures(profile){
|
||||
const features = ['맵']
|
||||
if(profile.modsEnabled){
|
||||
features.push('모드')
|
||||
}
|
||||
if(profile.pluginsEnabled){
|
||||
features.push('플러그인')
|
||||
}
|
||||
if(profile.serverEnabled){
|
||||
features.push('서버')
|
||||
}
|
||||
return features
|
||||
}
|
||||
|
||||
function createParagraph(className, text){
|
||||
@@ -40,23 +40,6 @@ function createParagraph(className, text){
|
||||
return element
|
||||
}
|
||||
|
||||
function createInfoLine(label, value){
|
||||
const line = document.createElement('div')
|
||||
line.className = 'launcherInfoLine'
|
||||
|
||||
const labelElement = document.createElement('span')
|
||||
labelElement.className = 'launcherInfoLabel'
|
||||
labelElement.textContent = label
|
||||
|
||||
const valueElement = document.createElement('span')
|
||||
valueElement.className = 'launcherInfoValue'
|
||||
valueElement.textContent = value
|
||||
|
||||
line.appendChild(labelElement)
|
||||
line.appendChild(valueElement)
|
||||
return line
|
||||
}
|
||||
|
||||
function showLibraryMessage(title, message){
|
||||
if(typeof setOverlayContent === 'function'){
|
||||
setOverlayContent(title, message, '확인')
|
||||
@@ -65,55 +48,24 @@ function showLibraryMessage(title, message){
|
||||
}
|
||||
}
|
||||
|
||||
function describeAssetState(profile){
|
||||
const state = ConfigManager.getLibraryProfileAssetState(profile.id)
|
||||
|
||||
if(profile.kind === 'map'){
|
||||
if(state.worldInstalledAt){
|
||||
return `맵 설치 완료 · ${profile.worldDirectoryName}`
|
||||
}
|
||||
if(profile.worldArchiveUrl){
|
||||
return '맵 아카이브 준비 필요'
|
||||
}
|
||||
}
|
||||
|
||||
if(profile.kind === 'server-pack'){
|
||||
if(state.serverBundleInstalledAt){
|
||||
return '서버 번들 설치 완료'
|
||||
}
|
||||
if(profile.serverBundleUrl){
|
||||
return '서버 번들 준비 필요'
|
||||
}
|
||||
}
|
||||
|
||||
return '추가 자산 없음'
|
||||
}
|
||||
|
||||
function isProfileInstalled(profile){
|
||||
const state = ConfigManager.getLibraryProfileAssetState(profile.id)
|
||||
|
||||
if(profile.kind === 'map'){
|
||||
return state.prefetchedAt != null || profile.worldArchiveUrl == null
|
||||
}
|
||||
|
||||
if(profile.kind === 'server-pack'){
|
||||
return state.serverBundleInstalledAt != null || state.prefetchedAt != null || profile.serverBundleUrl == null
|
||||
}
|
||||
|
||||
return true
|
||||
const mapReady = state.worldInstalledAt != null || state.prefetchedAt != null || profile.worldArchiveUrl == null
|
||||
const serverReady = profile.serverEnabled !== true || profile.hostReady !== true || state.serverInstalledAt != null || state.prefetchedAt != null || profile.serverJarUrl == null
|
||||
return mapReady && serverReady
|
||||
}
|
||||
|
||||
async function prepareProfileAssets(profile){
|
||||
try {
|
||||
await ProfileAssetManager.prefetchProfileAssets(profile)
|
||||
if(profile.kind === 'server-pack' && profile.hostReady){
|
||||
await ProfileAssetManager.ensureServerBundleInstalled(profile)
|
||||
if(profile.serverEnabled && profile.hostReady){
|
||||
await ProfileAssetManager.ensureServerJarInstalled(profile)
|
||||
}
|
||||
await renderLibraryView()
|
||||
showLibraryMessage('자료 준비 완료', `${profile.name} 자료를 준비했습니다.`)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
showLibraryMessage('자료 준비 실패', '프로필 자료를 내려받거나 해제하는 중 오류가 발생했습니다.')
|
||||
showLibraryMessage('자료 준비 실패', '프로필 자료를 내려받는 중 오류가 발생했습니다.')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,63 +90,13 @@ async function applyProfileSelection(profile){
|
||||
onDistroRefresh(distro)
|
||||
}
|
||||
|
||||
async function activateProfile(profile, launchNow = false){
|
||||
if(!profile.configured){
|
||||
const firstIssue = profile.launchIssues?.[0] ?? '이 프로필은 아직 실행 조건이 충족되지 않았습니다.'
|
||||
showLibraryMessage('프로필 설정 필요', firstIssue)
|
||||
function appendAddressOverrideField(profile, container){
|
||||
if(profile.serverEnabled !== true){
|
||||
return
|
||||
}
|
||||
|
||||
CatalogManager.selectProfile(profile.id)
|
||||
CatalogManager.applyConfiguredProfile()
|
||||
if(typeof refreshSelectedProfileButton === 'function'){
|
||||
refreshSelectedProfileButton()
|
||||
}
|
||||
|
||||
try {
|
||||
const distro = await DistroAPI.refreshDistributionOrFallback()
|
||||
if(distro == null){
|
||||
throw new Error('Distribution refresh returned null.')
|
||||
}
|
||||
|
||||
const currentServer = distro.getServerById(ConfigManager.getSelectedServer())
|
||||
if(currentServer == null && typeof distro.getMainServer === 'function'){
|
||||
const mainServer = distro.getMainServer()
|
||||
if(mainServer != null){
|
||||
ConfigManager.setSelectedServer(mainServer.rawServer.id)
|
||||
ConfigManager.save()
|
||||
}
|
||||
}
|
||||
|
||||
const selectedServerId = ConfigManager.getSelectedServer()
|
||||
if(selectedServerId != null){
|
||||
await ProfileAssetManager.prepareProfileForLaunch(profile, selectedServerId)
|
||||
}
|
||||
|
||||
onDistroRefresh(distro)
|
||||
|
||||
if(getCurrentView() === VIEWS.landing){
|
||||
if(launchNow){
|
||||
document.getElementById('launch_button').click()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
switchView(getCurrentView(), VIEWS.landing, 250, 250, () => {}, () => {
|
||||
if(launchNow){
|
||||
document.getElementById('launch_button').click()
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
showLibraryMessage('프로필 로드 실패', '선택한 프로필의 distribution.json 또는 부가 자산을 불러오지 못했습니다.')
|
||||
}
|
||||
}
|
||||
|
||||
function appendAddressOverrideField(profile, fieldGroup){
|
||||
if(!profile.allowCustomServerAddress){
|
||||
return
|
||||
}
|
||||
const fieldGroup = document.createElement('div')
|
||||
fieldGroup.className = 'launcherFieldGroup'
|
||||
|
||||
const label = document.createElement('label')
|
||||
label.className = 'launcherFieldLabel'
|
||||
@@ -203,45 +105,25 @@ function appendAddressOverrideField(profile, fieldGroup){
|
||||
const input = document.createElement('input')
|
||||
input.className = 'launcherFieldInput'
|
||||
input.type = 'text'
|
||||
input.placeholder = profile.defaultServerAddress || 'example.com:25565'
|
||||
input.placeholder = '비워두면 로컬 서버 실행'
|
||||
input.value = ConfigManager.getLibraryServerAddressOverride(profile.id) ?? ''
|
||||
input.addEventListener('change', () => {
|
||||
CatalogManager.setServerAddressOverride(profile.id, input.value)
|
||||
if(typeof refreshServerStatus === 'function'){
|
||||
refreshServerStatus(true)
|
||||
}
|
||||
})
|
||||
|
||||
const help = document.createElement('div')
|
||||
help.className = 'launcherFieldHint'
|
||||
help.textContent = profile.hostReady
|
||||
? '주소를 비워두면 PLAY 시 로컬 서버를 실행하고, 값을 넣으면 해당 주소로 바로 접속합니다.'
|
||||
: '주소를 비워두면 로컬 서버 실행을 시도합니다. 지금은 버킷 JAR이 없어 직접 실행 준비가 부족합니다.'
|
||||
|
||||
fieldGroup.appendChild(label)
|
||||
fieldGroup.appendChild(input)
|
||||
}
|
||||
|
||||
function appendPublishedAddressField(profile, hostState, fieldGroup){
|
||||
if(!hostState.publishedAddress){
|
||||
return
|
||||
}
|
||||
|
||||
const label = document.createElement('label')
|
||||
label.className = 'launcherFieldLabel'
|
||||
label.textContent = '호스트 공개 주소'
|
||||
|
||||
const row = document.createElement('div')
|
||||
row.className = 'launcherInlineField'
|
||||
|
||||
const input = document.createElement('input')
|
||||
input.className = 'launcherFieldInput'
|
||||
input.type = 'text'
|
||||
input.readOnly = true
|
||||
input.value = hostState.publishedAddress
|
||||
|
||||
const copyButton = document.createElement('button')
|
||||
copyButton.className = 'launcherSecondaryButton'
|
||||
copyButton.textContent = '주소 복사'
|
||||
copyButton.addEventListener('click', () => {
|
||||
clipboard.writeText(hostState.publishedAddress)
|
||||
})
|
||||
|
||||
row.appendChild(input)
|
||||
row.appendChild(copyButton)
|
||||
fieldGroup.appendChild(label)
|
||||
fieldGroup.appendChild(row)
|
||||
fieldGroup.appendChild(help)
|
||||
container.appendChild(fieldGroup)
|
||||
}
|
||||
|
||||
async function renderLibraryView(){
|
||||
@@ -273,24 +155,20 @@ async function renderLibraryView(){
|
||||
|
||||
const meta = document.createElement('div')
|
||||
meta.className = 'launcherCardMeta'
|
||||
meta.appendChild(createBadge(describeProfileKind(profile.kind)))
|
||||
if(profile.isCustom){
|
||||
meta.appendChild(createBadge('커스텀'))
|
||||
}
|
||||
describeProfileFeatures(profile).forEach((label) => {
|
||||
meta.appendChild(createBadge(label))
|
||||
})
|
||||
if(profile.id === selectedProfileId){
|
||||
meta.appendChild(createBadge('선택됨'))
|
||||
}
|
||||
if(profile.kind === 'map' && profile.worldDirectoryName){
|
||||
meta.appendChild(createBadge(profile.worldDirectoryName))
|
||||
if(!profile.launchReady){
|
||||
meta.appendChild(createBadge('실행 준비 필요'))
|
||||
}
|
||||
if(profile.kind === 'map' && !profile.launchReady){
|
||||
meta.appendChild(createBadge('맵 설정 필요'))
|
||||
}
|
||||
if(profile.kind === 'server-pack' && !profile.hostReady){
|
||||
meta.appendChild(createBadge('호스팅 설정 필요'))
|
||||
if(profile.serverEnabled && profile.hostReady){
|
||||
meta.appendChild(createBadge('로컬 서버 가능'))
|
||||
}
|
||||
if(hostState.running){
|
||||
meta.appendChild(createBadge(hostState.tunneling ? '서버+터널' : '서버 실행 중'))
|
||||
meta.appendChild(createBadge(hostState.ready ? '서버 실행 중' : '서버 시작 중'))
|
||||
}
|
||||
|
||||
titleGroup.appendChild(title)
|
||||
@@ -299,13 +177,17 @@ async function renderLibraryView(){
|
||||
|
||||
const description = createParagraph('launcherCardDescription', profile.description || '설명이 없습니다.')
|
||||
|
||||
const extra = document.createElement('div')
|
||||
extra.className = 'launcherCardContent'
|
||||
appendAddressOverrideField(profile, extra)
|
||||
|
||||
const actions = document.createElement('div')
|
||||
actions.className = 'launcherCardActions'
|
||||
|
||||
const installButton = document.createElement('button')
|
||||
installButton.className = 'launcherSecondaryButton'
|
||||
installButton.textContent = isProfileInstalled(profile) ? '설치됨' : '설치'
|
||||
installButton.disabled = isProfileInstalled(profile) || !profile.configured
|
||||
installButton.disabled = isProfileInstalled(profile) || !profile.launchReady
|
||||
installButton.addEventListener('click', async () => {
|
||||
await prepareProfileAssets(profile)
|
||||
})
|
||||
@@ -330,14 +212,11 @@ async function renderLibraryView(){
|
||||
}
|
||||
})
|
||||
|
||||
actions.appendChild(installButton)
|
||||
actions.appendChild(selectButton)
|
||||
|
||||
const removeButton = document.createElement('button')
|
||||
removeButton.className = 'launcherGhostButton'
|
||||
removeButton.textContent = '제거'
|
||||
removeButton.addEventListener('click', async () => {
|
||||
ServerRuntime.stopHostedProfile(profile.id)
|
||||
await ServerRuntime.stopHostedProfile(profile.id)
|
||||
CatalogManager.removeProfile(profile.id)
|
||||
if(typeof refreshSelectedProfileButton === 'function'){
|
||||
refreshSelectedProfileButton()
|
||||
@@ -351,10 +230,15 @@ async function renderLibraryView(){
|
||||
}
|
||||
})
|
||||
|
||||
actions.appendChild(installButton)
|
||||
actions.appendChild(selectButton)
|
||||
actions.appendChild(removeButton)
|
||||
|
||||
card.appendChild(header)
|
||||
card.appendChild(description)
|
||||
if(profile.serverEnabled){
|
||||
card.appendChild(extra)
|
||||
}
|
||||
card.appendChild(actions)
|
||||
libraryList.appendChild(card)
|
||||
}
|
||||
@@ -363,7 +247,7 @@ async function renderLibraryView(){
|
||||
renderLibraryEmptyState(false)
|
||||
const errorCard = document.createElement('article')
|
||||
errorCard.className = 'launcherCard'
|
||||
errorCard.innerHTML = '<h3 class="launcherCardTitle">라이브러리 로드 실패</h3><p class="launcherCardDescription">선택한 카탈로그를 읽지 못했습니다. 설치 페이지에서 카탈로그 경로를 다시 확인하세요.</p>'
|
||||
errorCard.innerHTML = '<h3 class="launcherCardTitle">라이브러리 로드 실패</h3><p class="launcherCardDescription">선택한 카탈로그를 읽지 못했습니다. 관리자 사이트에서 카탈로그 경로를 다시 확인하세요.</p>'
|
||||
libraryList.appendChild(errorCard)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user