Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store config in alternative location (portable app) #645

Closed
pstein opened this issue Feb 7, 2021 · 29 comments
Closed

Store config in alternative location (portable app) #645

pstein opened this issue Feb 7, 2021 · 29 comments

Comments

@pstein
Copy link

pstein commented Feb 7, 2021

Where are settings of LC stored?
I can't see a file like losslesscut.ini in installation folder

So it must me either in Windows Registry or in User App folder.

Unfortunately LC is not portable this way.
I would like to run it from USB flash drive on various computers and without leaving traces on the computers.

So could you make it really portable?
The preferences should be stored in an *.ini or *.xml file in Losslesscut folder.
Thank you
Peter

@markusd1984
Copy link

This would make rollouts so much better as well, to set defaults in a .ini file, please.

@mifi
Copy link
Owner

mifi commented Feb 7, 2021

It is pretty standard for apps these days to store their config inside the User folder so that many users can use the same app with diffferent configs, and you don't lose config if you delete the app (this is how it works on Linux, Mac and I believe also most Windows apps nowadays), because c:/program files should not be writeable by the user.

LosslessCut uses electron-store which uses getAppPath:

Per-user application data directory, which by default points to:
%APPDATA% on Windows
$XDG_CONFIG_HOME or ~/.config on Linux
~/Library/Application Support on macOS

We can leave this open as a feature request but I'm not going to prioritize this anytime soon, because I don't know an easy way to do this (maybe it could be done with a command line flag (-portable), but that would be a bit cumbersome for users)

@mifi mifi changed the title Where are LC settings stored? Make it portable Store config in alternative location (portable app) Feb 7, 2021
@markusd1984
Copy link

markusd1984 commented Feb 7, 2021

It makes absolutely sense why you used the popular user/platform default folders to store (user specific) app settings, we are just saying if we additionally could support using a local stored config file only when present (or take priority over present user setting), that this would make it fully portable as well as potentially easier for rollouts to multiple laptops.

I use ShareX and Greenshot which use this, they also have full installers besides fully portable versions which is nice. We are currently building an installer via app deployment tool to deploy/make available via software center (SSCM), I will check out to utilise the current setting files, biggest hurdle is the lack of uninstall support due to no installer #521/#86.)

Perhaps we could use a specific relative path via 'app.setPath(name,path)` as per https://stackoverflow.com/a/30610157/8719001 post.

(There is also a module called electron-json-storage in case that can be helpful, however a .ini file is more common to most people / editor friendly.)

@mifi
Copy link
Owner

mifi commented Feb 7, 2021

Yea could use setPath but then we would need to know when to call that instead of the default. (It cannot be a setting for obvious reasons)
A command line flag could work

@mifi
Copy link
Owner

mifi commented Feb 7, 2021

In addition, Electron internally uses the same path for storing a bunch of chrome caches and configs etc, i’m not sure if those would be affected by setAppPath too. If not then I’m pretty sure the app would crash if AppPath is not writable by the user

@markusd1984
Copy link

markusd1984 commented Feb 7, 2021

Can the path for the settings storage not be different that that used for Chrome caches and other stuff also used by electron? Unfortunately don't know anything about electron, just googling myself. 😄

If yes I imagined that we could perhaps have a logic check to see if config.ini is present in the same folder as losslesscut.exe and if so use that for settings instead of user data directory, (otherwise fault back on default using user data directory).

@mifi
Copy link
Owner

mifi commented Feb 8, 2021

If settings are still stored in User/AppData, then it would break the promise of not leaving traces on the computer.
If checking for config.ini and the file does not exist because the user forgot to create the file, then it would also leave traces on the computer

@pstein
Copy link
Author

pstein commented Feb 8, 2021

LC could check if a subfolder "settings" exist in the LC installation folder. If this subfolder exists then LC uses the files inside this folder otherwise LC looks in the default User/AppData directory.

I don't know in which programming language LC is written. So in pseudo code it would look like:

