Skip to content

Commit 2bf0eab

Browse files
committed
feat(electron): detect Snap/AppImage and adjust sandboxing
Detect Snap and AppImage environments at startup and adjust the renderer sandbox and GPU sandbox accordingly. Add env checks in main.ts and app.ts to determine if process.env.SNAP or process.env.APPIMAGE is set. When running inside Snap or AppImage, append the disable-gpu-sandbox command line switch and disable the renderer sandbox for BrowserWindow by setting sandbox: false. This prevents conflicts between Electron's sandboxing/GPU sandbox and confinement used by Snap/AppImage packages, improving stability for packaged Linux builds.
1 parent 54c61df commit 2bf0eab

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

apps/electron-backend/src/app/app.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export default class App {
6565

6666
const savedWindowBounds = store.get(WINDOW_BOUNDS);
6767

68+
// Detect if running in Snap or AppImage environment
69+
const isSnap = process.env.SNAP !== undefined;
70+
const isAppImage = process.env.APPIMAGE !== undefined;
71+
6872
// Create the browser window.
6973
App.mainWindow = new BrowserWindow({
7074
title: 'IPTVnator',
@@ -75,6 +79,9 @@ export default class App {
7579
contextIsolation: true,
7680
backgroundThrottling: false,
7781
preload: join(__dirname, 'main.preload.js'),
82+
// Enable sandbox by default, it will be automatically adjusted
83+
// based on command line switches set in main.ts
84+
sandbox: !(isSnap || isAppImage),
7885
},
7986
...savedWindowBounds,
8087
minHeight: 600,

apps/electron-backend/src/main.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ import SquirrelEvents from './app/events/squirrel.events';
1414
import StalkerEvents from './app/events/stalker.events';
1515
import XtreamEvents from './app/events/xtream.events';
1616

17+
// Detect if running in Snap or AppImage environment
18+
const isSnap = process.env.SNAP !== undefined;
19+
const isAppImage = process.env.APPIMAGE !== undefined;
20+
21+
// Handle sandbox for Snap and AppImage
22+
if (isSnap || isAppImage) {
23+
// Disable GPU sandbox which often conflicts with snap/AppImage confinement
24+
app.commandLine.appendSwitch('disable-gpu-sandbox');
25+
}
26+
1727
app.setName('iptvnator');
1828

1929
export default class Main {

0 commit comments

Comments
 (0)