Add store ID for default store (#17)

This commit is contained in:
Maxim Baz
2018-04-23 11:24:37 +02:00
committed by GitHub
parent fa3f194ac4
commit a6fe89a231
2 changed files with 20 additions and 22 deletions

View File

@@ -304,7 +304,7 @@ function hostAction(settings, action, params = {}) {
*/
async function parseFields(settings, login) {
var response = await hostAction(settings, "fetch", {
store: login.store.name,
storeId: login.store.id,
file: login.login + ".gpg"
});
if (response.status != "ok") {
@@ -381,13 +381,13 @@ async function receiveMessage(message, sender, sendResponse) {
settings.version = response.version;
if (settings.stores.length) {
// there are user-configured stores present
for (var key in settings.stores) {
if (response.data.storeSettings.hasOwnProperty(key)) {
var fileSettings = JSON.parse(response.data.storeSettings[key]);
if (typeof settings.stores[key].settings !== "object") {
settings.stores[key].settings = {};
for (var storeId in settings.stores) {
if (response.data.storeSettings.hasOwnProperty(storeId)) {
var fileSettings = JSON.parse(response.data.storeSettings[storeId]);
if (typeof settings.stores[storeId].settings !== "object") {
settings.stores[storeId].settings = {};
}
var storeSettings = settings.stores[key].settings;
var storeSettings = settings.stores[storeId].settings;
for (var settingKey in fileSettings) {
if (!storeSettings.hasOwnProperty(settingKey)) {
storeSettings[settingKey] = fileSettings[settingKey];
@@ -398,6 +398,7 @@ async function receiveMessage(message, sender, sendResponse) {
} else {
// no user-configured stores, so use the default store
settings.stores.default = {
id: "default",
name: "default",
path: response.data.defaultStore.path,
settings: response.data.defaultStore.settings

View File

@@ -16,12 +16,12 @@ chrome.tabs.query({ active: true, currentWindow: true }, async function(tabs) {
var settings = response.settings;
settings.tab = tabs[0];
settings.host = new URL(settings.tab.url).hostname;
for (var store in settings.stores) {
var when = localStorage.getItem("recent:" + settings.stores[store].path);
for (var storeId in settings.stores) {
var when = localStorage.getItem("recent:" + storeId);
if (when) {
settings.stores[store].when = JSON.parse(when);
settings.stores[storeId].when = JSON.parse(when);
} else {
settings.stores[store].when = 0;
settings.stores[storeId].when = 0;
}
}
settings.recent = localStorage.getItem("recent");
@@ -102,22 +102,20 @@ async function run(settings) {
if (recent) {
recent = JSON.parse(recent);
}
for (var store in response.files) {
for (var key in response.files[store]) {
for (var storeId in response.files) {
for (var key in response.files[storeId]) {
// set login fields
var login = {
index: index++,
store: settings.stores[store],
login: response.files[store][key].replace(/\.gpg$/i, ""),
store: settings.stores[storeId],
login: response.files[storeId][key].replace(/\.gpg$/i, ""),
allowFill: true
};
login.domain = pathToDomain(store + "/" + login.login);
login.domain = pathToDomain(storeId + "/" + login.login);
login.inCurrentDomain =
settings.host == login.domain || settings.host.endsWith("." + login.domain);
login.recent =
settings.recent[
sha1(settings.host + sha1(login.store.path + sha1(login.login)))
];
settings.recent[sha1(settings.host + sha1(login.store.id + sha1(login.login)))];
if (!login.recent) {
login.recent = {
when: 0,
@@ -151,15 +149,14 @@ function saveRecent(settings, login, remove = false) {
var ignoreInterval = 60000; // 60 seconds - don't increment counter twice within this window
// save store timestamp
localStorage.setItem("recent:" + login.store.path, JSON.stringify(Date.now()));
localStorage.setItem("recent:" + login.store.id, JSON.stringify(Date.now()));
// update login usage count & timestamp
if (Date.now() > login.recent.when + ignoreInterval) {
login.recent.count++;
}
login.recent.when = Date.now();
settings.recent[sha1(settings.host + sha1(login.store.path + sha1(login.login)))] =
login.recent;
settings.recent[sha1(settings.host + sha1(login.store.id + sha1(login.login)))] = login.recent;
// save to local storage
localStorage.setItem("recent", JSON.stringify(settings.recent));