Skip to content

Split any YouTube song into stems

TypeScript

linux: decide no-sandbox in a pre-exec launcher instead of app code

Daniel Ravina3858dd5ebbb7
diff --git a/electron-builder.yml b/electron-builder.yml
index 881ca0c..65ef503 100644
--- a/electron-builder.yml
+++ b/electron-builder.yml
@@ -1,5 +1,6 @@
appId: com.stemkit.app
productName: StemKit
+afterPack: scripts/after-pack.cjs
directories:
output: release
files:
diff --git a/scripts/after-pack.cjs b/scripts/after-pack.cjs
new file mode 100644
index 0000000..2c8489f
--- /dev/null
+++ b/scripts/after-pack.cjs
@@ -0,0 +1,45 @@
+const { chmodSync, renameSync, writeFileSync, existsSync } = require('fs')
+const { join } = require('path')
+
+/* Chromium boots its zygote before any app JS runs, so `no-sandbox` must be
+ decided before the executable starts (Electron reads it from argv or from
+ the ELECTRON_DISABLE_SANDBOX env var in BasicStartupComplete, see
+ shell/app/electron_main_delegate.cc). AppRun execs the packed executable
+ directly with no hook of its own, so on Linux we swap it for a launcher
+ that makes that decision for Electron: keep the sandbox when the kernel
+ can still provide one (unprivileged user namespaces, or a properly
+ installed root-owned SUID chrome-sandbox — e.g. the deb target), and set
+ ELECTRON_DISABLE_SANDBOX otherwise (e.g. the AppImage target on Ubuntu
+ 24.04+, where AppArmor blocks unprivileged user namespaces and the
+ read-only FUSE mount can never satisfy the SUID check — issue #15). */
+
+function launcherScript(bin) {
+ return `#!/bin/bash
+DIR="$(cd "$(dirname "$0")" && pwd)"
+BIN="$DIR/${bin}.bin"
+
+if (command -v unshare >/dev/null 2>&1 && unshare -Ur true 2>/dev/null) \\
+ || { sb="$DIR/chrome-sandbox"; [ -e "$sb" ] \\
+ && [ "$(stat -c '%u %a' "$sb" 2>/dev/null)" = "0 4755" ]; }; then
+ exec "$BIN" "$@"
+fi
+
+export ELECTRON_DISABLE_SANDBOX=1
+exec "$BIN" "$@"
+`
+}
+
+exports.default = async function afterPack(context) {
+ if (context.electronPlatformName !== 'linux') return
+
+ const dir = context.appOutDir
+ const bin = context.packager.executableName
+
+ // deb/rpm installs unpack as root, so the SUID sandbox works — make sure
+ // the helper carries the bit no matter how the electron zip was unpacked
+ const chromeSandbox = join(dir, 'chrome-sandbox')
+ if (existsSync(chromeSandbox)) chmodSync(chromeSandbox, 0o4755)
+
+ renameSync(join(dir, bin), join(dir, `${bin}.bin`))
+ writeFileSync(join(dir, bin), launcherScript(bin), { mode: 0o755 })
+}
\ No newline at end of file
diff --git a/src/main/index.ts b/src/main/index.ts
index 7c73ee3..be26902 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -20,8 +20,8 @@ import {
getStatus
} from './env'
import { loadSettings, saveSettings } from './settings'
-import { loadSongs, removeSong, stemBuffers, stemsDir, stemsFor, mixWavPath } from './library'
-import { startJob, cancelJob, searchYouTube } from './pipeline'
+import { loadSongs, removeSong, stemBuffers, stemsDir, stemsFor, mixWavPath, AUDIO_EXTENSIONS } from './library'
+import { startJob, startLocalJob, cancelJob, searchYouTube } from './pipeline'
import { initUpdater } from './updater'
import { runSmoke } from './smoke'
import { getThumb, clearThumbMemo } from './thumbs'
@@ -30,14 +30,6 @@ import { maybePing } from './telemetry'
let mainWindow: BrowserWindow | null = null
let staticServer: Server | null = null
-// Ubuntu 24.04+ blocks unprivileged user namespaces, so Chromium falls back to
-// the SUID sandbox, which can never pass its root-ownership check inside a
-// read-only AppImage FUSE mount (issue #15). Only AppImage runs are affected —
-// deb installs install chrome-sandbox root-owned 4755 and keep the real sandbox.
-if (process.platform === 'linux' && process.env.APPIMAGE) {
- app.commandLine.appendSwitch('no-sandbox')
-}
-
const MIME: Record<string, string> = {
'.html': 'text/html',
'.js': 'text/javascript',
@@ -178,6 +170,20 @@ app.whenReady().then(async () => {
void startJob(url, model, stems)
return { started: true }
})
+ ipcMain.handle('jobs:start-local', async (_e, filePath: string, model?: string, stems?: string[]) => {
+ void startLocalJob(filePath, model, stems)
+ return { started: true }
+ })
+ ipcMain.handle('files:pick-audio', async () => {
+ const result = await dialog.showOpenDialog({
+ title: 'Choose an audio file to split',
+ buttonLabel: 'Split',
+ properties: ['openFile'],
+ filters: [{ name: 'Audio files', extensions: AUDIO_EXTENSIONS }]
+ })
+ if (result.canceled || !result.filePaths[0]) return null
+ return result.filePaths[0]
+ })
ipcMain.handle('jobs:cancel', (_e, videoId?: string) => cancelJob(videoId))
ipcMain.handle('stem:export', async (_e, videoId: string, stem: string) => {