load i18n in notificat bar for safari

This commit is contained in:
Kyle Spearrin 2018-01-13 15:09:05 -05:00
parent 698632a1df
commit 561de6df04
4 changed files with 30 additions and 21 deletions

View File

@ -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();

View File

@ -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<any>(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<any>(ConstantsService.neverDomainsKey);
responseVal.disabledNotification = await this.storageService.get<boolean>(
responseData.neverDomains = await this.storageService.get<any>(ConstantsService.neverDomainsKey);
responseData.disabledNotification = await this.storageService.get<boolean>(
ConstantsService.disableAddLoginNotificationKey);
} else if (responseCommand === 'autofillerAutofillOnPageLoadEnabledResponse') {
responseVal.autofillEnabled = await this.storageService.get<boolean>(
responseData.autofillEnabled = await this.storageService.get<boolean>(
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);
}
}

View File

@ -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();

View File

@ -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');