From 3743e5b40963aa6c32e31427e0c2b6b57f102937 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 11 Jan 2018 15:34:55 -0500 Subject: [PATCH] isSafari checks --- src/services/browserMessaging.service.ts | 9 +++-- src/services/browserStorage.service.ts | 47 ++++++++++++++---------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/services/browserMessaging.service.ts b/src/services/browserMessaging.service.ts index f27012a617..9fa953aae8 100644 --- a/src/services/browserMessaging.service.ts +++ b/src/services/browserMessaging.service.ts @@ -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); + } } } diff --git a/src/services/browserStorage.service.ts b/src/services/browserStorage.service.ts index 69908c9c2f..b79724ca64 100644 --- a/src/services/browserStorage.service.ts +++ b/src/services/browserStorage.service.ts @@ -8,33 +8,42 @@ export default class BrowserStorageService implements StorageService { } get(key: string): Promise { - // 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 { - // 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 { - // 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(); + }); }); - }); + } } }