diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 386df7fb39..d0b1725867 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -166,6 +166,7 @@ export default class MainBackground { await this.runtimeBackground.init(); await this.tabsBackground.init(); + if (!this.isSafari) { await this.commandsBackground.init(); await this.contextMenusBackground.init(); diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 6b36c030e0..499c17cb4d 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -23,7 +23,7 @@ export default class RuntimeBackground { constructor(private main: MainBackground, private autofillService: AutofillService, private cipherService: CipherService, private platformUtilsService: PlatformUtilsService, - private storageService: StorageService) { + private storageService: StorageService, private i18nService: any) { this.isSafari = this.platformUtilsService.isSafari(); this.runtime = this.isSafari ? safari.application : chrome.runtime; } @@ -260,22 +260,27 @@ export default class RuntimeBackground { } } - private async sendStorageValueToTab(storageKey: string, tab: any, responseCommand: string) { - const val = await this.storageService.get(storageKey); - await BrowserApi.tabSendMessageData(tab, responseCommand, val); - } - private async getDataForTab(tab: any, responseCommand: string) { - const responseVal: any = {}; + const responseData: any = {}; if (responseCommand === 'notificationBarDataResponse') { - responseVal.neverDomains = await this.storageService.get(ConstantsService.neverDomainsKey); - responseVal.disabledNotification = await this.storageService.get( + responseData.neverDomains = await this.storageService.get(ConstantsService.neverDomainsKey); + responseData.disabledNotification = await this.storageService.get( ConstantsService.disableAddLoginNotificationKey); } else if (responseCommand === 'autofillerAutofillOnPageLoadEnabledResponse') { - responseVal.autofillEnabled = await this.storageService.get( + responseData.autofillEnabled = await this.storageService.get( ConstantsService.enableAutoFillOnPageLoadKey); + } else if (responseCommand === 'notificationBarFrameDataResponse') { + responseData.i18n = { + appName: this.i18nService.appName, + close: this.i18nService.close, + yes: this.i18nService.yes, + never: this.i18nService.never, + notificationAddSave: this.i18nService.notificationAddSave, + notificationNeverSave: this.i18nService.notificationNeverSave, + notificationAddDesc: this.i18nService.notificationAddDesc, + }; } - await BrowserApi.tabSendMessageData(tab, responseCommand, responseVal); + await BrowserApi.tabSendMessageData(tab, responseCommand, responseData); } } diff --git a/src/background/tabs.background.ts b/src/background/tabs.background.ts index 07734b53b9..9daf12a528 100644 --- a/src/background/tabs.background.ts +++ b/src/background/tabs.background.ts @@ -20,7 +20,7 @@ export default class TabsBackground { this.tabs.addEventListener('activate', async (ev: any) => { await this.main.refreshBadgeAndMenu(); }, true); - + this.tabs.addEventListener('navigate', async (ev: any) => { await this.main.checkLoginsToAdd(); await this.main.refreshBadgeAndMenu(); diff --git a/src/notification/bar.js b/src/notification/bar.js index 5140109e75..c52965ab22 100644 --- a/src/notification/bar.js +++ b/src/notification/bar.js @@ -3,15 +3,18 @@ require('./bar.less'); document.addEventListener('DOMContentLoaded', function () { var i18n = {}; if (typeof safari !== 'undefined') { - // TODO: load when we get i18n strings - i18n.appName = 'bitwarden'; - i18n.close = 'close'; - i18n.yes = 'Yes'; - i18n.never = 'Never'; - i18n.notificationAddSave = 'Save Site';; - i18n.notificationNeverSave = 'Never Save'; - i18n.notificationAddDesc = 'Want to Save?'; - setTimeout(load, 50); + const responseCommand = 'notificationBarFrameDataResponse'; + sendPlatformMessage({ + command: 'bgGetDataForTab', + responseCommand: responseCommand + }); + safari.self.addEventListener('message', function (msgEvent) { + const msg = msgEvent.message; + if (msg.command === responseCommand && msg.data) { + i18n = msg.data.i18n; + load(); + } + }, false); } else { i18n.appName = chrome.i18n.getMessage('appName');