feat(installer): 최종 리소스팩 다운로드 진행률(퍼센트) 표시

"예" 선택 후 최종 리소스팩 다운로드 시 퍼센트/진행바를 보여준다.
- finalResourcepack:install 을 downloadFile → downloadStream 으로 바꿔 content-length
  기반 진행률을 계산하고 finalResourcepack:progress 이벤트로 렌더러에 전송.
- preload onFinalResourcepackProgress 구독 추가, 렌더러에 진행바+% 표시(완료 100%,
  실패 시 바 숨김). 0.4.17→0.4.18.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-27 00:11:19 +09:00
parent bce87f1362
commit e30d7418df
4 changed files with 54 additions and 3 deletions

View File

@@ -290,8 +290,20 @@ ipcMain.handle('finalResourcepack:install', async (): Promise<{ ok: boolean; pat
const url = `${state.baseUrl}/file/resourcepacks/outputs/${encodeURIComponent(cleaned)}`
const destDir = path.join(getAppDataDir(), getMcCustomDirName(), 'resourcepacks')
const dest = path.join(destDir, cleaned)
await fsp.mkdir(destDir, { recursive: true })
sendLog(t('log.finalResourcepackDownload', { url }))
await downloadFile(url, dest)
// 진행률(퍼센트)을 렌더러로 흘려보내며 스트리밍 다운로드.
let lastPct = -1
const controller = new AbortController()
await downloadStream(url, dest, controller.signal, (loaded, total) => {
const percent = total > 0 ? Math.min(100, Math.max(0, Math.floor((loaded / total) * 100))) : -1
if (percent !== lastPct) {
lastPct = percent
if (mainWindow && !mainWindow.isDestroyed()) {
mainWindow.webContents.send('finalResourcepack:progress', { loaded, total, percent })
}
}
})
sendLog(t('log.finalResourcepackSaved', { path: dest }))
return { ok: true, path: dest }
} catch (error) {

View File

@@ -74,6 +74,15 @@ const api = {
const listener = (_event: unknown, line: string) => handler(line)
ipcRenderer.on('log', listener)
return () => ipcRenderer.removeListener('log', listener)
},
// 최종 리소스팩 다운로드 진행률 구독. 반환값을 호출하면 구독 해제.
onFinalResourcepackProgress: (
handler: (info: { loaded: number; total: number; percent: number }) => void
): (() => void) => {
const listener = (_event: unknown, info: { loaded: number; total: number; percent: number }) => handler(info)
ipcRenderer.on('finalResourcepack:progress', listener)
return () => ipcRenderer.removeListener('finalResourcepack:progress', listener)
}
}