fix (i hope) all bugs

This commit is contained in:
olcxja 2026-09-26 11:40:04 +02:00
commit 201f9d7a7e
11 changed files with 195 additions and 37 deletions

View file

@ -287,6 +287,28 @@ function iconUrl(id) {
return `plwl-icon://${encodeURIComponent(id)}/icon`
}
// Paths of imported (copy/move) apps live inside FILES/ and are stored
// relative to it in the registry (portable mode) - show them prefixed with
// files/ instead of the absolute install location. External (leave) apps
// keep their absolute path.
function displayPath(p) {
if (!p) return ''
const files = window.plwl.FILES_DIR
if (files && p.startsWith(files + '/')) return 'files/' + p.slice(files.length + 1)
return p
}
// Inverse of displayPath for input fields: accept a files/-prefixed (or bare,
// FILES-relative) path and resolve it to an absolute one.
function absPathInput(v) {
if (!v) return v
const files = window.plwl.FILES_DIR
if (!files) return v
if (v.startsWith('files/')) return files + '/' + v.slice(6)
if (!v.includes('/') && !v.startsWith('.')) return files + '/' + v
return v
}
function fmtPlaytime(seconds) {
const s = Math.round(seconds || 0)
if (s < 60) return t('library.playtimeSeconds', s)
@ -456,13 +478,19 @@ async function doImport(srcDir, mode) {
try {
const game = await window.plwl.gamesImport(srcDir, mode)
closeModal()
toast(t('toast.importDone', game.name), 'success')
if (!game || game.ok === false) {
const raw = (game && game.error) || ''
const errText = raw === 'no-exe-found' ? t('import.noExe') : (raw || 'unknown error')
toast(t('import.failed', errText), 'error')
return
}
state.games = await window.plwl.gamesList()
renderLibrary()
toast(t('toast.importDone', game.name), 'success')
await openGameConfig(game.id)
} catch (err) {
closeModal()
toast(t('toast.importFailed') + ': ' + (err.message || err), 'error')
toast(t('import.failed', (err && err.message) || String(err)), 'error')
}
}
@ -660,8 +688,8 @@ async function openGameConfig(id) {
qs('#gc-title').textContent = game.name
qs('#gc-name').value = game.name
refreshConfigIcon()
qs('#gc-exe').value = game.exePath
qs('#gc-workdir').value = game.workdir
qs('#gc-exe').value = displayPath(game.exePath)
qs('#gc-workdir').value = displayPath(game.workdir)
qs('#gc-args').value = game.args || ''
qs('#gc-env').value = Object.entries(game.env || {}).map(([k, v]) => `${k}=${v}`).join('\n')
renderWineOptions('gc-wine', game.wine)
@ -724,8 +752,8 @@ async function saveGameConfig() {
})
const patch = {
name: qs('#gc-name').value.trim() || game.name,
exePath: qs('#gc-exe').value.trim(),
workdir: qs('#gc-workdir').value.trim(),
exePath: absPathInput(qs('#gc-exe').value.trim()),
workdir: absPathInput(qs('#gc-workdir').value.trim()),
args: qs('#gc-args').value,
wine: selects['gc-wine'].value,
prefix: selects['gc-prefix'].value,
@ -818,12 +846,14 @@ function wireEvents() {
qs('#btn-gc-save').addEventListener('click', saveGameConfig)
qs('#gc-override-add').addEventListener('click', addOverrideRow)
qs('#gc-exe-browse').addEventListener('click', async () => {
const p = await window.plwl.dialogPickFile({ properties: ['openFile'], defaultPath: qs('#gc-workdir').value || window.plwl.FILES_DIR })
if (p) qs('#gc-exe').value = p
const cur = absPathInput(qs('#gc-workdir').value.trim())
const p = await window.plwl.dialogPickFile({ properties: ['openFile'], defaultPath: cur || window.plwl.FILES_DIR })
if (p) qs('#gc-exe').value = displayPath(p)
})
qs('#gc-workdir-browse').addEventListener('click', async () => {
const p = await window.plwl.dialogPickFile({ properties: ['openDirectory'], defaultPath: qs('#gc-exe').value || window.plwl.FILES_DIR })
if (p) qs('#gc-workdir').value = p
const cur = absPathInput(qs('#gc-exe').value.trim())
const p = await window.plwl.dialogPickFile({ properties: ['openDirectory'], defaultPath: cur || window.plwl.FILES_DIR })
if (p) qs('#gc-workdir').value = displayPath(p)
})
qs('#gc-tool-run').addEventListener('click', runCustomTool)
async function applyIconResult(res) {