2

I would like, from the Electron index.html file, to modify a config file present in the.asar of my application. In my case I need to change, if necessary, my application database config in order to work.

I understood that .asar is in readOnly and I wanted to know if there is a way to modify this config file from electron without changing its position in my application?

I see the extraResources option but I did not understand how its work.

It's also important that the config file stay in myapp/config folder.

Thanks for your help :)

Syno
  • 21
  • 1
  • 5

5 Answers5

2

What build tool do you use? If you are using electron builder, you can check out asarUnpack in configuration file here or extraFiles here

Hai Pham
  • 2,188
  • 11
  • 20
  • For asking question please leave comment behind the question. – Arash Jun 12 '18 at 06:57
  • Yes I am using electron builder, I think asarUnpack is a good idea but apparently in my case I just need to access to my all app folder. So I tried to set asar to false but the app folder is still in read only and I can't modify anything in it. Is there a way to get my app folder like in dev mode in the build ? – Syno Jun 12 '18 at 09:16
  • Did you try to put your config file in `MyApp` instead of `MyApp/resources/app` folder? You can put these line to your `package.json`: `"extraFiles": [{ "from": PATH_TO_CONFIG, "to": "." }]` to try it. – Hai Pham Jun 13 '18 at 01:57
1

I was able to edit the read-only file by first changing the file permissions programmatically and then editing it.

fs.chmod(filename, 0666, (error) => {
        console.log('Changed file permissions');
    });

   ...
    code to modify file
   ...
vaasu varma
  • 85
  • 1
  • 7
0

asar is in readonly

as you mentioned asar intended to be readonly package. For runtime-changing config, you should place it outside of asar and change values accordingly.

OJ Kwon
  • 4,385
  • 1
  • 20
  • 24
  • Sadly I can't modify the structure of my application and so I can't move my config file from it. Even with the option asar: false the folder is still in read only, do you know how can I access to my application folder without restriction ? – Syno Jun 12 '18 at 09:19
0

To manage settings you should use a node package that's specifically designed for this, like electron-settings or preferences.

As an alternative one may manually read an write config files that you place in the platform's native config directory.


Mutable application settings shouldn't be stored in the asar file. If it's required to replace a file in an asar archive for any other reason, use the the asar program to extract the entire archive to a temporary directory, replace the file(s) you want, then create a new asar file, replacing the original asar file.

Artur Kovacs
  • 141
  • 5
0
  • To unpack .asar files -> asar extract electron.asar app

  • modify as per your needs

  • To pack .asar files -> asar pack . electron.asar

Ahmed Maher
  • 1,521
  • 17
  • 22