try to improve link handling

This commit is contained in:
olcxja 2026-10-07 01:46:26 +02:00
commit 3f57682a9b
5 changed files with 30 additions and 14 deletions

View file

@ -450,6 +450,26 @@ function linuxPathFor(file) {
return abs
}
// The document a shortcut was handed. The sandbox cannot hand it over by
// itself: a file out of the user's home is buried under the prefix home, one
// out of /tmp sits behind the private tmpfs, and the rest of the machine is
// read-only. So it is mounted where the app was told it is, writable - the way
// a Wine app gets it as Z:\... and may save it. Prefix data needs nothing: it
// already is the app's own writable home.
function handedFileBinds({ openFile, root }) {
if (!openFile) return []
let abs = ''
try {
abs = fs.realpathSync(String(openFile))
if (!fs.statSync(abs).isFile()) return []
} catch {
// a path that is gone must not become a bind bwrap would refuse
return []
}
if (abs === root || abs.startsWith(root + path.sep)) return []
return [abs]
}
function bwrapSource() {
const devices = ['/dev/shm', '/dev/dri', '/dev/snd', '/dev/input'].filter(d => fs.existsSync(d))
const x11 = fs.existsSync('/tmp/.X11-unix') ? '/tmp/.X11-unix' : ''
@ -481,7 +501,7 @@ async function runLinuxGame({ game, sandbox, onExit, openFile, handoff = false }
if (chosen.backend === 'bwrap') {
const source = bwrapSource()
cmd = 'bwrap'
args = [...buildBwrapArgs({ dataRoot: root, user: source.user, devices: source.devices, x11: source.x11, runUser: source.runUser, shares: source.shares, appDir: writableAppDir(game), urlOpener: routing }), '--', exe, ...argList]
args = [...buildBwrapArgs({ dataRoot: root, user: source.user, devices: source.devices, x11: source.x11, runUser: source.runUser, shares: source.shares, appDir: writableAppDir(game), openFiles: handedFileBinds({ openFile, root }), urlOpener: routing }), '--', exe, ...argList]
header.push(`[plwl] HOME=${env.HOME}`)
}
@ -489,12 +509,7 @@ async function runLinuxGame({ game, sandbox, onExit, openFile, handoff = false }
}
module.exports = {
DATA_DIRS,
XDG_LAYOUT,
SYSTEM_DIRS,
DESKTOP_SEEDS,
DATA_SHARES,
X11_ENV,
SHIM_REL,
OPENER_REL,
MIME_REL,
@ -509,10 +524,10 @@ module.exports = {
ensureLinuxPfx,
resetSeededConfig,
dataShares,
syncDesktopConfig,
buildLinuxEnv,
pickBackend,
isolationLine,
linuxPathFor,
handedFileBinds,
runLinuxGame
}