From 17a58bc196f8becff85d10bf0479d2dfd32ed4c6 Mon Sep 17 00:00:00 2001 From: Andy McKay Date: Tue, 24 Oct 2017 16:34:28 -0700 Subject: [PATCH] add in managed example (#287) * add in managed example * Updated favourite-colour README to point to the storage.managed documentation --- favourite-colour/README.md | 24 ++++++++++++++++++++---- favourite-colour/manifest.json | 3 ++- favourite-colour/options.html | 1 + favourite-colour/options.js | 5 +++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/favourite-colour/README.md b/favourite-colour/README.md index 4cbfa5b..820fc08 100644 --- a/favourite-colour/README.md +++ b/favourite-colour/README.md @@ -1,7 +1,23 @@ # Favourite Colour -Shows and stores your favourite colour, in storage.local -in the about:addons page for the add-on. +Shows and stores your favourite colour, in storage.sync in the about:addons page for the add-on. -Demonstrates: storing data with storage.local, runtime.openOptionsPage and -creating an options page. +Demonstrates: + +* storing data with storage.sync + +* reading data from storage.managed, +* creating an options page and opening it with `runtime.openOptionsPage()`. + +To have Firefox read data from storage.managed, create a file with the following contents: + + { + "name": "favourite-colour-examples@mozilla.org", + "description": "ignored", + "type": "storage", + "data": { + "colour": "management thinks it should be blue!" + } + } + +Name the file `"favourite-colour-examples@mozilla.org.json"` and follow the instructions in the [`storage.managed` documentation](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/managed) to make the file discoverable by the extension (on OS X and Linux this means copying it to a specific location, while on Windows it means creating a specific registry key pointing to the file's location). diff --git a/favourite-colour/manifest.json b/favourite-colour/manifest.json index 560c795..8fe422e 100644 --- a/favourite-colour/manifest.json +++ b/favourite-colour/manifest.json @@ -17,7 +17,8 @@ "version": "1.1", "applications": { "gecko": { - "id": "favourite-colour-examples@mozilla.org" + "id": "favourite-colour-examples@mozilla.org", + "strict_min_version": "57.0a1" } } } diff --git a/favourite-colour/options.html b/favourite-colour/options.html index 77c925e..fbeedcd 100644 --- a/favourite-colour/options.html +++ b/favourite-colour/options.html @@ -6,6 +6,7 @@ +

storage.managed colour: no value found

diff --git a/favourite-colour/options.js b/favourite-colour/options.js index 5c23b75..9157e9d 100644 --- a/favourite-colour/options.js +++ b/favourite-colour/options.js @@ -6,6 +6,11 @@ function saveOptions(e) { } function restoreOptions() { + var storageItem = browser.storage.managed.get('colour'); + storageItem.then((res) => { + document.querySelector("#managed-colour").innerText = res.colour; + }); + var gettingItem = browser.storage.sync.get('colour'); gettingItem.then((res) => { document.querySelector("#colour").value = res.colour || 'Firefox red';