get autofiller enabled via message to bg
This commit is contained in:
parent
299f60dcb3
commit
02b0afd79a
|
@ -1,10 +1,12 @@
|
||||||
import { CipherType } from 'jslib/enums';
|
import { CipherType } from 'jslib/enums';
|
||||||
|
|
||||||
|
import { ConstantsService } from 'jslib/services/constants.service';
|
||||||
import { UtilsService } from 'jslib/services/utils.service';
|
import { UtilsService } from 'jslib/services/utils.service';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
CipherService,
|
CipherService,
|
||||||
PlatformUtilsService,
|
PlatformUtilsService,
|
||||||
|
StorageService,
|
||||||
} from 'jslib/abstractions';
|
} from 'jslib/abstractions';
|
||||||
|
|
||||||
import { BrowserApi } from '../browser/browserApi';
|
import { BrowserApi } from '../browser/browserApi';
|
||||||
|
@ -20,7 +22,8 @@ export default class RuntimeBackground {
|
||||||
private isSafari: boolean;
|
private isSafari: boolean;
|
||||||
|
|
||||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
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.isSafari = this.platformUtilsService.isSafari();
|
||||||
this.runtime = this.isSafari ? safari.application : chrome.runtime;
|
this.runtime = this.isSafari ? safari.application : chrome.runtime;
|
||||||
}
|
}
|
||||||
|
@ -83,6 +86,10 @@ export default class RuntimeBackground {
|
||||||
setTimeout(async () => await this.main.refreshBadgeAndMenu(), 2000);
|
setTimeout(async () => await this.main.refreshBadgeAndMenu(), 2000);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'bgGetAutofillOnPageLoadEnabled':
|
||||||
|
await this.sendStorageValueToTab(ConstantsService.enableAutoFillOnPageLoadKey, sender.tab,
|
||||||
|
msg.responseCommand);
|
||||||
|
break;
|
||||||
case 'bgOpenNotificationBar':
|
case 'bgOpenNotificationBar':
|
||||||
await BrowserApi.tabSendMessageData(sender.tab, 'openNotificationBar', msg.data);
|
await BrowserApi.tabSendMessageData(sender.tab, 'openNotificationBar', msg.data);
|
||||||
break;
|
break;
|
||||||
|
@ -256,12 +263,8 @@ export default class RuntimeBackground {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async currenttabSendMessageData(command: string, data: any = null) {
|
private async sendStorageValueToTab(storageKey: string, tab: any, responseCommand: string) {
|
||||||
const tab = await BrowserApi.getTabFromCurrentWindow();
|
const val = await this.storageService.get<any>(storageKey);
|
||||||
if (tab == null) {
|
await BrowserApi.tabSendMessageData(tab, responseCommand, val);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await BrowserApi.tabSendMessageData(tab, command, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,18 @@ document.addEventListener('DOMContentLoaded', (event) => {
|
||||||
const enabledKey = 'enableAutoFillOnPageLoad';
|
const enabledKey = 'enableAutoFillOnPageLoad';
|
||||||
|
|
||||||
if ((typeof safari !== 'undefined')) {
|
if ((typeof safari !== 'undefined')) {
|
||||||
const json = safari.extension.settings.getItem(enabledKey);
|
const responseCommand = 'autofillerAutofillOnPageLoadEnabledResponse';
|
||||||
if (json) {
|
safari.self.tab.dispatchMessage('bitwarden', {
|
||||||
const obj = JSON.parse(json);
|
command: 'bgGetAutofillOnPageLoadEnabled',
|
||||||
if (obj && obj[enabledKey] === true) {
|
responseCommand: responseCommand
|
||||||
|
});
|
||||||
|
safari.self.addEventListener('message', function (msgEvent) {
|
||||||
|
var msg = msgEvent.message;
|
||||||
|
if (msg.command === responseCommand && msg.data === true) {
|
||||||
setInterval(doFillIfNeeded, 500);
|
setInterval(doFillIfNeeded, 500);
|
||||||
}
|
}
|
||||||
}
|
}, false);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
chrome.storage.local.get(enabledKey, (obj) => {
|
chrome.storage.local.get(enabledKey, (obj) => {
|
||||||
|
|
Loading…
Reference in New Issue