allow overriding any stored setting from the command line #371

pull/982/head
Mikael Finstad 4 years ago
parent 6b29ee1e97
commit 802a701430
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26

@ -179,6 +179,19 @@ If you have an issue you can check the developer tools for any errors or clues.
1234,,Last segment
```
## Command line interface (CLI)
### Open one or more files:
```bash
LosslessCut file1.mp4 file2.mkv
```
### Override settings (experimental)
See [available settings](https://github.com/mifi/lossless-cut/blob/master/public/configStore.js). Note that this is subject to change in newer versions. ⚠️ If you specify incorrect values it could corrupt your configuration file. You may use JSON or JSON5:
```bash
LosslessCut --settings-json '{captureFormat:"jpeg", "keyframeCut":true}'
```
## Developing
See the [developer notes](developer-notes.md).

@ -115,7 +115,8 @@
"semver": "^7.1.3",
"string-to-stream": "^1.1.1",
"strtok3": "^6.0.0",
"trash": "^7.1.1"
"trash": "^7.1.1",
"yargs-parser": "^21.0.0"
},
"eslintConfig": {
"extends": "react-app"

@ -3,6 +3,9 @@ const isDev = require('electron-is-dev');
const unhandled = require('electron-unhandled');
const i18n = require('i18next');
const debounce = require('lodash/debounce');
const yargsParser = require('yargs-parser');
const JSON5 = require('json5');
const menu = require('./menu');
const configStore = require('./configStore');
@ -23,6 +26,10 @@ unhandled({
app.name = 'LosslessCut';
let filesToOpen;
let openFileInitial;
let fileOpened = false;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow;
@ -116,6 +123,20 @@ function updateMenu() {
menu(app, mainWindow, newVersion);
}
// 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
function parseCliArgs() {
const ignoreFirstArgs = isDev ? 2 : 1;
// production: First arg is the LosslessCut executable
// dev: First 2 args are electron and the electron.js
const argsWithoutAppName = process.argv.length > ignoreFirstArgs ? process.argv.slice(ignoreFirstArgs) : [];
return yargsParser(argsWithoutAppName);
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
@ -132,6 +153,18 @@ app.on('ready', async () => {
await configStore.init();
const argv = parseCliArgs();
console.log('CLI arguments', argv);
filesToOpen = argv._;
const { settingsJson } = argv;
if (settingsJson != null) {
console.log('initializing settings', settingsJson);
Object.entries(JSON5.parse(settingsJson)).forEach(([key, value]) => {
configStore.set(key, value);
});
}
if (isDev) {
const { default: installExtension, REACT_DEVELOPER_TOOLS } = require('electron-devtools-installer'); // eslint-disable-line global-require,import/no-extraneous-dependencies
@ -163,9 +196,6 @@ app.on('activate', () => {
}
});
let openFileInitial;
let fileOpened = false;
function openFilesOnce(files) {
if (fileOpened) return;
fileOpened = true;
@ -174,17 +204,6 @@ function openFilesOnce(files) {
electron.ipcMain.on('renderer-ready', () => {
rendererReady = true;
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) openFilesOnce(filesToOpen);
else if (openFileInitial) openFilesOnce([openFileInitial]);

Loading…
Cancel
Save