1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-24 03:12:41 +01:00

allow revealing config file path

This commit is contained in:
Mikael Finstad 2024-09-26 11:55:44 +02:00
parent fd27f2178e
commit a5000a8977
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
2 changed files with 16 additions and 5 deletions

View File

@ -148,17 +148,19 @@ const defaults: Config = {
invertTimelineScroll: undefined,
};
const configFileName = 'config.json'; // note: this is also hard-coded inside electron-store
// look for a config.json file next to the executable
// For portable app: https://github.com/mifi/lossless-cut/issues/645
async function lookForCustomStoragePath() {
async function lookForNeighbourConfigFile() {
try {
// 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;
const appExeDir = process.env['PORTABLE_EXECUTABLE_DIR'] || dirname(app.getPath('exe'));
const customConfigPath = join(appExeDir, configFileName);
if (await pathExists(customConfigPath)) return appExeDir;
return undefined;
} catch (err) {
@ -200,8 +202,12 @@ async function tryCreateStore({ customStoragePath }: { customStoragePath: string
throw new Error('Timed out while creating config store');
}
let customStoragePath: string | undefined;
export const getConfigPath = () => customStoragePath ?? join(app.getPath('userData'), configFileName); // custom path, or default used by electron-store
export async function init({ customConfigDir }: { customConfigDir: string | undefined }) {
const customStoragePath = customConfigDir ?? await lookForCustomStoragePath();
customStoragePath = customConfigDir ?? await lookForNeighbourConfigFile();
if (customStoragePath) logger.info('customStoragePath', customStoragePath);
await tryCreateStore({ customStoragePath });

View File

@ -4,6 +4,7 @@ import { t } from 'i18next';
import { homepage, getReleaseUrl, licensesPage } from './constants.js';
import { logFilePath } from './logger.js';
import { getConfigPath } from './configStore.js';
// menu-safe i18n.t:
@ -448,6 +449,10 @@ export default ({ app, mainWindow, newVersion, isStoreBuild }: {
click() { electron.shell.openExternal('https://github.com/mifi/lossless-cut/issues'); },
},
{ type: 'separator' },
{
label: esc(t('Configuration file')),
click() { electron.shell.showItemInFolder(getConfigPath()); },
},
{
label: esc(t('Log file')),
click() { electron.shell.openPath(logFilePath); },