Skip to content

Commit

Permalink
Edge tempfix
Browse files Browse the repository at this point in the history
  • Loading branch information
mymindstorm committed Aug 5, 2018
1 parent 655b4bf commit ebd1de2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
30 changes: 15 additions & 15 deletions src/models/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EntryStorage {
return new Promise(
(resolve: (value: boolean) => void,
reject: (reason: Error) => void) => {
chrome.storage.sync.get((_data: {[hash: string]: OTPStorage}) => {
chrome.storage.local.get((_data: {[hash: string]: OTPStorage}) => {
for (const hash of Object.keys(_data)) {
if (!this.isValidEntry(_data, hash)) {
continue;
Expand All @@ -89,7 +89,7 @@ class EntryStorage {
(resolve: (value: {[hash: string]: OTPStorage}) => void,
reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get((_data: {[hash: string]: OTPStorage}) => {
chrome.storage.local.get((_data: {[hash: string]: OTPStorage}) => {
for (const hash of Object.keys(_data)) {
if (!this.isValidEntry(_data, hash)) {
delete _data[hash];
Expand Down Expand Up @@ -127,7 +127,7 @@ class EntryStorage {
return new Promise(
(resolve: () => void, reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get((_data: {[hash: string]: OTPStorage}) => {
chrome.storage.local.get((_data: {[hash: string]: OTPStorage}) => {
for (const hash of Object.keys(data)) {
// never trust data import from user
// we do not support encrypted data import any longer
Expand Down Expand Up @@ -197,7 +197,7 @@ class EntryStorage {
}
}
_data = this.ensureUniqueIndex(_data);
chrome.storage.sync.set(_data, resolve);
chrome.storage.local.set(_data, resolve);
});
return;
} catch (error) {
Expand All @@ -210,15 +210,15 @@ class EntryStorage {
return new Promise(
(resolve: () => void, reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get((_data: {[hash: string]: OTPStorage}) => {
chrome.storage.local.get((_data: {[hash: string]: OTPStorage}) => {
if (_data.hasOwnProperty(entry.hash)) {
throw new Error('The specific entry has already existed.');
}
const storageItem =
this.getOTPStorageFromEntry(encryption, entry);
_data[entry.hash] = storageItem;
_data = this.ensureUniqueIndex(_data);
chrome.storage.sync.set(_data, resolve);
chrome.storage.local.set(_data, resolve);
});
return;
} catch (error) {
Expand All @@ -231,15 +231,15 @@ class EntryStorage {
return new Promise(
(resolve: () => void, reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get((_data: {[hash: string]: OTPStorage}) => {
chrome.storage.local.get((_data: {[hash: string]: OTPStorage}) => {
if (!_data.hasOwnProperty(entry.hash)) {
throw new Error('The specific entry is not existing.');
}
const storageItem =
this.getOTPStorageFromEntry(encryption, entry);
_data[entry.hash] = storageItem;
_data = this.ensureUniqueIndex(_data);
chrome.storage.sync.set(_data, resolve);
chrome.storage.local.set(_data, resolve);
});
return;
} catch (error) {
Expand All @@ -252,14 +252,14 @@ class EntryStorage {
return new Promise(
(resolve: () => void, reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get((_data: {[hash: string]: OTPStorage}) => {
chrome.storage.local.get((_data: {[hash: string]: OTPStorage}) => {
entries.forEach(entry => {
const storageItem =
this.getOTPStorageFromEntry(encryption, entry);
_data[entry.hash] = storageItem;
});
_data = this.ensureUniqueIndex(_data);
chrome.storage.sync.set(_data, resolve);
chrome.storage.local.set(_data, resolve);
});
return;
} catch (error) {
Expand All @@ -273,7 +273,7 @@ class EntryStorage {
(resolve: (value: OTPEntry[]) => void,
reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get(
chrome.storage.local.get(
async (_data: {[hash: string]: OTPStorage}) => {
const data: OTPEntry[] = [];
for (const hash of Object.keys(_data)) {
Expand Down Expand Up @@ -420,21 +420,21 @@ class EntryStorage {
static async remove(hash: string) {
return new Promise(
(resolve: () => void, reject: (reason: Error) => void) => {
return chrome.storage.sync.remove(hash, resolve);
return chrome.storage.local.remove(hash, resolve);
});
}

static async delete(entry: OTPEntry) {
return new Promise(
(resolve: () => void, reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get((_data: {[hash: string]: OTPStorage}) => {
chrome.storage.local.get((_data: {[hash: string]: OTPStorage}) => {
if (_data.hasOwnProperty(entry.hash)) {
delete _data[entry.hash];
}
_data = this.ensureUniqueIndex(_data);
chrome.storage.sync.remove(entry.hash, () => {
chrome.storage.sync.set(_data, resolve);
chrome.storage.local.remove(entry.hash, () => {
chrome.storage.local.set(_data, resolve);
});
return;
});
Expand Down
4 changes: 4 additions & 0 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ async function init() {
ui.instance.fixPopupSize();
}

if (ui.instance.isEdge()) {
localStorage.storageLocation = 'local'
}

return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function testFinished() {
async function clear() {
return new Promise((resolve: () => void, reject: (reason: Error) => void) => {
try {
chrome.storage.sync.clear(resolve);
chrome.storage.local.clear(resolve);
} catch (error) {
reject(error);
}
Expand All @@ -258,7 +258,7 @@ async function get<T>() {
(resolve: (items: {[key: string]: T}) => void,
reject: (reason: Error) => void) => {
try {
chrome.storage.sync.get(resolve);
chrome.storage.local.get(resolve);
} catch (error) {
reject(error);
}
Expand All @@ -269,7 +269,7 @@ async function set(items: {[key: string]: {}}) {
/* tslint:disable-next-line:no-any */
return new Promise((resolve: () => void, reject: (reason: Error) => void) => {
try {
chrome.storage.sync.set(items, resolve);
chrome.storage.local.set(items, resolve);
} catch (error) {
reject(error);
}
Expand Down

0 comments on commit ebd1de2

Please sign in to comment.