From 2ff8920225e70fd14e9167355e9251eb11b94604 Mon Sep 17 00:00:00 2001 From: olcxja Date: Wed, 7 Oct 2026 00:57:55 +0200 Subject: [PATCH 01/16] support opening links from linux apps --- README.md | 2 + development.md | 2 + files/translations/en-us.json | 1 + files/translations/pl.json | 1 + src/linuxrunner.js | 177 +++++++++++++++++++++++++++++++++- src/sandbox.js | 9 +- 6 files changed, 187 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 21084ec..f18276c 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ When **bubblewrap** is installed *and* usable (PLWL probes it with a real run, n The redirected home starts with a **copy of your desktop preferences** — `kdeglobals`, the GTK 3/4 settings and `user-dirs.dirs` — so the app keeps your theme instead of falling back to its built-in light look. The copy keeps following your host as long as the app has not changed it: a theme change arrives on the next launch, and the moment the app writes its own version, PLWL never touches it again. Your own **fonts, icons, themes and colour schemes are not copied but mounted read-only** inside the sandbox and added to `XDG_DATA_DIRS`, so they follow the host live and nothing can be written back to your `~`. +A **link you click inside the app opens on your desktop**, in your own default browser: PLWL hands the URI to the host's xdg-desktop-portal instead of resolving a browser in here, where the default association and its `.desktop` file are behind the redirected home — that used to mean a system browser you never chose, or nothing at all. Both routes reach the portal: `xdg-open` itself (what Qt, Prism and Electron call) and GIO's in-process resolution (`gtk_show_uri`). On a machine without a portal nothing is changed — a link then behaves exactly as it did before. A KDE-native app that resolves the link in-process through KIO (Dolphin, Kate) is the one path still left out: it asks KDE's own handler database, which has no answer in here (measured: `kde-open` opens nothing and reports success). + Every prefix in the **Wine prefixes** tab has a **Reset Linux config** button: it deletes the desktop preferences PLWL copied in (and the hashes that track them), so the next app start seeds a clean copy from your system — the way back when an app has hijacked a seeded file with its own theme. App data in `linux_pfx` is never touched, and an app running from that prefix blocks the reset. Imported trees get **normalised permissions**: every file gets the owner's `rwx` and an `x` mirrored from its `r`, because sources come from archives, FAT sticks or read-only backups where those bits are simply not there. diff --git a/development.md b/development.md index f464a91..45bb67d 100644 --- a/development.md +++ b/development.md @@ -84,6 +84,7 @@ Renderer never touches Node/Electron directly — everything goes through the `w - Imports normalise permissions (fsutil.chmodTree): owner `rwx`, `x` mirrored from `r` (0644 → 0755). Sources are archives, FAT sticks and read-only backups. - **Reset Linux config** on every prefix row removes exactly what PLWL seeded (DESKTOP_SEEDS, the pulse cookie, `home/.Xauthority`, `.seeded.json`) plus the folders that existed only for the seed, so the next start seeds clean. syncDesktopConfig can only follow a copy it can still prove is its own; the reset does not argue. App data (`data/`, `cache/`, `state/`, `config//`, the rest of `home/`) is never touched, and a running app from that prefix blocks it (the usual `inUse` guard). - The user's real `~` is deliberately invisible in the sandbox (HOME is bound straight to `{prefix}/linux_pfx/home`), so absolute paths an app wrote into its config before the import (Prism's instance `JavaPath`) do not resolve — that is what `isolation: 'off'` is for. +- A clicked link belongs to the host desktop, so it leaves through `org.freedesktop.portal.OpenURI` — both routes, because two different things open a link. The `xdg-open` BINARY is replaced inside the sandbox (a written shim `--ro-bind` over `/usr/bin/xdg-open`, the host's own script parked at `/tmp/.plwl-host/xdg-open` as what the shim falls back to for anything that is not a URI): Qt execs it (measured — `QGenericUnixServices` picks `xdg-open` first, and reaches the portal itself only under `/.flatpak-info`/`SNAP`, which a bwrap profile does not have) and so does Electron. GIO resolves an URI IN-PROCESS, which no shim can reach: for that the prefix seeds `home/.plwl/open-url` (launcher-written, like the shim) plus a desktop entry and a `mimeapps.list` naming it the default for `x-scheme-handler/http|https` and `text/html`. Without the seed GIO falls back to the host's `/usr/share` list — measured: it offered `brave-origin.desktop`, and `gio open` answered "The specified location is not supported". Measured end to end (both backends): the portal launches the host's `helium.desktop` with the exact URI. `GIO_USE_PORTALS=1` was measured and REJECTED: it opened NOTHING and still reported success (GIO's portal path wants a sandbox marker this launcher does not fake), while on a machine WITHOUT a portal it fails hard (“Failed to create OpenURI proxy”). The whole wiring is therefore written only when a session bus and a portal are present (`portalReady`), and a KDE-native app resolving through KIO in-process (`kde-open`) stays uncovered — KDE ignores the seeded list (measured). - Not built: a private or overlay `/etc` (`buildBwrapArgs` accepts `etcRoot`, nothing sets it; `--ro-bind / /` leaves `/etc` read-only, which is all we promise today), `--tmpfs /home` against OTHER users' homes (`hideHome` is plumbed, no UI) and `dataMode` — app data always lands in `{prefix}/linux_pfx`. - Measured, not assumed (Debian 13, kernel 6.12, `bwrap` 0.12.0): the functional probe passes here, no firejail/proot/fuse-overlayfs on the box, `/etc` is 16 MB and its `machine-id` is read-only even on the host. @@ -132,6 +133,7 @@ node test/bench-sync.js # timing: cold vs cached sync node test/linux-sandbox.test.js # bwrap argv profile + auto/off/require choice node test/linux-env.test.js # redirected HOME/XDG_* for both backends node test/linux-import.test.js # ELF/AppImage/.desktop detection + icons +node test/linux-links.test.js # link opening: shim binds + mime seed node test/linux-sync.test.js # linux_pfx stays out of a sync node test/linux-e2e.js # REAL run: plain + bwrap (/etc read-only, home in prefix) npm start # click through the flow you touched diff --git a/files/translations/en-us.json b/files/translations/en-us.json index bac6a51..09be67c 100644 --- a/files/translations/en-us.json +++ b/files/translations/en-us.json @@ -125,6 +125,7 @@ "sandbox.badgeOff": "isolation off", "sandbox.badgeRequired": "bwrap required", "sandbox.required": "This app needs a working bubblewrap sandbox: {0}", + "sandbox.linkOpener": "PLWL link opener", "config.save": "Save changes", "config.shortcut": "Create shortcut", "config.shortcutCreated": "Shortcut for {0} created (menu + desktop)", diff --git a/files/translations/pl.json b/files/translations/pl.json index 470e7c4..a3a5e7d 100644 --- a/files/translations/pl.json +++ b/files/translations/pl.json @@ -125,6 +125,7 @@ "sandbox.badgeOff": "izolacja wyłączona", "sandbox.badgeRequired": "wymaga bwrap", "sandbox.required": "Ta aplikacja wymaga działającego sandboxa bubblewrap: {0}", + "sandbox.linkOpener": "PLWL - otwieranie linków", "config.save": "Zapisz zmiany", "config.shortcut": "Utwórz skrót", "config.shortcutCreated": "Skrót dla {0} utworzony (menu + pulpit)", diff --git a/src/linuxrunner.js b/src/linuxrunner.js index cc401fe..daf1571 100644 --- a/src/linuxrunner.js +++ b/src/linuxrunner.js @@ -10,7 +10,8 @@ const os = require('os') const path = require('path') const { DIRS, readJson, writeJson } = require('./paths') const { prefixPath, prefixLinuxRoot } = require('./prefixes') -const { prefixNameForGame } = require('./library') +const { prefixNameForGame, loadSettings } = require('./library') +const i18n = require('./i18n') const { spawnTracked, parseArgs } = require('./runner') const { buildBwrapArgs, SHARE_ROOT } = require('./sandbox') @@ -104,6 +105,30 @@ const DESKTOP_SEEDS = [ // host without an import. const DATA_SHARES = ['fonts', 'icons', 'themes', 'color-schemes'] +// A clicked link is the host desktop's business: in here there is no default +// browser at all, because the association (mimeapps.list) and the .desktop +// file it names live in the host's own home. Handing the URI to the host's +// portal is the only route that ends in the browser the user actually chose. +const PORTAL_BUS = 'org.freedesktop.portal.Desktop' +const PORTAL_METHOD = 'org.freedesktop.portal.OpenURI.OpenURI' +const PORTAL_BINS = ['/usr/libexec/xdg-desktop-portal', '/usr/lib/xdg-desktop-portal', '/usr/lib64/xdg-desktop-portal'] +const PORTAL_DIRS = ['/usr/share/xdg-desktop-portal/portals', '/usr/local/share/xdg-desktop-portal/portals'] +const OPEN_BINS = ['/usr/bin/xdg-open', '/bin/xdg-open', '/usr/local/bin/xdg-open'] +// Launcher-owned files, kept in the redirected home: the app never edits them, +// and each is rewritten whenever it differs. The prefix root is not mounted in +// the sandbox, so nothing a link needs may live there. +const PLWL_DIR = '.plwl' +const SHIM_NAME = 'xdg-open' +const OPENER_NAME = 'open-url' +const OPENER_DESKTOP = 'plwl-url-opener.desktop' +const SHIM_REL = path.join('home', PLWL_DIR, SHIM_NAME) +const OPENER_REL = path.join('home', PLWL_DIR, OPENER_NAME) +const MIME_REL = path.join('config', 'mimeapps.list') +const DESKTOP_REL = path.join('data', 'applications', OPENER_DESKTOP) +// What a link in an app resolves to. Nothing else about the app's file types +// is touched: the rest of the MIME lists stay the system's. +const LINK_TYPES = ['x-scheme-handler/http', 'x-scheme-handler/https', 'text/html'] + function hostShareDir() { return path.join(os.homedir(), '.local', 'share') } @@ -112,6 +137,138 @@ function dataShares() { return DATA_SHARES.map(name => path.join(hostShareDir(), name)).filter(dir => fs.existsSync(dir)) } +// The session bus address names the socket, and a stale address is how the +// portal "disappears" after a session restart. +function busSocket(address) { + for (const part of String(address || '').split(';')) { + const match = part.match(/^unix:path=([^,]+)/) + if (match) return match[1] + } + return '' +} + +function portalDescribed() { + return PORTAL_DIRS.some(dir => { + try { + return fs.readdirSync(dir).some(file => file.endsWith('.portal')) + } catch { + return false + } + }) +} + +// Sending a URI to a portal that is not there fails hard, it does not fall +// back (measured: GIO answers "Failed to create OpenURI proxy"), so the check +// stays on this side of the sandbox. +function portalReady() { + const bus = process.env.DBUS_SESSION_BUS_ADDRESS + if (!bus) return false + const socket = busSocket(bus) + if (socket && !fs.existsSync(socket)) return false + return PORTAL_BINS.some(bin => fs.existsSync(bin)) || portalDescribed() +} + +function readText(file) { + try { + return fs.readFileSync(file, 'utf8') + } catch { + return '' + } +} + +function writeIfChanged(file, text, mode) { + try { + fs.mkdirSync(path.dirname(file), { recursive: true }) + if (readText(file) !== text) fs.writeFileSync(file, text) + fs.chmodSync(file, mode) + return file + } catch { + return '' + } +} + +// The one shell snippet both hand-offs need: give the URI to the host portal. +function portalOpen(uri) { + return [ + `gdbus call --session --dest ${PORTAL_BUS} \\`, + ' --object-path /org/freedesktop/portal/desktop \\', + ` --method ${PORTAL_METHOD} "" ${uri} "{}"` + ].join('\n') +} + +// The stand-in for xdg-open inside the sandbox. The host's own script is +// mounted at the fallback path, so what this cannot hand over - a plain path, +// or a portal that stopped answering - behaves exactly as it did before. +function writeUrlShim(root) { + const script = `#!/bin/sh +# Written by PLWL: a link belongs to the host desktop, so it is opened there. +case "$1" in + *://*|mailto:*) + if command -v gdbus >/dev/null 2>&1; then + ${portalOpen('"$1"')} >/dev/null 2>&1 && exit 0 + fi + ;; +esac +exec ${path.join(SHARE_ROOT, SHIM_NAME)} "$@" +` + return writeIfChanged(path.join(root, SHIM_REL), script, 0o755) +} + +// What the seeded desktop entry runs: the portal hand-off, and nothing else - +// a browser started in here would be the wrong one, with an empty profile +// growing inside the prefix. +function writeUrlOpener(root) { + const script = `#!/bin/sh +# Written by PLWL: hand the link to the host desktop. +if command -v gdbus >/dev/null 2>&1; then + ${portalOpen('"$1"')} >/dev/null 2>&1 && exit 0 +fi +exit 1 +` + return writeIfChanged(path.join(root, OPENER_REL), script, 0o755) +} + +// The entry's display name. A translation that is not loaded answers with its +// own key, and that would end up in a chooser dialog, so it is never used. +function linkOpenerName() { + const text = i18n.translate(loadSettings().language, 'sandbox.linkOpener') + return text === 'sandbox.linkOpener' ? 'PLWL' : text +} + +// GIO resolves an URI in-process (gtk_show_uri, `gio open`) against the MIME +// lists, and the host's default browser is not among the choices in here: it +// would open a system browser, or none at all. Naming our opener as the +// default for the link types leaves that resolution alone and changes only its +// answer. The portal itself is not reachable this way - GIO looks for a sandbox +// marker this launcher does not fake (measured: GIO_USE_PORTALS opens nothing). +function writeMimeSeed(root, home) { + const desktop = [ + '[Desktop Entry]', + 'Type=Application', + `Name=${linkOpenerName()}`, + `Exec="${path.join(home, PLWL_DIR, OPENER_NAME)}" %u`, + `MimeType=${LINK_TYPES.join(';')};`, + 'NoDisplay=true', + 'Terminal=false', + '' + ].join('\n') + writeIfChanged(path.join(root, DESKTOP_REL), desktop, 0o644) + const mime = ['[Default Applications]', ...LINK_TYPES.map(type => `${type}=${OPENER_DESKTOP};`), ''].join('\n') + return writeIfChanged(path.join(root, MIME_REL), mime, 0o644) +} + +// Everything a link needs: the portal hand-off, the association naming it as +// the default, and - in a sandbox - xdg-open replaced by the same hand-off. +// Nothing is done on a machine without a portal: a URI sent to a portal that +// is not there fails hard, it does not fall back. +function urlRouting({ root, home, sandboxed }) { + if (!portalReady() || !writeUrlOpener(root)) return null + writeMimeSeed(root, home) + const target = OPEN_BINS.find(bin => fs.existsSync(bin)) + const shim = sandboxed && target ? writeUrlShim(root) : '' + return { target: target || '', shim, real: target || '' } +} + function hashOf(file) { try { return crypto.createHash('sha1').update(fs.readFileSync(file)).digest('hex') @@ -262,7 +419,9 @@ function buildLinuxEnv({ game, backend = 'env' }) { if (game.forceX11) Object.assign(env, X11_ENV) // the app's own environment comes last: it overrides everything above for (const [k, v] of Object.entries(game.env || {})) env[k] = v - return { env, root, home, prefixName, prefixDir: prefixPath(prefixName) } + // a clicked link must leave through the host's portal; `home` is where the + // seeded desktop entry has to find the opener, so it is resolved first + return { env, root, home, prefixName, prefixDir: prefixPath(prefixName), routing: urlRouting({ root, home, sandboxed }) } } // bwrap when it works, plain run otherwise - unless the app demands a sandbox. @@ -313,7 +472,7 @@ async function runLinuxGame({ game, sandbox, onExit, openFile, handoff = false } const argList = parseArgs(game.args) if (openFile) argList.push(linuxPathFor(openFile)) - const { env, root } = buildLinuxEnv({ game, backend: chosen.backend }) + const { env, root, routing } = buildLinuxEnv({ game, backend: chosen.backend }) const header = [isolationLine(chosen)] if (game.forceX11) header.push('[plwl] x11 forced (XWayland)') @@ -322,7 +481,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) }), '--', exe, ...argList] + 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] header.push(`[plwl] HOME=${env.HOME}`) } @@ -336,6 +495,16 @@ module.exports = { DESKTOP_SEEDS, DATA_SHARES, X11_ENV, + SHIM_REL, + OPENER_REL, + MIME_REL, + DESKTOP_REL, + busSocket, + portalReady, + writeUrlShim, + writeUrlOpener, + writeMimeSeed, + urlRouting, writableAppDir, ensureLinuxPfx, resetSeededConfig, diff --git a/src/sandbox.js b/src/sandbox.js index 44644ca..bfc990e 100644 --- a/src/sandbox.js +++ b/src/sandbox.js @@ -114,7 +114,8 @@ function buildBwrapArgs({ hideHome = false, etcRoot = '', unshareNet = false, - appDir = '' + appDir = '', + urlOpener = null }) { const xdgDir = sub => path.join(home, sub) return [ @@ -134,6 +135,12 @@ function buildBwrapArgs({ ...(x11 ? ['--ro-bind', x11, x11] : []), // the host's theme data, read-only: fonts, icons, colour schemes ...shares.flatMap(dir => ['--ro-bind', dir, path.join(SHARE_ROOT, path.basename(dir))]), + // a link clicked in here belongs to the host desktop: xdg-open is replaced + // by a shim that hands the URI to the host's portal, and the host's own + // script stays mounted aside as what that shim falls back to + ...(urlOpener && urlOpener.shim + ? ['--ro-bind', urlOpener.real, path.join(SHARE_ROOT, 'xdg-open'), '--ro-bind', urlOpener.shim, urlOpener.target] + : []), // hard profile: nothing of anybody's /home is even readable ...(hideHome ? ['--tmpfs', '/home', '--tmpfs', '/root', '--tmpfs', '/mnt', '--tmpfs', '/media'] : []), // the app's own folder stays writable (portable apps keep logs/data next From 3f57682a9ba28239946df83317620fe028576871 Mon Sep 17 00:00:00 2001 From: olcxja Date: Wed, 7 Oct 2026 01:46:26 +0200 Subject: [PATCH 02/16] try to improve link handling --- README.md | 2 +- development.md | 1 + src/linuxapp.js | 5 ----- src/linuxrunner.js | 29 ++++++++++++++++++++++------- src/sandbox.js | 7 ++++++- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f18276c..f6ff87a 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Per app you choose the **Isolation** policy: *Automatic* (bwrap when it works, p ## "Open with PLWL" -The desktop entry registers `.exe/.msi/.bat/.cmd/.lnk` in file managers. Opening one shows a popup to pick the **Wine/Proton build** and **prefix** for that run (defaults preselected, nothing imported). A second instance hands the path to the running one. App shortcuts work as **Open With** targets too: the app receives the file as the Windows path it would get on Windows — `C:\...` inside its prefix, `Z:\...` otherwise. A file handed to an already running app goes to that instance instead of a second tracked run. +The desktop entry registers `.exe/.msi/.bat/.cmd/.lnk` in file managers. Opening one shows a popup to pick the **Wine/Proton build** and **prefix** for that run (defaults preselected, nothing imported). A second instance hands the path to the running one. App shortcuts work as **Open With** targets too: the app receives the file as the Windows path it would get on Windows — `C:\...` inside its prefix, `Z:\...` otherwise. A file handed to an already running app goes to that instance instead of a second tracked run. A **Linux app shortcut** is an Open With target the same way: the app gets the plain absolute path, and that one file is mounted read-write inside its sandbox — the deliberate exception to "only its home and its app folder are writable", because it is the document you chose to hand over. ## LAN syncing diff --git a/development.md b/development.md index 45bb67d..c8c3127 100644 --- a/development.md +++ b/development.md @@ -85,6 +85,7 @@ Renderer never touches Node/Electron directly — everything goes through the `w - **Reset Linux config** on every prefix row removes exactly what PLWL seeded (DESKTOP_SEEDS, the pulse cookie, `home/.Xauthority`, `.seeded.json`) plus the folders that existed only for the seed, so the next start seeds clean. syncDesktopConfig can only follow a copy it can still prove is its own; the reset does not argue. App data (`data/`, `cache/`, `state/`, `config//`, the rest of `home/`) is never touched, and a running app from that prefix blocks it (the usual `inUse` guard). - The user's real `~` is deliberately invisible in the sandbox (HOME is bound straight to `{prefix}/linux_pfx/home`), so absolute paths an app wrote into its config before the import (Prism's instance `JavaPath`) do not resolve — that is what `isolation: 'off'` is for. - A clicked link belongs to the host desktop, so it leaves through `org.freedesktop.portal.OpenURI` — both routes, because two different things open a link. The `xdg-open` BINARY is replaced inside the sandbox (a written shim `--ro-bind` over `/usr/bin/xdg-open`, the host's own script parked at `/tmp/.plwl-host/xdg-open` as what the shim falls back to for anything that is not a URI): Qt execs it (measured — `QGenericUnixServices` picks `xdg-open` first, and reaches the portal itself only under `/.flatpak-info`/`SNAP`, which a bwrap profile does not have) and so does Electron. GIO resolves an URI IN-PROCESS, which no shim can reach: for that the prefix seeds `home/.plwl/open-url` (launcher-written, like the shim) plus a desktop entry and a `mimeapps.list` naming it the default for `x-scheme-handler/http|https` and `text/html`. Without the seed GIO falls back to the host's `/usr/share` list — measured: it offered `brave-origin.desktop`, and `gio open` answered "The specified location is not supported". Measured end to end (both backends): the portal launches the host's `helium.desktop` with the exact URI. `GIO_USE_PORTALS=1` was measured and REJECTED: it opened NOTHING and still reported success (GIO's portal path wants a sandbox marker this launcher does not fake), while on a machine WITHOUT a portal it fails hard (“Failed to create OpenURI proxy”). The whole wiring is therefore written only when a session bus and a portal are present (`portalReady`), and a KDE-native app resolving through KIO in-process (`kde-open`) stays uncovered — KDE ignores the seeded list (measured). +- A file handed over (a shortcut's `--file %f`, a drop on it) is the ONE path the sandbox cannot see by itself, and all three reasons are real: 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. `handedFileBinds` returns it for `--bind` at the same path, placed AFTER the app data binds so it wins over the home mounted there, and writable — the way Wine hands a file over as `Z:\…` and may save it (parity with the Wine side is the point: same shortcut, same outcome). Prefix data is skipped, being the app's own writable home already; a folder and a path that is gone are skipped too, since a missing bind source makes bwrap refuse the launch. The argv is untouched: `linuxPathFor` still passes the host path to the app. Only a *new* run gets the mount — a handoff into an app already running in its own namespace cannot, and the app reports that itself. - Not built: a private or overlay `/etc` (`buildBwrapArgs` accepts `etcRoot`, nothing sets it; `--ro-bind / /` leaves `/etc` read-only, which is all we promise today), `--tmpfs /home` against OTHER users' homes (`hideHome` is plumbed, no UI) and `dataMode` — app data always lands in `{prefix}/linux_pfx`. - Measured, not assumed (Debian 13, kernel 6.12, `bwrap` 0.12.0): the functional probe passes here, no firejail/proot/fuse-overlayfs on the box, `/etc` is 16 MB and its `machine-id` is read-only even on the host. diff --git a/src/linuxapp.js b/src/linuxapp.js index 64f724c..2a03dd1 100644 --- a/src/linuxapp.js +++ b/src/linuxapp.js @@ -252,13 +252,8 @@ function findIconFile(spec, baseDir) { } module.exports = { - ELF_MAGIC, - isElfBuffer, - isElfSync, findLinuxExe, - parseDesktopEntry, readDesktopEntry, - desktopExecPath, desktopFileFor, findIconFile, pngOrSvg diff --git a/src/linuxrunner.js b/src/linuxrunner.js index daf1571..eb8db3b 100644 --- a/src/linuxrunner.js +++ b/src/linuxrunner.js @@ -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 } diff --git a/src/sandbox.js b/src/sandbox.js index bfc990e..2bce2c8 100644 --- a/src/sandbox.js +++ b/src/sandbox.js @@ -115,6 +115,7 @@ function buildBwrapArgs({ etcRoot = '', unshareNet = false, appDir = '', + openFiles = [], urlOpener = null }) { const xdgDir = sub => path.join(home, sub) @@ -152,6 +153,10 @@ function buildBwrapArgs({ '--bind', path.join(dataRoot, 'data'), xdgDir(path.join('.local', 'share')), '--bind', path.join(dataRoot, 'cache'), xdgDir('.cache'), '--bind', path.join(dataRoot, 'state'), xdgDir(path.join('.local', 'state')), + // a file handed over from the desktop, mounted where the app was told it + // is: the prefix home sits ON TOP of the user's real home and /tmp is + // emptied, so such a document would otherwise simply not be there + ...openFiles.flatMap(file => ['--bind', file, file]), // Wayland, PipeWire, PulseAudio and the session bus all live here ...(runUser ? ['--bind', runUser, runUser] : []), ...(etcRoot ? ['--bind', etcRoot, '/etc'] : []), @@ -164,4 +169,4 @@ function buildBwrapArgs({ ] } -module.exports = { createSandboxProbe, buildBwrapArgs, SHARE_ROOT, PROBE_TIMEOUT_MS } +module.exports = { createSandboxProbe, buildBwrapArgs, SHARE_ROOT } From 9748b981637f6b57b01917a0dde4bd259800a83d Mon Sep 17 00:00:00 2001 From: olcxja Date: Wed, 7 Oct 2026 08:26:57 +0200 Subject: [PATCH 03/16] improve native isolation --- README.md | 15 ++-- development.md | 23 +++--- files/translations/en-us.json | 26 ++++--- files/translations/pl.json | 26 ++++--- renderer/app.js | 88 ++++++++++++++++++++--- renderer/index.html | 1 + renderer/style.css | 9 +++ src/fsutil.js | 45 +++++++++++- src/ipc/games.js | 15 +++- src/ipc/index.js | 4 +- src/library.js | 25 +++++-- src/linuxrunner.js | 132 ++++++++++++++++++++++++---------- src/main.js | 11 ++- src/preload.js | 3 + src/sandbox.js | 21 ++++-- 15 files changed, 345 insertions(+), 99 deletions(-) diff --git a/README.md b/README.md index f6ff87a..95b19b7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PLWL — Portable Linux Wine Launcher -A portable launcher for Windows games and applications on Linux — and for native Linux apps, run with their own isolated home (bubblewrap when available). +A portable launcher for Windows games and applications on Linux — and for native Linux apps, run with their own home and a chosen isolation level (bubblewrap when available). ## Portable layout @@ -44,7 +44,7 @@ The entry point is found automatically in the picked folder: an ELF binary or `. A native app runs with its **own home folder**: `HOME`, `XDG_CONFIG_HOME`, `XDG_DATA_HOME`, `XDG_CACHE_HOME` and `XDG_STATE_HOME` point into `files/wineprefixes//linux_pfx/`, so config, cache and state land there instead of in your `~`. The prefix select in the app's config picks which one; **Open data folder** takes you to it. `linux_pfx` is machine-local — a LAN sync never pushes it and never deletes it. -When **bubblewrap** is installed *and* usable (PLWL probes it with a real run, not `which bwrap` — Ubuntu's AppArmor profile kills it even when it is installed), the app also gets its own namespaces: `/` is mounted read-only, so only **its home folder and its own app folder stay writable** — anything else fails with `EROFS`. The app folder is included on purpose: portable apps keep their logs and data next to themselves (Prism Launcher refuses to start otherwise). System trees are never handed out writable, not even when the app itself lives in one. Screens, audio (X11/Wayland, PulseAudio/PipeWire), gamepads and networking keep working. `XDG_RUNTIME_DIR` stays the host's, so the session bus is shared — the sandbox is not airtight, and the UI says so rather than pretending. +When **bubblewrap** is installed *and* usable (PLWL probes it with a real run, not `which bwrap` — Ubuntu's AppArmor profile kills it even when it is installed), the two sandboxed levels also give the app its own namespaces: `/` is mounted read-only, so only **its home folder and its own app folder stay writable** — anything else fails with `EROFS`. Relaxed adds exactly one mount on top of that profile (the writable host filesystem described below); everything else on this page is the same at both levels. The app folder is included on purpose: portable apps keep their logs and data next to themselves (Prism Launcher refuses to start otherwise). System trees are never handed out writable, not even when the app itself lives in one. Screens, audio (X11/Wayland, PulseAudio/PipeWire), gamepads and networking keep working. `XDG_RUNTIME_DIR` stays the host's, so the session bus is shared — the sandbox is not airtight, and the UI says so rather than pretending. The redirected home starts with a **copy of your desktop preferences** — `kdeglobals`, the GTK 3/4 settings and `user-dirs.dirs` — so the app keeps your theme instead of falling back to its built-in light look. The copy keeps following your host as long as the app has not changed it: a theme change arrives on the next launch, and the moment the app writes its own version, PLWL never touches it again. Your own **fonts, icons, themes and colour schemes are not copied but mounted read-only** inside the sandbox and added to `XDG_DATA_DIRS`, so they follow the host live and nothing can be written back to your `~`. @@ -56,11 +56,18 @@ Imported trees get **normalised permissions**: every file gets the owner's `rwx` Some apps draw their window icon themselves, which Wayland does not allow — Minecraft (LWJGL 3.4+) is the known case: its taskbar icon turns into the generic Wayland one. The per-app **Force X11 (XWayland)** switch moves the app *and the programs it launches* back to X11, where the icon works again. -Per app you choose the **Isolation** policy: *Automatic* (bwrap when it works, plain run when it does not), *Off*, or *Required* (refuse to start instead of running unsandboxed). The backend actually used is always visible: a badge on the library card, a `[plwl] isolation: …` line in the app log, and a status card in Settings with **Check again**. When bwrap is missing, PLWL says so once instead of quietly launching without it. +Per app you choose the **Isolation** level — what the app gets besides its own home folder: + +- **None** — a plain run. The app sees your real filesystem exactly as any other program of yours does: what a shortcut hands it works, including into an app that is already running. +- **Relaxed** — the sandbox *plus* your whole filesystem mounted writable at `/tmp/plwl-fs-root`. A document handed over behaves natively — it opens where the app was told it is, it can be saved, and it also reaches an app that is already running, because the mount is there from the first second of every run. The price is real and the UI says it: at this level the app can change anything your user can. +- **Isolated** — the sandbox without that mount. The system stays read-only, and a document handed over is **copied** first, into `plwl-handoff` inside the app's own home folder; the app works on that copy (so the original cannot be touched), and a copy big enough to be noticed shows a progress popup in the launcher. +- **Automatic** (default) — Relaxed where bubblewrap works, None where it does not. + +An explicit Relaxed or Isolated on a machine without a working bubblewrap **refuses to start** instead of quietly dropping the promise; Automatic is the one level allowed to weaken itself. What the app really ran as is always visible: a badge on the library card, a `[plwl] isolation: …` line in the app log, and a status card in Settings with **Check again**. When bwrap is missing, PLWL says so once instead of quietly launching without it. ## "Open with PLWL" -The desktop entry registers `.exe/.msi/.bat/.cmd/.lnk` in file managers. Opening one shows a popup to pick the **Wine/Proton build** and **prefix** for that run (defaults preselected, nothing imported). A second instance hands the path to the running one. App shortcuts work as **Open With** targets too: the app receives the file as the Windows path it would get on Windows — `C:\...` inside its prefix, `Z:\...` otherwise. A file handed to an already running app goes to that instance instead of a second tracked run. A **Linux app shortcut** is an Open With target the same way: the app gets the plain absolute path, and that one file is mounted read-write inside its sandbox — the deliberate exception to "only its home and its app folder are writable", because it is the document you chose to hand over. +The desktop entry registers `.exe/.msi/.bat/.cmd/.lnk` in file managers. Opening one shows a popup to pick the **Wine/Proton build** and **prefix** for that run (defaults preselected, nothing imported). A second instance hands the path to the running one. App shortcuts work as **Open With** targets too: the app receives the file as the Windows path it would get on Windows — `C:\...` inside its prefix, `Z:\...` otherwise. A file handed to an already running app goes to that instance instead of a second tracked run. A **Linux app shortcut** is an Open With target the same way, and what the app is handed depends on its isolation level: at **None** the plain absolute path, at **Relaxed** the same file through the writable host mount (`/tmp/plwl-fs-root/…`) — which is also the only shape an app that is *already running* can resolve, since a mount cannot be added to a live sandbox — and at **Isolated** a copy in `plwl-handoff` inside the app's own home folder, so the original stays untouched. ## LAN syncing diff --git a/development.md b/development.md index c8c3127..1d6bc09 100644 --- a/development.md +++ b/development.md @@ -15,11 +15,14 @@ src/ main process (Node/Electron backend) lansync.js LAN sync handlers (identity, devices, re-roll, sync + progress) runner.js spawns wine/proton (env, prefix, playtime, logs) and owns spawnTracked() - the log/playtime/exit tail every run shares - linuxrunner.js native Linux apps: redirected HOME/XDG, bwrap or plain run + linuxrunner.js native Linux apps: redirected HOME/XDG, the isolation level + (none/relaxed/isolated/auto) and the handed-document path linuxapp.js native app detection (ELF/AppImage/.desktop) + icon lookup sandbox.js bubblewrap probe (functional, cached) + buildBwrapArgs + (+ FS_ROOT, the one mount the relaxed level adds) library.js apps registry (apps.json) + settings + playtime files, plus - the "which prefix does this app use" / in-use guards + the "which prefix does this app use" / in-use guards and + the isolation-mode gate on the way in wines.js wine/proton build scan, registry, portable symlink healing prefixes.js prefix registry (files/wineprefixes) symlinks.js relative symlink rewiring + executable-bit restoration @@ -67,12 +70,13 @@ Renderer never touches Node/Electron directly — everything goes through the `w - Registries (apps.json, wines.json, prefixes.json) are rewritten whole via writeJson(); playtime lives in its own tiny file so the registry is not rewritten while a game runs. - Deleting user data needs a confirm modal; best-effort cleanup is try/catch-and-ignore with a comment saying why it is safe to ignore. - Windows apps run through runGame()/buildEnv() — never spawn wine directly elsewhere (prefix handling, Proton env and playtime live there). -- Native Linux apps run through linuxrunner.runLinuxGame()/buildLinuxEnv() the same way: HOME and the XDG folders are redirected into `{prefix}/linux_pfx/`, and bwrap (when the probe says it works) forces the same layout with mounts. Never spawn a native app elsewhere. `game.kind` is absent on old entries — that means Windows; `game.isolation` is `auto` (bwrap when usable, plain run otherwise), `off` or `require` (refuse to start instead of quietly weakening). The chosen backend always lands in the log and the UI (a silent downgrade is the failure mode to avoid). -- Under bwrap ONLY two things stay writable: the redirected home and the app's own folder (`writableAppDir`: inside files/apps, or the folder the app was imported from — never `/usr`, `/etc`, `/bin`… and never files/wines). Portable apps write logs and data next to themselves and a read-only app folder makes them refuse to start (Prism Launcher: "couldn't create a log file - Read-only file system"). Everything else is `EROFS` by design. +- Native Linux apps run through linuxrunner.runLinuxGame()/buildLinuxEnv() the same way: HOME and the XDG folders are redirected into `{prefix}/linux_pfx/`, and bwrap (when the probe says it works) forces the same layout with mounts. Never spawn a native app elsewhere. `game.kind` is absent on old entries — that means Windows; `game.isolation` is one of four levels, resolved by linuxrunner.resolveLevel: `none` (plain run), `relaxed` (bwrap + the whole host filesystem mounted writable at sandbox.FS_ROOT) and `isolated` (bwrap with the stock read-only profile), with `auto` (default) meaning relaxed where bwrap works and none where it does not. Only `auto` may weaken itself — an explicit relaxed/isolated answers `sandbox-required` instead ("no silent downgrade"), and library.js maps the values launcher 0.5.x wrote (`off` → none, `require` → isolated) both when reading the registry and when a patch is saved. The level always lands in the log and the UI. resolveLevel awaits the probe when nothing has measured yet: a shortcut boots HEADLESS, so no renderer ran `sandbox:status` — without that wait `auto` would read an empty cache and quietly pick `none` (and an explicit level would refuse a machine that can sandbox perfectly well). +- Under bwrap ONLY two things stay writable: the redirected home and the app's own folder (`writableAppDir`: inside files/apps, or the folder the app was imported from — never `/usr`, `/etc`, `/bin`… and never files/wines). Portable apps write logs and data next to themselves and a read-only app folder makes them refuse to start (Prism Launcher: "couldn't create a log file - Read-only file system"). Everything else is `EROFS` by design — at the isolated level. Relaxed is the deliberate exception and says so in the UI: `FS_ROOT` is the same filesystem, mounted writable, so "everything else" is only unreachable through the real paths. - Two pipes feed one log in spawnTracked: neither may end the stream (pipe(ws, { end: false }), closed when both sources drained, at the latest LOG_DRAIN_MS after the exit) and the write stream carries an error listener. Ending it at `exit` while a pipe still had data killed the whole launcher with ERR_STREAM_WRITE_AFTER_END. - A prefix or wine build a running app uses cannot be renamed/deleted (wine holds files open there): the guards sit next to the handlers in src/ipc/, use the games service's running list plus library.js helpers (prefixNameForGame/gamesUsingPrefix/is*InUse) and answer `{ ok:false, error:'inUse'|'hasApps', apps:[names] }` for the toast. -- Long operations stream progress through the single import:progress slot as `{ phase: 'count'|'copy'|'remove', files, bytes, totalFiles, totalBytes }` (runWithProgress for deletes/imports). Emit 'count' (a treeSize walk) first, copy/remove through the fsutil helpers. +- Long operations stream progress through the single import:progress slot as `{ phase: 'count'|'copy'|'remove', files, bytes, totalFiles, totalBytes }` (runWithProgress for deletes/imports). Emit 'count' (a treeSize walk) first, copy/remove through the fsutil helpers. An isolated hand-off has its own slot, handoff:progress (`{ phase: 'copy'|'done'|'error', name, bytes, totalBytes, notice }`), because it can start before the window exists: main.js gets the event first and, when `notice` is set (a copy above linuxrunner.STAGE_NOTICE_BYTES), puts the launcher window up so the renderer's popup can be seen; below that the copy is over before a window could paint. Copies of one file go through fsutil.copyFileProgress (streamed, throttled by progressGate, `.part` + rename). - CSS: reuse the existing variables/classes (.button, .field-label, .custom-select, form-card); spacing comes from --button-margin and flex gaps, not per-element magic numbers. +- The blanket `transform: translateZ(0)` (crisper small glyphs) makes every element its own stacking context, so a select's own z-index cannot escape the wrapper it sits in: a list opened inside `.linux-only`, `.win-only` or an override row was painted UNDER the field label and textarea that follow it (measuring with `elementsFromPoint` over the open list returned the label). CustomSelect lifts the chain instead of the host — `lift()` adds `.select-lift` to every STATIC ancestor while the list is open, and `close()`/`closeAll()` take it off again; positioned ancestors are skipped, so the fixed modal overlay keeps stacking over every view on its own. ### Native Linux apps @@ -83,9 +87,10 @@ Renderer never touches Node/Electron directly — everything goes through the `w - SESSION_MANAGER is dropped in the sandbox: the session socket sits in the private `/tmp`, so the pointer led nowhere (Qt: "Could not open network socket"). - Imports normalise permissions (fsutil.chmodTree): owner `rwx`, `x` mirrored from `r` (0644 → 0755). Sources are archives, FAT sticks and read-only backups. - **Reset Linux config** on every prefix row removes exactly what PLWL seeded (DESKTOP_SEEDS, the pulse cookie, `home/.Xauthority`, `.seeded.json`) plus the folders that existed only for the seed, so the next start seeds clean. syncDesktopConfig can only follow a copy it can still prove is its own; the reset does not argue. App data (`data/`, `cache/`, `state/`, `config//`, the rest of `home/`) is never touched, and a running app from that prefix blocks it (the usual `inUse` guard). -- The user's real `~` is deliberately invisible in the sandbox (HOME is bound straight to `{prefix}/linux_pfx/home`), so absolute paths an app wrote into its config before the import (Prism's instance `JavaPath`) do not resolve — that is what `isolation: 'off'` is for. +- With HOME bound straight to `{prefix}/linux_pfx/home`, the user's real `~` is invisible to the app — one reason absolute paths an app wrote into its config before the import (Prism's instance `JavaPath`) do not resolve. `relaxed` does not change that shadowing, but it does make the real filesystem reachable through `FS_ROOT`/home/… — and `none` gives the app the real paths outright, which is what those two levels are for. - A clicked link belongs to the host desktop, so it leaves through `org.freedesktop.portal.OpenURI` — both routes, because two different things open a link. The `xdg-open` BINARY is replaced inside the sandbox (a written shim `--ro-bind` over `/usr/bin/xdg-open`, the host's own script parked at `/tmp/.plwl-host/xdg-open` as what the shim falls back to for anything that is not a URI): Qt execs it (measured — `QGenericUnixServices` picks `xdg-open` first, and reaches the portal itself only under `/.flatpak-info`/`SNAP`, which a bwrap profile does not have) and so does Electron. GIO resolves an URI IN-PROCESS, which no shim can reach: for that the prefix seeds `home/.plwl/open-url` (launcher-written, like the shim) plus a desktop entry and a `mimeapps.list` naming it the default for `x-scheme-handler/http|https` and `text/html`. Without the seed GIO falls back to the host's `/usr/share` list — measured: it offered `brave-origin.desktop`, and `gio open` answered "The specified location is not supported". Measured end to end (both backends): the portal launches the host's `helium.desktop` with the exact URI. `GIO_USE_PORTALS=1` was measured and REJECTED: it opened NOTHING and still reported success (GIO's portal path wants a sandbox marker this launcher does not fake), while on a machine WITHOUT a portal it fails hard (“Failed to create OpenURI proxy”). The whole wiring is therefore written only when a session bus and a portal are present (`portalReady`), and a KDE-native app resolving through KIO in-process (`kde-open`) stays uncovered — KDE ignores the seeded list (measured). -- A file handed over (a shortcut's `--file %f`, a drop on it) is the ONE path the sandbox cannot see by itself, and all three reasons are real: 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. `handedFileBinds` returns it for `--bind` at the same path, placed AFTER the app data binds so it wins over the home mounted there, and writable — the way Wine hands a file over as `Z:\…` and may save it (parity with the Wine side is the point: same shortcut, same outcome). Prefix data is skipped, being the app's own writable home already; a folder and a path that is gone are skipped too, since a missing bind source makes bwrap refuse the launch. The argv is untouched: `linuxPathFor` still passes the host path to the app. Only a *new* run gets the mount — a handoff into an app already running in its own namespace cannot, and the app reports that itself. +- A file handed over (a shortcut's `--file %f`, a drop on it) is the one path the sandbox cannot see 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. Per-file `--bind` (what 0.5.0 did) is the wrong tool: a mount cannot be added to a namespace that is ALREADY running, so a hand-off into a running app could never be served that way. `handedPathFor` instead names the document in the one shape the chosen level can reach, and the app is told nothing else: `none` → the real path; `relaxed` → `FS_ROOT` + the real path; `isolated` → a copy in `{prefix}/linux_pfx/home/plwl-handoff/`, which is a live bind of the app's home, so it reaches a running app too (measured end to end in test/linux-e2e.js: both levels hand a document to a sandbox that is already up). Copies are one per name and refreshed on every open (the folder cannot grow), written through a `.part` name and renamed so nothing ever reads a half-written document, and the app's edits stay in the copy — that IS the level's promise. A handed path that is gone fails the hand-off instead of launching an app with no document. +- `FS_ROOT` (`/tmp/plwl-fs-root`) is where relaxed mounts the host filesystem, and it has to live under the private `/tmp`: bubblewrap creates the mount point itself, and the root of a read-only root cannot be written to (measured on 0.12.0: `Can't create file /PLWL_FS_ROOT: Read-only file system`, for a `--dir` before the `--ro-bind / /` too). Measured also: through it the real `~` reads, a write lands on the real file, and a file created AFTER a sandboxed run started is visible inside it — that last one is what makes a hand-off into a running app possible at all. - Not built: a private or overlay `/etc` (`buildBwrapArgs` accepts `etcRoot`, nothing sets it; `--ro-bind / /` leaves `/etc` read-only, which is all we promise today), `--tmpfs /home` against OTHER users' homes (`hideHome` is plumbed, no UI) and `dataMode` — app data always lands in `{prefix}/linux_pfx`. - Measured, not assumed (Debian 13, kernel 6.12, `bwrap` 0.12.0): the functional probe passes here, no firejail/proot/fuse-overlayfs on the box, `/etc` is 16 MB and its `machine-id` is read-only even on the host. @@ -131,12 +136,12 @@ node test/lansync-pending-links.test.js # links to files created later, startup node test/lansync-consent.test.js # accept / decline / timeout gate node test/lansync-token.test.js # long-sync token expiry (sliding TTL) node test/bench-sync.js # timing: cold vs cached sync -node test/linux-sandbox.test.js # bwrap argv profile + auto/off/require choice +node test/linux-sandbox.test.js # bwrap argv profile + the four levels, handed paths, mode migration node test/linux-env.test.js # redirected HOME/XDG_* for both backends node test/linux-import.test.js # ELF/AppImage/.desktop detection + icons node test/linux-links.test.js # link opening: shim binds + mime seed node test/linux-sync.test.js # linux_pfx stays out of a sync -node test/linux-e2e.js # REAL run: plain + bwrap (/etc read-only, home in prefix) +node test/linux-e2e.js # REAL runs: plain, relaxed (+ its mount), isolated, hand-off into a running app npm start # click through the flow you touched # Repairing / testing a real instance (test/ scripts are gitignored helpers): diff --git a/files/translations/en-us.json b/files/translations/en-us.json index 09be67c..9f038f7 100644 --- a/files/translations/en-us.json +++ b/files/translations/en-us.json @@ -93,10 +93,15 @@ "config.openData": "Open data folder", "config.linuxKindValue": "Linux", "config.isolation": "Isolation", - "config.isolation.auto": "Automatic (strongest available)", - "config.isolation.off": "Off (plain run)", - "config.isolation.require": "Required (refuse to run without bwrap)", - "config.isolation.bwrap": "bwrap {0} (strong)", + "config.isolation.auto": "Automatic", + "config.isolation.none": "None", + "config.isolation.relaxed": "Relaxed", + "config.isolation.isolated": "Isolated", + "config.isolationHint.auto": "Relaxed where bubblewrap works; on a machine without it the app runs without isolation.", + "config.isolationHint.none": "No sandbox: the app sees, and may change, everything your user can.", + "config.isolationHint.relaxed": "The whole disk is mounted writable as /tmp/plwl-fs-root.", + "config.isolationHint.isolated": "The system is read-only.", + "config.isolation.bwrap": "bwrap {0} (available)", "config.isolation.env": "no sandbox: {0}", "config.forceX11": "Force X11 (XWayland)", "config.forceX11Hint": "Runs the app through XWayland instead of Wayland. Useful when a window cannot carry its own icon or misbehaves on Wayland.", @@ -109,7 +114,7 @@ "config.overrides.remove": "Remove", "config.overrides.hint": "Wine module names, e.g. dinput8. native,builtin (the default) loads a DLL shipped with the game and falls back to Wine's builtin; disabled blocks the module.", "sandbox.title": "Linux app isolation", - "sandbox.hint": "Native apps always run with a redirected home folder. With bubblewrap they get their own namespaces too: only their home folder and their own app folder stay writable, the rest of the system is read-only.", + "sandbox.hint": "Native apps always run with a redirected home folder, so their config and cache stay in the prefix. The isolation level says what else they get: None is no sandbox at all, Relaxed mounts the whole disk writable, Isolated writes nothing outside the app's own folders and copies an opened file into its home folder.", "sandbox.status": "Status", "sandbox.check": "Check again", "sandbox.rechecked": "Isolation checked again", @@ -118,12 +123,15 @@ "sandbox.reason.timeout": "not responding", "sandbox.reason.failed": "not working", "sandbox.warnTitle": "No sandbox for Linux apps", - "sandbox.warnBody": "bubblewrap is {0}. Linux apps will run with only a redirected home folder - they can still read the rest of your system, and write to anything your user can.", + "sandbox.warnBody": "bubblewrap is {0}. Apps left on Automatic run as plain programs (None), while apps set to Relaxed or Isolated refuse to start instead of pretending the sandbox is there.", "sandbox.dismiss": "Got it", - "sandbox.badgeStrong": "bwrap", - "sandbox.badgeWeak": "no sandbox", - "sandbox.badgeOff": "isolation off", + "sandbox.badgeNone": "no isolation", + "sandbox.badgeRelaxed": "relaxed", + "sandbox.badgeIsolated": "isolated", "sandbox.badgeRequired": "bwrap required", + "handoff.copying": "Copying into the app: {0}", + "handoff.copyNote": "{0} / {1} - the app works on a copy inside its own home folder (plwl-handoff); edits in the copy never come back.", + "handoff.failed": "Could not copy {0} into the app: {1}", "sandbox.required": "This app needs a working bubblewrap sandbox: {0}", "sandbox.linkOpener": "PLWL link opener", "config.save": "Save changes", diff --git a/files/translations/pl.json b/files/translations/pl.json index a3a5e7d..e12374e 100644 --- a/files/translations/pl.json +++ b/files/translations/pl.json @@ -93,10 +93,15 @@ "config.openData": "Otwórz folder danych", "config.linuxKindValue": "Linux", "config.isolation": "Izolacja", - "config.isolation.auto": "Automatyczna (najmocniejsza dostępna)", - "config.isolation.off": "Wyłączona (zwykłe uruchomienie)", - "config.isolation.require": "Wymagana (odmów bez bwrap)", - "config.isolation.bwrap": "bwrap {0} (mocna)", + "config.isolation.auto": "Automatyczna", + "config.isolation.none": "None", + "config.isolation.relaxed": "Relaxed", + "config.isolation.isolated": "Isolated", + "config.isolationHint.auto": "Relaxed, gdy bubblewrap działa; na maszynie bez bwrap aplikacja uruchamia bez izolacji.", + "config.isolationHint.none": "Bez sandboxa: aplikacja widzi i może zmienić wszystko, do czego ma prawo Twój użytkownik.", + "config.isolationHint.relaxed": "Cały dysk podmontowany zapisywalnie jako /tmp/plwl-fs-root.", + "config.isolationHint.isolated": "System tylko do odczytu.", + "config.isolation.bwrap": "bwrap {0} (dostępny)", "config.isolation.env": "brak sandboxa: {0}", "config.forceX11": "Wymuś X11 (XWayland)", "config.forceX11Hint": "Uruchamia aplikację przez XWayland zamiast Waylanda. Przydatne, gdy okno nie potrafi mieć własnej ikony albo źle działa na Waylandzie.", @@ -109,7 +114,7 @@ "config.overrides.remove": "Usuń", "config.overrides.hint": "Nazwy modułów Wine, np. dinput8. native,builtin (domyślne) wczytuje DLL dołączony do gry, a gdy go nie ma — wbudowany Wine; disabled blokuje moduł.", "sandbox.title": "Izolacja aplikacji Linux", - "sandbox.hint": "Natywne aplikacje zawsze działają z przekierowanym folderem domowym. Z bubblewrap dostają dodatkowo własne przestrzenie nazw: zapisywać można tylko w swoim folderze domowym i w swoim folderze aplikacji, reszta systemu jest tylko do odczytu.", + "sandbox.hint": "Natywne aplikacje zawsze działają z przekierowanym folderem domowym - ich config i cache zostają w prefiksie. Poziom izolacji mówi, co jeszcze dostają: None to brak sandboxa, Relaxed daje cały dysk zapisywalny, a Isolated nie pozwala zapisać niczego poza folderem aplikacji i kopiuje otwierane pliki do jej folderu domowego.", "sandbox.status": "Status", "sandbox.check": "Sprawdź ponownie", "sandbox.rechecked": "Sprawdzono izolację ponownie", @@ -118,12 +123,15 @@ "sandbox.reason.timeout": "nie odpowiada", "sandbox.reason.failed": "nie działa", "sandbox.warnTitle": "Brak sandboxa dla aplikacji Linux", - "sandbox.warnBody": "bubblewrap {0}. Aplikacje linuksowe będą działać tylko z przekierowanym folderem domowym - nadal mogą czytać resztę systemu i pisać wszędzie, gdzie pozwala Twój użytkownik.", + "sandbox.warnBody": "bubblewrap {0}. Aplikacje ustawione na Automatyczną uruchomią się jak zwykłe programy (None), a te ustawione jawnie na Relaxed albo Isolated odmówią startu, zamiast udawać, że sandbox działa.", "sandbox.dismiss": "Rozumiem", - "sandbox.badgeStrong": "bwrap", - "sandbox.badgeWeak": "bez sandboxa", - "sandbox.badgeOff": "izolacja wyłączona", + "sandbox.badgeNone": "bez izolacji", + "sandbox.badgeRelaxed": "relaxed", + "sandbox.badgeIsolated": "isolated", "sandbox.badgeRequired": "wymaga bwrap", + "handoff.copying": "Kopiowanie do aplikacji: {0}", + "handoff.copyNote": "{0} / {1} - aplikacja pracuje na kopii w swoim folderze domowym (plwl-handoff); zmiany w kopii nie wracają do oryginału.", + "handoff.failed": "Nie udało się skopiować {0} do aplikacji: {1}", "sandbox.required": "Ta aplikacja wymaga działającego sandboxa bubblewrap: {0}", "sandbox.linkOpener": "PLWL - otwieranie linków", "config.save": "Zapisz zmiany", diff --git a/renderer/app.js b/renderer/app.js index 108108c..a49e8eb 100644 --- a/renderer/app.js +++ b/renderer/app.js @@ -335,11 +335,24 @@ class CustomSelect { if (this.disabled) return const wasOpen = this.host.classList.contains('open') CustomSelect.closeAll() - if (!wasOpen) this.host.classList.add('open') + if (!wasOpen) { + this.host.classList.add('open') + this.lift() + } + } + + // the transform on every element (see style.css) makes each one its own + // stacking context, so an ancestor wrapper would still paint the open list + // under the rows that follow it; positioned ancestors already stack right + lift() { + for (let el = this.host.parentElement; el && el !== document.body; el = el.parentElement) { + if (getComputedStyle(el).position === 'static') el.classList.add('select-lift') + } } close() { this.host.classList.remove('open') + CustomSelect.unlift() } setValue(v) { @@ -358,6 +371,11 @@ class CustomSelect { static closeAll() { qsa('.custom-select.open').forEach(el => el.classList.remove('open')) + CustomSelect.unlift() + } + + static unlift() { + qsa('.select-lift').forEach(el => el.classList.remove('select-lift')) } } @@ -434,12 +452,21 @@ function isolationStatusText(status) { return t('config.isolation.env', t('sandbox.reason.' + (status.reason || 'failed'))) } -function isolationBadge(game) { +// The badge names the level the app would really run at, not the policy: +// automatic is a choice, and what it resolves to depends on this machine. +function isolationLevel(game) { const policy = (game && game.isolation) || 'auto' - if (policy === 'off') return `${t('sandbox.badgeOff')}` - if (sandboxStrong()) return `${t('sandbox.badgeStrong')}` - if (policy === 'require') return `${t('sandbox.badgeRequired')}` - return `${t('sandbox.badgeWeak')}` + if (policy === 'none') return 'none' + if (policy === 'auto') return sandboxStrong() ? 'relaxed' : 'none' + return sandboxStrong() ? policy : 'unavailable' +} + +function isolationBadge(game) { + const level = isolationLevel(game) + if (level === 'none') return `${t('sandbox.badgeNone')}` + if (level === 'unavailable') return `${t('sandbox.badgeRequired')}` + if (level === 'isolated') return `${t('sandbox.badgeIsolated')}` + return `${t('sandbox.badgeRelaxed')}` } // Portable apps show files/-relative paths; external apps keep absolute ones. @@ -936,6 +963,36 @@ function wireOpenWith() { window.plwl.openwithTake().then(handleOpenWith) } +// --- isolated hand-off ------------------------------------------------------- + +// A document handed to an isolated app is copied in first. Only copies big +// enough to be noticed arrive here (main decides, and puts a window up so this +// popup can be seen at all). +function wireHandoffProgress() { + window.plwl.onHandoffProgress(data => { + if (!data || !data.notice) return + if (data.phase === 'copy') return showHandoffCopy(data) + if (data.phase !== 'done' && data.phase !== 'error') return + // only ever close our own modal: another one may have opened over it + if (qs('#modal').querySelector('#ho-progress')) closeModal() + if (data.phase === 'error') toast(t('handoff.failed', data.name, data.error || ''), 'error') + }) +} + +function showHandoffCopy(data) { + const modal = qs('#modal').querySelector('#ho-progress') + ? qs('#modal') + : showModal(` +

${t('handoff.copying', data.name)}

+
+

+ `) + renderProgressBar(modal.querySelector('#ho-progress'), data.bytes, data.totalBytes) + const pct = modal.querySelector('.progress-pct') + pct.textContent = data.totalBytes ? Math.round(((data.bytes || 0) / data.totalBytes) * 100) + '%' : '' + modal.querySelector('#ho-status').textContent = t('handoff.copyNote', formatBytes(data.bytes), formatBytes(data.totalBytes)) +} + // Import step 2: register the app in place, nothing is copied. async function doPrefixImport(prefix, srcDir) { const name = srcDir.split('/').filter(Boolean).pop() @@ -1314,14 +1371,24 @@ async function openGameConfig(id) { const isolationOptions = () => [ { value: 'auto', label: t('config.isolation.auto') }, - { value: 'off', label: t('config.isolation.off') }, - { value: 'require', label: t('config.isolation.require') } + { value: 'none', label: t('config.isolation.none') }, + { value: 'relaxed', label: t('config.isolation.relaxed') }, + { value: 'isolated', label: t('config.isolation.isolated') } ] +// The level names are one word each - what they mean has to be spelled out +// right under the select, because the price of relaxed is not visible anywhere +// else in the UI. +function renderIsolationHint(value) { + qs('#gc-isolation-hint').textContent = t(`config.isolationHint.${value || 'auto'}`) +} + function renderIsolationOptions(selected) { const opts = isolationOptions() - if (!selects['gc-isolation']) selects['gc-isolation'] = new CustomSelect(qs('#gc-isolation'), opts, selected) - else selects['gc-isolation'].update(opts, selected) + if (!selects['gc-isolation']) { + selects['gc-isolation'] = new CustomSelect(qs('#gc-isolation'), opts, selected, renderIsolationHint) + } else selects['gc-isolation'].update(opts, selected) + renderIsolationHint(selected) } async function createAppShortcut() { @@ -2096,6 +2163,7 @@ async function boot() { wireEvents() wireRealtime() wireOpenWith() + wireHandoffProgress() wireLanSync() qs('#loading').remove() qs('#main').style.display = 'flex' diff --git a/renderer/index.html b/renderer/index.html index cb4bea1..4f521cc 100644 --- a/renderer/index.html +++ b/renderer/index.html @@ -206,6 +206,7 @@