Skip to content

The swiss army knife of lossless video/audio editing

implement custom config dir arg

Mikael Finstadfedd826af04a
diff --git a/cli.md b/cli.md
index 835bb114..ced19ac4 100644
--- a/cli.md
+++ b/cli.md
@@ -37,6 +37,7 @@ LosslessCut --settings-json '{captureFormat:"jpeg", "keyframeCut":true}'
- `--disable-networking` Turn off all network requests.
- `--http-api` Start the [HTTP server with an API](./api.md) to control LosslessCut, optionally specifying a port (default `8080`).
- `--keyboard-action` Run a keyboard action (see below.)
+- `--custom-config-dir` Path to a directory where the `config.json` file will be stored and loaded from.
## Controlling a running instance (experimental)
diff --git a/src/main/configStore.ts b/src/main/configStore.ts
index babe4080..9bb44e8d 100644
--- a/src/main/configStore.ts
+++ b/src/main/configStore.ts
@@ -145,17 +145,18 @@ const defaults: Config = {
invertTimelineScroll: undefined,
};
+// look for a config.json file next to the executable
// For portable app: https://github.com/mifi/lossless-cut/issues/645
-async function getCustomStoragePath() {
+async function lookForCustomStoragePath() {
try {
- if (!isWindows || process.windowsStore) return undefined;
-
// https://github.com/mifi/lossless-cut/issues/645#issuecomment-1001363314
// https://stackoverflow.com/questions/46307797/how-to-get-the-original-path-of-a-portable-electron-app
// https://github.com/electron-userland/electron-builder/blob/master/docs/configuration/nsis.md
+ if (!isWindows || process.windowsStore) return undefined;
const customStorageDir = process.env['PORTABLE_EXECUTABLE_DIR'] || dirname(app.getPath('exe'));
const customConfigPath = join(customStorageDir, 'config.json');
if (await pathExists(customConfigPath)) return customStorageDir;
+
return undefined;
} catch (err) {
logger.error('Failed to get custom storage path', err);
@@ -196,8 +197,8 @@ async function tryCreateStore({ customStoragePath }: { customStoragePath: string
throw new Error('Timed out while creating config store');
}
-export async function init() {
- const customStoragePath = await getCustomStoragePath();
+export async function init({ customConfigDir }: { customConfigDir: string | undefined }) {
+ const customStoragePath = customConfigDir ?? await lookForCustomStoragePath();
if (customStoragePath) logger.info('customStoragePath', customStoragePath);
await tryCreateStore({ customStoragePath });
diff --git a/src/main/index.ts b/src/main/index.ts
index 0c167791..9c7038ca 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -231,7 +231,10 @@ function parseCliArgs(rawArgv = process.argv) {
// dev: First 2 args are electron and the index.js
const argsWithoutAppName = rawArgv.length > ignoreFirstArgs ? rawArgv.slice(ignoreFirstArgs) : [];
- return yargsParser(argsWithoutAppName, { boolean: ['allow-multiple-instances', 'disable-networking'], string: ['settings-json'] });
+ return yargsParser(argsWithoutAppName, {
+ boolean: ['allow-multiple-instances', 'disable-networking'],
+ string: ['settings-json', 'custom-config-dir'],
+ });
}
const argv = parseCliArgs();
@@ -330,7 +333,7 @@ const readyPromise = app.whenReady();
(async () => {
try {
logger.info('Initializing config store');
- await configStore.init();
+ await configStore.init({ customConfigDir: argv['customConfigDir'] });
const allowMultipleInstances = configStore.get('allowMultipleInstances');