1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-27 12:36:14 +01:00

isSafari checks

This commit is contained in:
Kyle Spearrin 2018-01-11 15:34:55 -05:00
parent 82e88eb1ba
commit 3743e5b409
2 changed files with 34 additions and 22 deletions

View File

@ -8,8 +8,11 @@ export default class BrowserMessagingService implements MessagingService {
}
send(subscriber: string, arg: any = {}) {
// if safari, else
const message = Object.assign({}, { command: subscriber }, arg);
chrome.runtime.sendMessage(message);
if (this.platformUtilsService.isSafari()) {
// send message
} else {
const message = Object.assign({}, { command: subscriber }, arg);
chrome.runtime.sendMessage(message);
}
}
}

View File

@ -8,33 +8,42 @@ export default class BrowserStorageService implements StorageService {
}
get<T>(key: string): Promise<T> {
// if safari, else
return new Promise((resolve) => {
chrome.storage.local.get(key, (obj: any) => {
if (obj && (typeof obj[key] !== 'undefined') && obj[key] !== null) {
resolve(obj[key] as T);
} else {
resolve(null);
}
if (this.platformUtilsService.isSafari()) {
// use safari storage
} else {
return new Promise((resolve) => {
chrome.storage.local.get(key, (obj: any) => {
if (obj && (typeof obj[key] !== 'undefined') && obj[key] !== null) {
resolve(obj[key] as T);
} else {
resolve(null);
}
});
});
});
}
}
save(key: string, obj: any): Promise<any> {
// if safari, else
return new Promise((resolve) => {
chrome.storage.local.set({ [key]: obj }, () => {
resolve();
if (this.platformUtilsService.isSafari()) {
// use safari storage
} else {
return new Promise((resolve) => {
chrome.storage.local.set({ [key]: obj }, () => {
resolve();
});
});
});
}
}
remove(key: string): Promise<any> {
// if safari, else
return new Promise((resolve) => {
chrome.storage.local.remove(key, () => {
resolve();
if (this.platformUtilsService.isSafari()) {
// use safari storage
} else {
return new Promise((resolve) => {
chrome.storage.local.remove(key, () => {
resolve();
});
});
});
}
}
}