refactor: remove dead code (#3337)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-09 01:41:26 +02:00
1 parent a19002652b
commit 93d1f8af46
1527 files changed
+21170 -73846

No files matched your search

@@ -2,12 +2,10 @@
const {EventEmitter} = require('node:events');
const {existsSync} = require('node:fs');
const {delimiter, join, sep} = require('node:path');
const {join, sep} = require('node:path');
const {createNativeLoadError, loadNativeBinding} = require('./loader-diagnostics.cjs');
const MODULE_NAME = '@fluxer/linux-screen-capture';
const SKIP_NATIVE_PROBE_ENV = 'FLUXER_LINUX_SCREEN_CAPTURE_SKIP_NATIVE_PROBE';
const OBS_VKCAPTURE_LAYER_NAME = 'VK_LAYER_OBS_vkcapture_64';
const DEFAULT_NVIDIA_VULKAN_ICD = '/usr/share/vulkan/icd.d/nvidia_icd.json';
function resolveNativeRoot() {
const asarSegment = `${sep}app.asar${sep}`;
@@ -93,127 +91,6 @@ function listSources() {
return binding.listSources();
}
function prependPathEnv(current, next) {
if (!next) return current;
if (!current) return next;
const parts = current.split(delimiter).filter(Boolean);
return parts.includes(next) ? current : `${next}${delimiter}${current}`;
}
function appendColonEnv(current, next) {
if (!next) return current;
if (!current) return next;
const parts = current.split(':').filter(Boolean);
return parts.includes(next) ? current : `${current}:${next}`;
}
function bundledObsVkcaptureRoots(nativeRoot) {
return [join(nativeRoot, 'obs-vkcapture'), join(nativeRoot, 'game-capture', 'obs-vkcapture')];
}
function resolveBundledVulkanLayerDir(nativeRoot) {
for (const root of bundledObsVkcaptureRoots(nativeRoot)) {
const jsonPath = join(root, 'obs_vkcapture_64.json');
const layerPath = join(root, 'libVkLayer_obs_vkcapture.so');
if (existsSync(jsonPath) && existsSync(layerPath)) return root;
const vulkanRoot = join(root, 'vulkan');
const vulkanJsonPath = join(vulkanRoot, 'obs_vkcapture_64.json');
const vulkanLayerPath = join(vulkanRoot, 'libVkLayer_obs_vkcapture.so');
if (existsSync(vulkanJsonPath) && existsSync(vulkanLayerPath)) return vulkanRoot;
}
return null;
}
function resolveBundledGlCaptureLib(nativeRoot) {
for (const root of bundledObsVkcaptureRoots(nativeRoot)) {
const candidates = [
join(root, 'obs_glcapture', 'libobs_glcapture.so'),
join(root, 'opengl', 'libobs_glcapture.so'),
join(root, 'libobs_glcapture.so'),
];
for (const candidate of candidates) {
if (existsSync(candidate)) return candidate;
}
}
return null;
}
function resolveSystemVulkanLayerManifest() {
const candidates = [
'/usr/share/vulkan/implicit_layer.d/obs_vkcapture_64.json',
'/usr/local/share/vulkan/implicit_layer.d/obs_vkcapture_64.json',
];
return candidates.find((candidate) => existsSync(candidate)) ?? null;
}
function resolveSystemGlCaptureLib() {
const candidates = [
'/usr/lib/obs_glcapture/libobs_glcapture.so',
'/usr/lib64/obs_glcapture/libobs_glcapture.so',
'/usr/local/lib/obs_glcapture/libobs_glcapture.so',
'/usr/lib/x86_64-linux-gnu/obs_glcapture/libobs_glcapture.so',
'/usr/lib/aarch64-linux-gnu/obs_glcapture/libobs_glcapture.so',
];
return candidates.find((candidate) => existsSync(candidate)) ?? null;
}
function resolveNvidiaIcdPath(forceNvidiaIcd) {
if (typeof forceNvidiaIcd === 'string' && forceNvidiaIcd.length > 0) return forceNvidiaIcd;
if (forceNvidiaIcd !== true) return null;
return existsSync(DEFAULT_NVIDIA_VULKAN_ICD) ? DEFAULT_NVIDIA_VULKAN_ICD : null;
}
function addDiscreteGpuLaunchEnv(env, options = {}) {
env.DRI_PRIME = env.DRI_PRIME || '1';
env.__NV_PRIME_RENDER_OFFLOAD = '1';
env.__VK_LAYER_NV_optimus = 'NVIDIA_only';
env.__GLX_VENDOR_LIBRARY_NAME = 'nvidia';
const nvidiaIcdPath = resolveNvidiaIcdPath(options.forceNvidiaIcd);
if (nvidiaIcdPath) env.VK_ICD_FILENAMES = nvidiaIcdPath;
return nvidiaIcdPath;
}
function getGameCaptureLaunchEnvironment(options = {}) {
const baseEnv = options.env ?? process.env;
const nativeRoot = options.nativeRoot ?? resolveNativeRoot();
const mode = options.mode === 'vulkan' || options.mode === 'opengl' ? options.mode : 'auto';
const env = {...baseEnv, OBS_VKCAPTURE: '1'};
if (options.name) env.OBS_VKCAPTURE_NAME = String(options.name);
const nvidiaIcdPath = options.preferDiscreteGpu ? addDiscreteGpuLaunchEnv(env, options) : null;
const bundledVulkanLayerDir = resolveBundledVulkanLayerDir(nativeRoot);
const systemVulkanLayerManifest = resolveSystemVulkanLayerManifest();
if (mode !== 'opengl' && bundledVulkanLayerDir) {
env.VK_ADD_LAYER_PATH = prependPathEnv(env.VK_ADD_LAYER_PATH, bundledVulkanLayerDir);
env.VK_INSTANCE_LAYERS = appendColonEnv(env.VK_INSTANCE_LAYERS, OBS_VKCAPTURE_LAYER_NAME);
}
const bundledGlCaptureLib = resolveBundledGlCaptureLib(nativeRoot);
const systemGlCaptureLib = resolveSystemGlCaptureLib();
const glCaptureLib = bundledGlCaptureLib ?? systemGlCaptureLib;
if (mode !== 'vulkan' && glCaptureLib) {
env.LD_PRELOAD = appendColonEnv(env.LD_PRELOAD, glCaptureLib);
}
return {
env,
diagnostics: {
mode,
preferDiscreteGpu: options.preferDiscreteGpu === true,
forceNvidiaIcd: options.forceNvidiaIcd === true || typeof options.forceNvidiaIcd === 'string',
nvidiaIcdPath,
bundledVulkanLayerDir,
systemVulkanLayerManifest,
vulkanLayerName: bundledVulkanLayerDir ? OBS_VKCAPTURE_LAYER_NAME : null,
bundledGlCaptureLib,
systemGlCaptureLib,
glCaptureLib,
licenseBoundary:
'obs-vkcapture hook assets are separate GPL-covered runtime tools; Fluxer communicates through the OBS-compatible socket protocol.',
},
};
}
function __setBindingForTests(nextBinding) {
binding = nextBinding;
loadError = null;
@@ -342,7 +219,6 @@ module.exports = {
ScreenCapture,
getAvailability,
getBackendInfo,
getGameCaptureLaunchEnvironment,
listSources,
loadError,
__setBindingForTests,