The swiss army knife of lossless video/audio editing
Fix issue with relative paths and allow multiple on command line
Mikael Finstad30ba5fe041e6
diff --git a/public/electron.js b/public/electron.jsindex 0a460e03..3fe22281 100644--- a/public/electron.js+++ b/public/electron.js@@ -24,9 +24,8 @@ let mainWindow;let askBeforeClose = false;let rendererReady = false;-function openFile(path) {- mainWindow.webContents.send('file-opened', [path]);-}+const openFiles = (paths) => mainWindow.webContents.send('file-opened', paths);+const openFile = (path) => openFile([path]);function createWindow() {mainWindow = new BrowserWindow({@@ -111,16 +110,23 @@ let openFileInitial;electron.ipcMain.on('renderer-ready', () => {rendererReady = true;- if (!isDev) {- // Take the last argument, but ONLY if there is more than one argv (first one is the LosslessCut executable)- const fileToOpen = process.argv.length > 1 && process.argv[process.argv.length - 1];- // https://github.com/electron/electron/issues/3657- // https://github.com/mifi/lossless-cut/issues/357- if (fileToOpen && !fileToOpen.startsWith('-')) openFile(fileToOpen);- }- if (openFileInitial) openFile(openFileInitial);+ const ignoreFirstArgs = isDev ? 2 : 1;+ // production: First arg is the LosslessCut executable+ // dev: First 2 args are electron and the electron.js++ // https://github.com/electron/electron/issues/3657+ // https://github.com/mifi/lossless-cut/issues/357+ // https://github.com/mifi/lossless-cut/issues/639+ // https://github.com/mifi/lossless-cut/issues/591+ const filesToOpen = process.argv.length > ignoreFirstArgs+ ? process.argv.slice(ignoreFirstArgs).filter((arg) => arg && !arg.startsWith('-'))+ : [];++ if (filesToOpen.length > 0) openFiles(filesToOpen);+ else if (openFileInitial) openFile(openFileInitial);});+// Mac OS open with LosslessCutapp.on('open-file', (event, path) => {if (rendererReady) openFile(path);else openFileInitial = path;diff --git a/src/App.jsx b/src/App.jsxindex 553cdf1c..ee318cd7 100644--- a/src/App.jsx+++ b/src/App.jsx@@ -66,7 +66,7 @@ const isDev = window.require('electron-is-dev');const electron = window.require('electron'); // eslint-disable-lineconst trash = window.require('trash');const { unlink, exists } = window.require('fs-extra');-const { extname, parse: parsePath, sep: pathSep, join: pathJoin, normalize: pathNormalize } = window.require('path');+const { extname, parse: parsePath, sep: pathSep, join: pathJoin, normalize: pathNormalize, resolve: pathResolve, isAbsolute: pathIsAbsolute } = window.require('path');const { dialog, app } = electron.remote;@@ -1476,7 +1476,13 @@ const App = memo(() => {setCopyStreamIdsForPath(path, () => fromPairs(streams.map(({ index }) => [index, true])));}, [externalStreamFiles]);- const userOpenFiles = useCallback(async (filePaths) => {+ const userOpenFiles = useCallback(async (filePathsRaw) => {+ console.log('userOpenFiles');+ console.log(filePathsRaw.join('\n'));++ // Need to resolve relative paths https://github.com/mifi/lossless-cut/issues/639+ const filePaths = filePathsRaw.map((path) => (pathIsAbsolute(path) ? path : pathResolve(path)));+if (filePaths.length < 1) return;if (filePaths.length > 1) {showMergeDialog(filePaths, mergeFiles);