Fix issue with relative paths and allow multiple on command line

Fixes #639
Fixes #591
pull/640/head
Mikael Finstad 6 years ago
parent 95db959f5b
commit 30ba5fe041
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -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 LosslessCut
app.on('open-file', (event, path) => {
if (rendererReady) openFile(path);
else openFileInitial = path;

@ -66,7 +66,7 @@ const isDev = window.require('electron-is-dev');
const electron = window.require('electron'); // eslint-disable-line
const 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);

Loading…
Cancel
Save