get autofiller enabled via message to bg

This commit is contained in:
Kyle Spearrin 2018-01-12 22:31:03 -05:00
parent 299f60dcb3
commit 02b0afd79a
2 changed files with 21 additions and 13 deletions

View File

@ -1,10 +1,12 @@
import { CipherType } from 'jslib/enums';
import { ConstantsService } from 'jslib/services/constants.service';
import { UtilsService } from 'jslib/services/utils.service';
import {
CipherService,
PlatformUtilsService,
StorageService,
} from 'jslib/abstractions';
import { BrowserApi } from '../browser/browserApi';
@ -20,7 +22,8 @@ export default class RuntimeBackground {
private isSafari: boolean;
constructor(private main: MainBackground, private autofillService: AutofillService,
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService) {
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService,
private storageService: StorageService) {
this.isSafari = this.platformUtilsService.isSafari();
this.runtime = this.isSafari ? safari.application : chrome.runtime;
}
@ -83,6 +86,10 @@ export default class RuntimeBackground {
setTimeout(async () => await this.main.refreshBadgeAndMenu(), 2000);
}
break;
case 'bgGetAutofillOnPageLoadEnabled':
await this.sendStorageValueToTab(ConstantsService.enableAutoFillOnPageLoadKey, sender.tab,
msg.responseCommand);
break;
case 'bgOpenNotificationBar':
await BrowserApi.tabSendMessageData(sender.tab, 'openNotificationBar', msg.data);
break;
@ -256,12 +263,8 @@ export default class RuntimeBackground {
}
}
private async currenttabSendMessageData(command: string, data: any = null) {
const tab = await BrowserApi.getTabFromCurrentWindow();
if (tab == null) {
return;
}
await BrowserApi.tabSendMessageData(tab, command, data);
private async sendStorageValueToTab(storageKey: string, tab: any, responseCommand: string) {
const val = await this.storageService.get<any>(storageKey);
await BrowserApi.tabSendMessageData(tab, responseCommand, val);
}
}

View File

@ -3,13 +3,18 @@ document.addEventListener('DOMContentLoaded', (event) => {
const enabledKey = 'enableAutoFillOnPageLoad';
if ((typeof safari !== 'undefined')) {
const json = safari.extension.settings.getItem(enabledKey);
if (json) {
const obj = JSON.parse(json);
if (obj && obj[enabledKey] === true) {
const responseCommand = 'autofillerAutofillOnPageLoadEnabledResponse';
safari.self.tab.dispatchMessage('bitwarden', {
command: 'bgGetAutofillOnPageLoadEnabled',
responseCommand: responseCommand
});
safari.self.addEventListener('message', function (msgEvent) {
var msg = msgEvent.message;
if (msg.command === responseCommand && msg.data === true) {
setInterval(doFillIfNeeded, 500);
}
}
}, false);
return;
}
else {
chrome.storage.local.get(enabledKey, (obj) => {