mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 18:22:42 -08:00
refactor: add main.ts decomposition guardrails and extract core helpers
This commit is contained in:
39
src/core/utils/electron-backend.ts
Normal file
39
src/core/utils/electron-backend.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { CliArgs, shouldStartApp } from "../../cli/args";
|
||||
|
||||
function getElectronOzonePlatformHint(): string | null {
|
||||
const hint = process.env.ELECTRON_OZONE_PLATFORM_HINT?.trim().toLowerCase();
|
||||
if (hint) return hint;
|
||||
const ozone = process.env.OZONE_PLATFORM?.trim().toLowerCase();
|
||||
if (ozone) return ozone;
|
||||
return null;
|
||||
}
|
||||
|
||||
function shouldPreferWaylandBackend(): boolean {
|
||||
return Boolean(
|
||||
process.env.HYPRLAND_INSTANCE_SIGNATURE || process.env.SWAYSOCK,
|
||||
);
|
||||
}
|
||||
|
||||
export function forceX11Backend(args: CliArgs): void {
|
||||
if (process.platform !== "linux") return;
|
||||
if (!shouldStartApp(args)) return;
|
||||
if (shouldPreferWaylandBackend()) return;
|
||||
|
||||
const hint = getElectronOzonePlatformHint();
|
||||
if (hint === "x11") return;
|
||||
|
||||
process.env.ELECTRON_OZONE_PLATFORM_HINT = "x11";
|
||||
process.env.OZONE_PLATFORM = "x11";
|
||||
}
|
||||
|
||||
export function enforceUnsupportedWaylandMode(args: CliArgs): void {
|
||||
if (process.platform !== "linux") return;
|
||||
if (!shouldStartApp(args)) return;
|
||||
const hint = getElectronOzonePlatformHint();
|
||||
if (hint !== "wayland") return;
|
||||
|
||||
const message =
|
||||
"Unsupported Electron backend: Wayland. Set ELECTRON_OZONE_PLATFORM_HINT=x11 and restart SubMiner.";
|
||||
console.error(message);
|
||||
throw new Error(message);
|
||||
}
|
||||
Reference in New Issue
Block a user