mirror of https://github.com/keeweb/keeweb.git
starting the extension host based on settings
This commit is contained in:
parent
195e2cc8f0
commit
dd4ad6d72b
|
@ -30,7 +30,7 @@ const pendingBrowserMessages = [];
|
||||||
let processingBrowserMessage = false;
|
let processingBrowserMessage = false;
|
||||||
|
|
||||||
const BrowserExtensionConnector = {
|
const BrowserExtensionConnector = {
|
||||||
enabled: true,
|
started: false,
|
||||||
logger,
|
logger,
|
||||||
|
|
||||||
init(appModel) {
|
init(appModel) {
|
||||||
|
@ -41,6 +41,7 @@ const BrowserExtensionConnector = {
|
||||||
|
|
||||||
if (Launcher) {
|
if (Launcher) {
|
||||||
const { ipcRenderer } = Launcher.electron();
|
const { ipcRenderer } = Launcher.electron();
|
||||||
|
|
||||||
ipcRenderer.on('browserExtensionSocketConnected', (e, socketId, connectionInfo) =>
|
ipcRenderer.on('browserExtensionSocketConnected', (e, socketId, connectionInfo) =>
|
||||||
this.socketConnected(socketId, connectionInfo)
|
this.socketConnected(socketId, connectionInfo)
|
||||||
);
|
);
|
||||||
|
@ -50,9 +51,13 @@ const BrowserExtensionConnector = {
|
||||||
ipcRenderer.on('browserExtensionSocketRequest', (e, socketId, request) =>
|
ipcRenderer.on('browserExtensionSocketRequest', (e, socketId, request) =>
|
||||||
this.socketRequest(socketId, request)
|
this.socketRequest(socketId, request)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
AppSettingsModel.on('change', () => this.appSettingsChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.start();
|
if (this.isEnabled()) {
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
@ -61,6 +66,8 @@ const BrowserExtensionConnector = {
|
||||||
} else {
|
} else {
|
||||||
this.startWebMessageListener();
|
this.startWebMessageListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.started = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
@ -73,7 +80,31 @@ const BrowserExtensionConnector = {
|
||||||
ProtocolImpl.cleanup();
|
ProtocolImpl.cleanup();
|
||||||
connections.clear();
|
connections.clear();
|
||||||
|
|
||||||
logger.info('Stopped');
|
this.started = false;
|
||||||
|
},
|
||||||
|
|
||||||
|
appSettingsChanged() {
|
||||||
|
if (this.isEnabled()) {
|
||||||
|
if (!this.started) {
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
|
} else if (this.started) {
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isEnabled() {
|
||||||
|
if (!Launcher) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (const ext of SupportedExtensions) {
|
||||||
|
for (const browser of SupportedBrowsers) {
|
||||||
|
if (AppSettingsModel[`extensionEnabled${ext.alias}${browser}`]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
startWebMessageListener() {
|
startWebMessageListener() {
|
||||||
|
|
Loading…
Reference in New Issue