If exists(getLCInstallationfolder()\settings) {
    settingsfolder=getLCInstallationfolder()\settings; }
else {
    settingsfolder=getAppDatafolder()\Roaming\Losslesscut; }

So making LC portable costs only 3 tiny lines of source code more.

Is this too difficult?

@markusd1984
Copy link

markusd1984 commented Feb 8, 2021

Shouldn't require a folder just a file in the same folder where the exe is to keep it simple.

Yes if electron still requires user/App Data folder that may not be fully portable or without trace, but this is happening currently regardless thus the main benefit is being able to deploy or use it portable including preconfigured settings . That's why we need it and should implement it.

Potentially it could be also a setting to enable local settings which creates the config.ini file and when present use that to populate all default settings and update with any changes made in the app, that would also make it user-friendly for changing settings as one just does the changes in the app and can copy or backup the config file. (and we can have a remark that some settings or data needs to be stored in User/AppData). 😄

Portable app settings is more practical while potentially avoiding or removing temporary data would be a nice to have in comparison in my option (but maybe this can be figure out as well).

@mifi
Copy link
Owner

mifi commented Feb 16, 2021

I'm not going to spend too much time on this, but I will add a check for whether a config file exists in the app dir getAppPath

@mattack1
Copy link

mattack1 commented Feb 16, 2021

I know nothing about electron-store, but IMO it should be putting things in preferences files, not
~/Library/Application Support on macOS

though I guess if you have a whole bunch of different unrelated files, that's ok.. but I think of configuration info as largely the same as user preferences for an app.

i.e. it should be in a plist file in ~/Library/Preferences/ (on the Mac obviously)

@mifi
Copy link
Owner

mifi commented Feb 16, 2021

