Load configuration from a JSON file?
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.
This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.
Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.
This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.
Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
-
- Knows the dark side
- Posts: 4983
- Joined: 2015-12-09, 15:45
Load configuration from a JSON file?
I want to store some configuration in a JSON file within my extension for easier maintenance later, that's too large for the usual preferences. Is there a way to directly load them as chrome:// resources, the way one can with .jsm files or do I have to go through the whole nsiFile API?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Re: Load configuration from a JSON file?
In general, for reading data from chrome resources, I usually prefer using XMLHttpRequest, but in your case I would consider just using jsm instead of json.
-
- Knows the dark side
- Posts: 4983
- Joined: 2015-12-09, 15:45
Re: Load configuration from a JSON file?
So can I create a .jsm file with just JSON syntax in it, as in an object?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Re: Load configuration from a JSON file?
No, you still need to wrap the json in a standard jsm file, but I think it will be just as easy to maintain as plain json.
-
- Knows the dark side
- Posts: 4983
- Joined: 2015-12-09, 15:45
Re: Load configuration from a JSON file?
I tried the first approach with XMLHttpRequest and got a network error trying to load a chrome URL. Let me try the .jsm then.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
-
- Knows the dark side
- Posts: 4983
- Joined: 2015-12-09, 15:45
Re: Load configuration from a JSON file?
Maybe because I was doing it in a .jsm and not the main window. Anyhow, I've gone with using a .jsm only, less complicated.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
Re: Load configuration from a JSON file?
Wouldn't it be a bit tricky to store changes to the configuration if it was in a module?
-
- Moon Magic practitioner
- Posts: 2194
- Joined: 2018-05-05, 13:29
Re: Load configuration from a JSON file?
Doesn't seem like the JSON has to be edited.thosrtanner wrote: ↑2020-08-01, 17:19Wouldn't it be a bit tricky to store changes to the configuration if it was in a module?
In fact at first I was about to reply with a different solution, but then rereading the OP it sounds like the configuration is actually just a one-off initialization.
-
- Knows the dark side
- Posts: 4983
- Joined: 2015-12-09, 15:45
Re: Load configuration from a JSON file?
Ok, my use case is where I want to provide a template of links that can be configured by the end user. For eg, PMPlayer currently supports a few websites using regex to detect the URL and video embeds, but these are hardcoded so it only supports the popular ones (Youtube, Dailymotion, Vimeo etc). If I can store the configuration for each site (URL detection regex, video embed template and name), and provide a UI for the user to edit or add their own, they can use it with any other site as well. I could store it in a preference string, but I thought a separate JSON would be easier to maintain.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
-
- Lunatic
- Posts: 395
- Joined: 2014-05-10, 18:19
- Location: UK
Re: Load configuration from a JSON file?
So that looks like you want to make changes to it. I think nsiFile is going to be where you need to go.
You can still read/write the configuration as a single JSON string though, with JSON.parse and JSON.stringify
You can still read/write the configuration as a single JSON string though, with JSON.parse and JSON.stringify
-
- Knows the dark side
- Posts: 4983
- Joined: 2015-12-09, 15:45
Re: Load configuration from a JSON file?
Yeah, I've used JSON before, just wasn't clear how I'd load the string before passing it to JSON.parse.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Re: Load configuration from a JSON file?
Put the json in a location that is mapped to a resource uri not chrome uri.. Might have better luck.
-
- Knows the dark side
- Posts: 4983
- Joined: 2015-12-09, 15:45
Re: Load configuration from a JSON file?
Thanks, I'll try that.
"One hosts to look them up, one DNS to find them and in the darkness BIND them."
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX