Simpl-storage problem


(Niklas Gollenstede) #21

So now I did the whole thing. This works:

C:\dev\storage-test\package.json:

{
	"name": "storage-test",
	"title": "Storage Test",
	"version": "0.0.1",
	"main": "main.js"
}

C:\dev\storage-test\main.js:

const { storage, } = require("sdk/simple-storage");
let userId = storage.userId, written = false; // read the id
if (!userId) { // write it if not set, should only happen once (or after it was deleted)
	userId = storage.userId = Math.random().toString(32).slice(2);
	written = true;
}

console.log(written ? 'Wrote' : 'Read', 'userId', userId);

C:\dev\storage-test\start.bat:

mkdir ..\sdk-profile
echo pref("xpinstall.signatures.required", false); >> ..\sdk-profile\prefs.js
echo pref("extensions.@storage-test.sdk.console.logLevel", "all"); >> ..\sdk-profile\prefs.js
jpm run -b "C:\Program Files\Firefox Developer Edition\firefox.exe" --no-copy --profile ..\sdk-profile

You may have to use Program Files (x86) in the last line.

Then double-click the start.bat and observe the last line in the console output once the browser is fully started. The first time and every time you deleted C:\dev\sdk-profile, it will say Wrote userId <<random>>, and afterwords Read userId <<same_id>>.