mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-24 12:06:15 +01:00
Add settings toggle to enable/disable browser integration
This commit is contained in:
parent
19edc24b0b
commit
45302e5bd5
@ -1,7 +1,7 @@
|
|||||||
/* tslint:disable:no-console */
|
/* tslint:disable:no-console */
|
||||||
import IPC from 'ipc';
|
import IPC from 'ipc';
|
||||||
|
|
||||||
// Mostly copied from the example on
|
// Mostly based on the example from MDN,
|
||||||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging
|
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging
|
||||||
export default class NativeMessage {
|
export default class NativeMessage {
|
||||||
ipc: IPC;
|
ipc: IPC;
|
||||||
|
@ -88,6 +88,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<small class="help-block">{{'disableFaviconDesc' | i18n}}</small>
|
<small class="help-block">{{'disableFaviconDesc' | i18n}}</small>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="checkbox">
|
||||||
|
<label for="enableBrowserIntegration">
|
||||||
|
<input id="enableBrowserIntegration" type="checkbox" name="EnableBrowserIntegration"
|
||||||
|
[(ngModel)]="enableBrowserIntegration" (change)="saveBrowserIntegration()">
|
||||||
|
{{'enableBrowserIntegration' | i18n}}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<small class="help-block">{{'enableBrowserIntegrationDesc' | i18n}}</small>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="checkbox">
|
<div class="checkbox">
|
||||||
<label for="enableTray">
|
<label for="enableTray">
|
||||||
|
@ -33,6 +33,7 @@ export class SettingsComponent implements OnInit {
|
|||||||
vaultTimeoutAction: string;
|
vaultTimeoutAction: string;
|
||||||
pin: boolean = null;
|
pin: boolean = null;
|
||||||
disableFavicons: boolean = false;
|
disableFavicons: boolean = false;
|
||||||
|
enableBrowserIntegration: boolean = false;
|
||||||
enableMinToTray: boolean = false;
|
enableMinToTray: boolean = false;
|
||||||
enableCloseToTray: boolean = false;
|
enableCloseToTray: boolean = false;
|
||||||
enableTray: boolean = false;
|
enableTray: boolean = false;
|
||||||
@ -119,6 +120,7 @@ export class SettingsComponent implements OnInit {
|
|||||||
const pinSet = await this.vaultTimeoutService.isPinLockSet();
|
const pinSet = await this.vaultTimeoutService.isPinLockSet();
|
||||||
this.pin = pinSet[0] || pinSet[1];
|
this.pin = pinSet[0] || pinSet[1];
|
||||||
this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
|
this.disableFavicons = await this.storageService.get<boolean>(ConstantsService.disableFaviconKey);
|
||||||
|
this.enableBrowserIntegration = await this.storageService.get<boolean>(ElectronConstants.enableBrowserIntegration);
|
||||||
this.enableMinToTray = await this.storageService.get<boolean>(ElectronConstants.enableMinimizeToTrayKey);
|
this.enableMinToTray = await this.storageService.get<boolean>(ElectronConstants.enableMinimizeToTrayKey);
|
||||||
this.enableCloseToTray = await this.storageService.get<boolean>(ElectronConstants.enableCloseToTrayKey);
|
this.enableCloseToTray = await this.storageService.get<boolean>(ElectronConstants.enableCloseToTrayKey);
|
||||||
this.enableTray = await this.storageService.get<boolean>(ElectronConstants.enableTrayKey);
|
this.enableTray = await this.storageService.get<boolean>(ElectronConstants.enableTrayKey);
|
||||||
@ -277,6 +279,11 @@ export class SettingsComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async saveBrowserIntegration() {
|
||||||
|
await this.storageService.save(ElectronConstants.enableBrowserIntegration, this.enableBrowserIntegration);
|
||||||
|
this.messagingService.send(this.enableBrowserIntegration ? 'enableBrowserIntegration' : 'disableBrowserIntegration');
|
||||||
|
}
|
||||||
|
|
||||||
private callAnalytics(name: string, enabled: boolean) {
|
private callAnalytics(name: string, enabled: boolean) {
|
||||||
const status = enabled ? 'Enabled' : 'Disabled';
|
const status = enabled ? 'Enabled' : 'Disabled';
|
||||||
this.analytics.eventTrack.next({ action: `${status} ${name}` });
|
this.analytics.eventTrack.next({ action: `${status} ${name}` });
|
||||||
|
@ -1401,5 +1401,11 @@
|
|||||||
},
|
},
|
||||||
"masterPasswordPolicyRequirementsNotMet": {
|
"masterPasswordPolicyRequirementsNotMet": {
|
||||||
"message": "Your new master password does not meet the policy requirements."
|
"message": "Your new master password does not meet the policy requirements."
|
||||||
|
},
|
||||||
|
"enableBrowserIntegration": {
|
||||||
|
"message": "Enable browser integration"
|
||||||
|
},
|
||||||
|
"enableBrowserIntegrationDesc": {
|
||||||
|
"message": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,6 +144,10 @@ export class Main {
|
|||||||
await this.biometricMain.init();
|
await this.biometricMain.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (await this.storageService.get<boolean>(ElectronConstants.enableBrowserIntegration)) {
|
||||||
|
this.nativeMessagingService.listen();
|
||||||
|
}
|
||||||
|
|
||||||
if (!app.isDefaultProtocolClient('bitwarden')) {
|
if (!app.isDefaultProtocolClient('bitwarden')) {
|
||||||
app.setAsDefaultProtocolClient('bitwarden');
|
app.setAsDefaultProtocolClient('bitwarden');
|
||||||
}
|
}
|
||||||
@ -157,8 +161,6 @@ export class Main {
|
|||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
console.error(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
this.nativeMessagingService.listen();
|
|
||||||
this.nativeMessagingService.generateManifests();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private processDeepLink(argv: string[]): void {
|
private processDeepLink(argv: string[]): void {
|
||||||
|
@ -44,6 +44,14 @@ export class MessagingMain {
|
|||||||
case 'hideToTray':
|
case 'hideToTray':
|
||||||
this.main.trayMain.hideToTray();
|
this.main.trayMain.hideToTray();
|
||||||
break;
|
break;
|
||||||
|
case 'enableBrowserIntegration':
|
||||||
|
this.main.nativeMessagingService.generateManifests();
|
||||||
|
this.main.nativeMessagingService.listen();
|
||||||
|
break;
|
||||||
|
case 'disableBrowserIntegration':
|
||||||
|
this.main.nativeMessagingService.removeManifests();
|
||||||
|
this.main.nativeMessagingService.stop();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,10 @@ export class NativeMessagingService {
|
|||||||
ipc.server.start();
|
ipc.server.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
ipc.server.stop();
|
||||||
|
}
|
||||||
|
|
||||||
generateManifests() {
|
generateManifests() {
|
||||||
const baseJson = {
|
const baseJson = {
|
||||||
'name': 'com.8bit.bitwarden',
|
'name': 'com.8bit.bitwarden',
|
||||||
@ -90,6 +94,35 @@ export class NativeMessagingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeManifests() {
|
||||||
|
switch (process.platform) {
|
||||||
|
case 'win32':
|
||||||
|
this.deleteWindowsRegistry('HKCU\\SOFTWARE\\Mozilla\\NativeMessagingHosts\\com.8bit.bitwarden');
|
||||||
|
this.deleteWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden');
|
||||||
|
break;
|
||||||
|
case 'darwin':
|
||||||
|
if (existsSync('~/Library/Application Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json')) {
|
||||||
|
fs.unlink('~/Library/Application Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existsSync('~/Library/Application Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json')) {
|
||||||
|
fs.unlink('~/Library/Application Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json')
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'linux':
|
||||||
|
if (existsSync('~/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json')) {
|
||||||
|
fs.unlink('~/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existsSync('~/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json')) {
|
||||||
|
fs.unlink('~/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json')
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private writeManifest(destination: string, manifest: object) {
|
private writeManifest(destination: string, manifest: object) {
|
||||||
fs.writeFile(destination, JSON.stringify(manifest, null, 2)).catch(this.logService.error);
|
fs.writeFile(destination, JSON.stringify(manifest, null, 2)).catch(this.logService.error);
|
||||||
}
|
}
|
||||||
@ -106,7 +139,7 @@ export class NativeMessagingService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private createWindowsRegistry(check: string, location: string, jsonFile: string) {
|
private async createWindowsRegistry(check: string, location: string, jsonFile: string) {
|
||||||
const regedit = require('regedit');
|
const regedit = require('regedit');
|
||||||
regedit.setExternalVBSLocation('resources/regedit/vbs');
|
regedit.setExternalVBSLocation('resources/regedit/vbs');
|
||||||
|
|
||||||
@ -117,12 +150,15 @@ export class NativeMessagingService {
|
|||||||
this.logService.debug(`Adding registry: ${location}`)
|
this.logService.debug(`Adding registry: ${location}`)
|
||||||
|
|
||||||
// Check installed
|
// Check installed
|
||||||
list(check)
|
try {
|
||||||
.then(() => {
|
await list(check)
|
||||||
// Create path
|
} catch {
|
||||||
return createKey(location);
|
return;
|
||||||
})
|
}
|
||||||
.then(() => {
|
|
||||||
|
try {
|
||||||
|
await createKey(location);
|
||||||
|
|
||||||
// Insert path to manifest
|
// Insert path to manifest
|
||||||
const obj: any = {};
|
const obj: any = {};
|
||||||
obj[location] = {
|
obj[location] = {
|
||||||
@ -133,7 +169,24 @@ export class NativeMessagingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return putValue(obj);
|
return putValue(obj);
|
||||||
})
|
} catch (error) {
|
||||||
.catch(this.logService.error)
|
this.logService.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async deleteWindowsRegistry(key: string) {
|
||||||
|
const regedit = require("regedit");
|
||||||
|
|
||||||
|
const list = util.promisify(regedit.list);
|
||||||
|
const deleteKey = util.promisify(regedit.deleteKey);
|
||||||
|
|
||||||
|
this.logService.debug(`Removing registry: ${location}`)
|
||||||
|
|
||||||
|
try {
|
||||||
|
await list(key);
|
||||||
|
await deleteKey(key);
|
||||||
|
} catch {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user