mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-26 07:39:04 +02:00
extension installation on Windows
This commit is contained in:
parent
822602a38f
commit
233721bf51
|
@ -40,7 +40,6 @@
|
||||||
<li><a href="https://github.com/antelle/node-yubikey-chalresp" target="_blank">node-yubikey-chalresp</a><span class="muted-color">, YubiKey challenge-response API for node.js, © 2020 Antelle</span></li>
|
<li><a href="https://github.com/antelle/node-yubikey-chalresp" target="_blank">node-yubikey-chalresp</a><span class="muted-color">, YubiKey challenge-response API for node.js, © 2020 Antelle</span></li>
|
||||||
<li><a href="https://github.com/antelle/node-secure-enclave" target="_blank">node-secure-enclave</a><span class="muted-color">, Secure Enclave module for node.js and Electron, © 2020 Antelle</span></li>
|
<li><a href="https://github.com/antelle/node-secure-enclave" target="_blank">node-secure-enclave</a><span class="muted-color">, Secure Enclave module for node.js and Electron, © 2020 Antelle</span></li>
|
||||||
<li><a href="https://github.com/antelle/node-keyboard-auto-type" target="_blank">node-keyboard-auto-type</a><span class="muted-color">, node.js bindings for keyboard-auto-type, © 2021 Antelle</span></li>
|
<li><a href="https://github.com/antelle/node-keyboard-auto-type" target="_blank">node-keyboard-auto-type</a><span class="muted-color">, node.js bindings for keyboard-auto-type, © 2021 Antelle</span></li>
|
||||||
<li><a href="https://github.com/Eugeny/windows-native-registry" target="_blank">windows-native-registry</a><span class="muted-color">, native windows registry access for Node, © 2020 Eugeny</span></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const windowsRegistry = require('./windows-registry');
|
||||||
const { isDev } = require('./app-info');
|
const { isDev } = require('./app-info');
|
||||||
const { app } = require('electron');
|
const { app } = require('electron');
|
||||||
|
|
||||||
|
@ -17,8 +18,6 @@ function getManifestDir(browser) {
|
||||||
default:
|
default:
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
case 'win32':
|
|
||||||
throw new Error('not implemented');
|
|
||||||
case 'linux':
|
case 'linux':
|
||||||
switch (browser) {
|
switch (browser) {
|
||||||
case 'Chrome':
|
case 'Chrome':
|
||||||
|
@ -33,15 +32,39 @@ function getManifestDir(browser) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getManifestFileName(extension) {
|
function getWindowsRegistryPath(browser) {
|
||||||
|
switch (browser) {
|
||||||
|
case 'Chrome':
|
||||||
|
return 'HKCU\\Software\\Google\\Chrome\\NativeMessagingHosts\\';
|
||||||
|
case 'Firefox':
|
||||||
|
return 'HKCU\\Software\\Mozilla\\NativeMessagingHosts\\';
|
||||||
|
case 'Edge':
|
||||||
|
return 'HKCU\\Software\\Microsoft\\Edge\\NativeMessagingHosts\\';
|
||||||
|
default:
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWindowsManifestFileName(browser) {
|
||||||
|
const suffix = browser === 'Firefox' ? 'firefox' : 'chrome';
|
||||||
|
const manifestName = `native-messaging.${suffix}.json`;
|
||||||
|
return path.join(app.getPath('userData'), manifestName);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNativeHostName(extension) {
|
||||||
switch (extension) {
|
switch (extension) {
|
||||||
case 'KWC':
|
case 'KWC':
|
||||||
return 'net.antelle.keeweb.keeweb_connect.json';
|
return 'net.antelle.keeweb.keeweb_connect';
|
||||||
case 'KPXC':
|
case 'KPXC':
|
||||||
return 'org.keepassxc.keepassxc_browser.json';
|
return 'org.keepassxc.keepassxc_browser';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getManifestFileName(extension) {
|
||||||
|
const nativeHostName = getNativeHostName(extension);
|
||||||
|
return nativeHostName ? nativeHostName + '.json' : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function createManifest(browser, extension) {
|
function createManifest(browser, extension) {
|
||||||
switch (extension) {
|
switch (extension) {
|
||||||
case 'KWC':
|
case 'KWC':
|
||||||
|
@ -92,41 +115,71 @@ function getNativeMessagingHostPath() {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.install = async function (browser, extension) {
|
module.exports.install = async function (browser, extension) {
|
||||||
const manifestDir = getManifestDir(browser);
|
|
||||||
if (!manifestDir) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.promises.mkdir(manifestDir, { recursive: true });
|
|
||||||
|
|
||||||
const manifestFileName = getManifestFileName(extension);
|
|
||||||
if (!manifestFileName) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fullPath = path.join(manifestDir, manifestFileName);
|
|
||||||
|
|
||||||
const manifest = createManifest(browser, extension);
|
const manifest = createManifest(browser, extension);
|
||||||
if (!manifest) {
|
if (!manifest) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
manifest.path = getNativeMessagingHostPath();
|
manifest.path = getNativeMessagingHostPath();
|
||||||
|
|
||||||
await fs.promises.writeFile(fullPath, JSON.stringify(manifest, null, 4));
|
if (process.platform === 'win32') {
|
||||||
|
const registryPath = getWindowsRegistryPath(browser);
|
||||||
|
if (!registryPath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const registryKeyName = getNativeHostName(extension);
|
||||||
|
if (!registryKeyName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifestFileName = getWindowsManifestFileName(browser);
|
||||||
|
await fs.promises.writeFile(manifestFileName, JSON.stringify(manifest, null, 4));
|
||||||
|
|
||||||
|
windowsRegistry.createKey(registryPath + registryKeyName, manifestFileName);
|
||||||
|
} else {
|
||||||
|
const manifestDir = getManifestDir(browser);
|
||||||
|
if (!manifestDir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.promises.mkdir(manifestDir, { recursive: true });
|
||||||
|
|
||||||
|
const manifestFileName = getManifestFileName(extension);
|
||||||
|
if (!manifestFileName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fullPath = path.join(manifestDir, manifestFileName);
|
||||||
|
|
||||||
|
await fs.promises.writeFile(fullPath, JSON.stringify(manifest, null, 4));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.uninstall = async function (browser, extension) {
|
module.exports.uninstall = async function (browser, extension) {
|
||||||
const manifestDir = getManifestDir(browser);
|
if (process.platform === 'win32') {
|
||||||
if (!manifestDir) {
|
const registryPath = getWindowsRegistryPath(browser);
|
||||||
return;
|
if (!registryPath) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const manifestFileName = getManifestFileName(extension);
|
const registryKeyName = getNativeHostName(extension);
|
||||||
if (!manifestFileName) {
|
if (!registryKeyName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const fullPath = path.join(manifestDir, manifestFileName);
|
|
||||||
|
|
||||||
await fs.promises.unlink(fullPath);
|
windowsRegistry.deleteKey(registryPath + registryKeyName);
|
||||||
|
} else {
|
||||||
|
const manifestDir = getManifestDir(browser);
|
||||||
|
if (!manifestDir) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const manifestFileName = getManifestFileName(extension);
|
||||||
|
if (!manifestFileName) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fullPath = path.join(manifestDir, manifestFileName);
|
||||||
|
|
||||||
|
await fs.promises.unlink(fullPath);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
13
desktop/scripts/util/windows-registry.js
Normal file
13
desktop/scripts/util/windows-registry.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
|
function reg(...args) {
|
||||||
|
spawn('REG', args);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.createKey = function (key, value) {
|
||||||
|
return reg('ADD', key, '/ve', '/d', value, '/f');
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.deleteKey = function (key) {
|
||||||
|
return reg('DELETE', key, '/f');
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user