mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
Initial work of biometric unlock for browser
This commit is contained in:
@@ -55,8 +55,8 @@ export default class ContextMenusBackground {
|
||||
private async cipherAction(info: any) {
|
||||
const id = info.menuItemId.split('_')[1];
|
||||
if (id === 'noop') {
|
||||
if (chrome.browserAction && chrome.browserAction.openPopup) {
|
||||
chrome.browserAction.openPopup();
|
||||
if (chrome.browserAction && (chrome.browserAction as any).openPopup) {
|
||||
(chrome.browserAction as any).openPopup();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ import I18nService from '../services/i18n.service';
|
||||
import { PopupUtilsService } from '../popup/services/popup-utils.service';
|
||||
|
||||
import { AutofillService as AutofillServiceAbstraction } from '../services/abstractions/autofill.service';
|
||||
import { NativeMessagingBackground } from './nativeMessaging.background';
|
||||
|
||||
export default class MainBackground {
|
||||
messagingService: MessagingServiceAbstraction;
|
||||
@@ -137,8 +138,11 @@ export default class MainBackground {
|
||||
private menuOptionsLoaded: any[] = [];
|
||||
private syncTimeout: any;
|
||||
private isSafari: boolean;
|
||||
nativeMessagingBackground: NativeMessagingBackground;
|
||||
|
||||
constructor() {
|
||||
this.nativeMessagingBackground = new NativeMessagingBackground();
|
||||
|
||||
// Services
|
||||
this.messagingService = new BrowserMessagingService();
|
||||
this.platformUtilsService = new BrowserPlatformUtilsService(this.messagingService,
|
||||
@@ -146,7 +150,7 @@ export default class MainBackground {
|
||||
if (this.systemService != null) {
|
||||
this.systemService.clearClipboard(clipboardValue, clearMs);
|
||||
}
|
||||
});
|
||||
}, this.nativeMessagingBackground);
|
||||
this.storageService = new BrowserStorageService(this.platformUtilsService);
|
||||
this.secureStorageService = new BrowserStorageService(this.platformUtilsService);
|
||||
this.i18nService = new I18nService(BrowserApi.getUILanguage(window));
|
||||
|
||||
40
src/background/nativeMessaging.background.ts
Normal file
40
src/background/nativeMessaging.background.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { BrowserApi } from "../browser/browserApi";
|
||||
|
||||
export class NativeMessagingBackground {
|
||||
private connected = false;
|
||||
private port: browser.runtime.Port | chrome.runtime.Port;
|
||||
|
||||
private resolver: any = null;
|
||||
|
||||
connect() {
|
||||
this.port = BrowserApi.connectNative("com.8bit.bitwarden");
|
||||
|
||||
this.connected = true;
|
||||
this.port.onMessage.addListener((msg: any) => {
|
||||
if (this.resolver) {
|
||||
this.resolver(msg);
|
||||
} else {
|
||||
console.error('NO RESOLVER');
|
||||
}
|
||||
});
|
||||
this.port.onDisconnect.addListener(() => {
|
||||
this.connected = false;
|
||||
console.log('Disconnected');
|
||||
});
|
||||
}
|
||||
|
||||
send(message: object) {
|
||||
// If not connected, try to connect
|
||||
if (!this.connected) {
|
||||
this.connect();
|
||||
}
|
||||
|
||||
this.port.postMessage(message);
|
||||
}
|
||||
|
||||
await(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.resolver = resolve;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user