I will only make the "portable" change for Windows. MacOs/Linux will always be using electron app.getPath('appData') (https://www.electronjs.org/docs/api/app#appgetpathname)
I believe most MacOs apps store configuration inside ~/Library/Application Support, see for instance Chrome ~/Library/Application\ Support/Google/Chrome/Default.
What's the benefit of storing under ~/Library/Preferences ?

@mifi mifi closed this as completed in 04a6d5c Feb 16, 2021
@mifi
Copy link
Owner

mifi commented Feb 16, 2021

will be out in the next ver

@seiferflo
Copy link

seiferflo commented Mar 4, 2021

will be out in the next ver

Thanks, but how do we set it to portable mode on Windows since the 3.33.1 ?
Data still appears in %APPDATA%\Roaming and I would like this folder to be inside the app root folder

@mifi
Copy link
Owner

mifi commented Mar 5, 2021

Put an config.json file containing {} next to the exe and it should use that. It will still create electron stuff inside appdata/roaming, unfortunately i dont know if it’s possible to fix that

@tobwz
Copy link

tobwz commented Mar 5, 2021

How should users this know?

Wouldn't it be easier if you create a clickable checkbox/button/menu in GUI with the label "Run in portable mode" which prepare everything necessary?

@mifi
Copy link
Owner

mifi commented Mar 5, 2021

either that or a command line flag to start it in portable mode can be done. I just don't think a lot of people need that, and if they do, then they can now still achieve it by creating this config file.

@seiferflo
Copy link

seiferflo commented Mar 5, 2021

Thx for your feedback @mifi . I disagree in a sense that they are much more users than you think who prefer to have an app running in portable mode, simply to avoid leaving any trace or any leftovers in case they don't use it anymore.
Keeping the app and its settings at the same place to be used simply on another computer is also important nowadays as people are very mobile.
So giving the choice to people of installing it or using it in portable mode as @tobwz mentioned is a good idea.

A neat way would to have an App & Data folder and a shortcut on the root level.
App contains what you have today with the exe.
Data contains what you create in the %APPDATA%\Roaming

Whether this is a achieved through a json file or portable command line flag is ok, as long as it's described somewhere.
Speaking of which, creating a config.json containing what you mentioned doesn't seem to be doing anything in my case...

Thx for your consideration

@mifi
Copy link
Owner

mifi commented Mar 5, 2021

Thx for your feedback @mifi . I disagree in a sense that they are much more users than you think who prefer to have an app running in portable mode, simply to avoid leaving any trace or any leftovers in case they don't use it anymore.

The problem is that it is not that simple because lc is using a framework called electron which has some ways of doing things, like storing appdata.
I found this app.setPath(name, path) however I think that would only work if we had a a command line flag (because it needs to run immediately upon startup, before app->ready event, I believe in the first tick) so we cannot run async code. (to check for an existing file)

Speaking of which, creating a config.json containing what you mentioned doesn't seem to be doing anything in my case...

Are you running single EXE version? can you check developer tools if it logs customStoragePath somewhere there? or try to run the exe from the command line and see if it spits out the path there

@seiferflo
Copy link

Sorry I'm not understanding your first answer as I'm not a developer.

For the exe, I'm using your zip version and there is only one LosslessCut.exe file in the root folder, where I put the config.json file there.

I've opened the developer tools and didn't find the customStoragePath log anywhere.

Launching the exe from cmd,gives me "(electron) The default value of app.allowRendererProcessReuse is deprecated, it is currently "false". It will change to be "true" in Electron 9."

@mifi
Copy link
Owner

mifi commented Mar 6, 2021

sorry those were just some notes for myself (and any other devs). In layman terms I believe it's not possible to have it store the other files (Electron app data) in the same dir as the exe file after detecting a config.json next to the exe because it is too late (electron has already stored the files in Roaming by then). if we want to store those files also next to exe, I think we need to run losslesscut with a command line flag that says to use exe dir for storage of those. but then the user would have to start lc with a command line flag every time, i'm not sure how nice that is.

@mifi
Copy link
Owner

mifi commented Mar 6, 2021

As for why config.json doesn't work, I have to look into that. I only tested on mac and here it worked, so i need to fire up a windows vm to test

@ghost
Copy link

ghost commented Dec 23, 2021

Has there been any progress on the feature? I have noticed that placing config.json containing {} next to the exe doesn't do anything.

@mifi
Copy link
Owner

mifi commented Dec 27, 2021

Are you running the self-contained LosslessCut-win.exe from github, e.g. this one? https://github.com/mifi/lossless-cut/releases/download/v3.39.0/LosslessCut-win.exe

I think that version is a self-extracting exe archive, and will extract all files into a temp directory like maybe c:/Temp, before running the extracted exe file from the temp file. I have a suspicion that getAppPath will return this temp folder instead.
What you could try is instead download the zip file, extract that to a directory and then make a config.json file inside there, if that fixes the problem, then I'm pretty sure that this is the issue. https://github.com/mifi/lossless-cut/releases/download/v3.39.0/LosslessCut-win.zip

Meanwhile I found this and will look into it:
https://stackoverflow.com/questions/46307797/how-to-get-the-original-path-of-a-portable-electron-app

@mifi mifi reopened this Dec 27, 2021
mifi added a commit that referenced this issue Dec 27, 2021
@ghost
Copy link

ghost commented Dec 28, 2021

I've been using the zip version from the very beginning.

@mifi
Copy link
Owner

mifi commented Jan 1, 2022

Ok it seems there was a bug, where I used getAppPath(), but that points to asar instead. In the enxt version will instead use getPath('exe'), hopefully that fixed the problemn.

@JohnTHaller
Copy link

For folks who would like the Electron data in AppData handled as well, we've released Lossless Cut Portable at PortableApps.com. It uses the config.json method mentioned above as well as moving files to/from %APPDATA%\LosslessCut. It also adjusts paths within config.json as you move between computers.

@mifi
Copy link
Owner

mifi commented Feb 2, 2022

@JohnTHaller that's great! BTW you can all try the latest version from github, hopefully the config issue is solved

@mifi
Copy link
Owner

mifi commented Feb 19, 2022

Closing for now. I'll reopen if still an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants