Tested on Windows 11 / mpv.exe is in user path.
Running mpv via Electron on Windows, assuming the goal is to run MPV as a standalone so the Electron app can close without affecting mpv.
As opposed to exec, we use spawn as the method to fork the process, spawn returns a stream of io, in this example, we 'ignore' stdio.
We place in the main.js
import { ipcMain } from 'electron';
import { spawn } from 'child-process';
ipcMain.on('open-in-mpv', (_, path) => {
spawn('mpv', [path], {
shell: true,
stdio: 'ignore',
windowsHide: true,
});
});in preload.js:
const { contextBridge, ipcRenderer } = require('electron')
contextBridge.exposeInMainWorld('electronAPI', {
openInMpv: (path) => ipcRenderer.send('open-in-mpv', path)
})In the web/render side (windows as any).electronAPI.openInMpv(path: string) is the simplest call to electronAPI in TypeScript.
detaachedappears very plausible on reading the docs, however in testing on Electron app installed on WindowswindowsHideanddetacheddo not work together.detachedappears to take precident and launchesmpvvia a new terminal window.windowsHideis windows specific so developer must set up platform specific spawn options if goal is multi platform build / deploy.- tl;dr
detachedandwindowsHideare mutually exclusive. (detachedwill overridewindowsHide)
There will be updates to this gist when (if) I need a Linux or MacOS desktop app for this or similar projects spawning mpv
Should broadly apply to any .exe mpv is used here in the tests, so no claims are made to avoid assumptions.