From c3fab882f24e60bc3dcfb568887eb0cfcd268146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 17 Apr 2017 20:39:53 +0200 Subject: [PATCH] Add compat.js for getPref and setPref --- chrome_addon/compat.js | 44 ++++++++++++++++++++++++++++++ chrome_addon/lib/misc.js | 22 --------------- chrome_addon/manifest.json | 4 +-- firefox_webextension/compat.js | 39 ++++++++++++++++++++++++++ firefox_webextension/manifest.json | 2 +- 5 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 chrome_addon/compat.js create mode 100644 firefox_webextension/compat.js diff --git a/chrome_addon/compat.js b/chrome_addon/compat.js new file mode 100644 index 0000000..0abf3aa --- /dev/null +++ b/chrome_addon/compat.js @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013-2017 Grégory Soutadé + + This file is part of gPass. + + gPass is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + gPass is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with gPass. If not, see . +*/ + +function getPref(key) +{ + var promise = new Promise((resolve, reject) => { + chrome.storage.local.get(key, (items) => { + let err = chrome.runtime.lastError; + if (err) { + reject(err); + } else { + resolve(items); + } + }); + }) + .then(function (pref) { + if (!pref.hasOwnProperty(key)) + return default_preferences[key]; + return pref[key]; + }); + + return promise; +} + +function setPref(key, value) +{ + chrome.storage.local.set({key:value}, function ok() {}); +} diff --git a/chrome_addon/lib/misc.js b/chrome_addon/lib/misc.js index 52b563e..4d12317 100644 --- a/chrome_addon/lib/misc.js +++ b/chrome_addon/lib/misc.js @@ -175,25 +175,3 @@ async function decrypt(mkey, data) return result; } - -function getPref(key) -{ - return browser.storage.local.get(key) - .then( - function (pref) { - if (!pref.hasOwnProperty(key)) - return default_preferences[key]; - return pref[key]; - } - , - function (err) { - console.log("Error getting preference " + err); - } - ); -} - -function setPref(key, value) -{ - browser.storage.local.set({key:value}); -} - diff --git a/chrome_addon/manifest.json b/chrome_addon/manifest.json index 552444c..ed3bfae 100644 --- a/chrome_addon/manifest.json +++ b/chrome_addon/manifest.json @@ -3,7 +3,7 @@ "name": "gPass", "short_name": "gPass", - "version": "0.7", + "version": "0.8", "description": "gPass : global password manager", "icons" : {"16":"icons/gpass_icon_16.png", "32":"icons/gpass_icon_32.png", "64":"icons/gpass_icon_64.png", "128":"icons/gpass_icon_128.png"}, "author" : "Grégory Soutadé", @@ -12,7 +12,7 @@ "content_scripts": [ { "matches": ["https://*/*", "http://*/*"], - "js": ["lib/parseuri.js", "lib/misc.js", "lib/main.js"], + "js": ["lib/parseuri.js", "lib/misc.js", "compat.js", "lib/main.js"], "run_at" : "document_idle", "all_frames" : true } diff --git a/firefox_webextension/compat.js b/firefox_webextension/compat.js new file mode 100644 index 0000000..49b9a6e --- /dev/null +++ b/firefox_webextension/compat.js @@ -0,0 +1,39 @@ +/* + Copyright (C) 2013-2017 Grégory Soutadé + + This file is part of gPass. + + gPass is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + gPass is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with gPass. If not, see . +*/ + +function getPref(key) +{ + return browser.storage.local.get(key) + .then( + function (pref) { + if (!pref.hasOwnProperty(key)) + return default_preferences[key]; + return pref[key]; + } + , + function (err) { + console.log("Error getting preference " + err); + } + ); +} + +function setPref(key, value) +{ + browser.storage.local.set({key:value}); +} diff --git a/firefox_webextension/manifest.json b/firefox_webextension/manifest.json index a2eec9f..d494b7a 100644 --- a/firefox_webextension/manifest.json +++ b/firefox_webextension/manifest.json @@ -12,7 +12,7 @@ "content_scripts": [ { "matches": ["https://*/*", "http://*/*"], - "js": ["lib/parseuri.js", "lib/misc.js", "lib/main.js"], + "js": ["lib/parseuri.js", "lib/misc.js", "compat.js", "lib/main.js"], "run_at" : "document_idle", "all_frames" : true }