mirror of
https://github.com/lajg-dev/Obsidian-Plugin-GPG-Inline-Encrypt.git
synced 2026-07-22 09:20:31 +00:00
Add new feacture to include add a before and after gpg command
This commit is contained in:
parent
fb4d99fcf0
commit
2c6d745144
7 changed files with 379 additions and 131 deletions
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"id": "gpg-encrypt",
|
||||
"name": "GPG Encrypt",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.8",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "GPG encrypt inline text using hotkeys",
|
||||
"description": "Plugin to encrypt partial text or complete notes using GPG technology, it is compatible with security keys such as YubiKey or traditional GPG encryption methods",
|
||||
"author": "Luis Jaramillo",
|
||||
"authorUrl": "https://www.lajg.dev",
|
||||
"fundingUrl": "https://www.lajg.dev/donate/",
|
||||
|
|
|
|||
403
package-lock.json
generated
403
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "gpg-encrypt",
|
||||
"version": "1.0.7",
|
||||
"description": "GPG encrypt inline text using hotkeys",
|
||||
"version": "1.0.8",
|
||||
"description": "Plugin to encrypt partial text or complete notes using GPG technology, it is compatible with security keys such as YubiKey or traditional GPG encryption methods",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ export interface GpgEncryptSettings {
|
|||
pgpExecPath: string;
|
||||
pgpSignPublicKeyId: string
|
||||
pgpAlwaysTrust: boolean,
|
||||
pgpDefaultEncryptKeys: Array<string>
|
||||
pgpDefaultEncryptKeys: Array<string>,
|
||||
pgpAditionalCommands: boolean,
|
||||
pgpAditionalCommandsBefore: string,
|
||||
pgpAditionalCommandsAfter: string
|
||||
}
|
||||
|
||||
// Default settings values
|
||||
|
|
@ -13,7 +16,10 @@ const DEFAULT_SETTINGS: GpgEncryptSettings = {
|
|||
pgpExecPath: getDefaultExecPath(),
|
||||
pgpSignPublicKeyId: "0",
|
||||
pgpAlwaysTrust: false,
|
||||
pgpDefaultEncryptKeys: []
|
||||
pgpDefaultEncryptKeys: [],
|
||||
pgpAditionalCommands: false,
|
||||
pgpAditionalCommandsBefore: "",
|
||||
pgpAditionalCommandsAfter: ""
|
||||
}
|
||||
|
||||
// Settings class
|
||||
|
|
|
|||
|
|
@ -26,7 +26,11 @@ export class GpgSettingsTab extends PluginSettingTab {
|
|||
}
|
||||
// List of settings objetcts
|
||||
private gpgExecPath: Setting;
|
||||
private gpgAditionalCommands: Setting;
|
||||
private gpgAditionalCommandsBefore: Setting;
|
||||
private gpgAditionalCommandsAfter: Setting;
|
||||
private gpgExecPathStatus: HTMLDivElement;
|
||||
private gpgAditionalCommandsWarning: HTMLDivElement;
|
||||
private gpgPublicKeysList: Setting;
|
||||
private gpgSignKeyId: Setting;
|
||||
// Display function in settings tabs
|
||||
|
|
@ -94,6 +98,31 @@ export class GpgSettingsTab extends PluginSettingTab {
|
|||
// Call method to refresh list to Sign text
|
||||
this.RefreshListSign(this.plugin.settings.pgpSignPublicKeyId != "0");
|
||||
// ---------- GPG Key ID to Sign text ----------
|
||||
|
||||
// ---------- Aditional Commands ----------
|
||||
this.gpgAditionalCommands = new Setting(containerEl)
|
||||
.setName("Aditional commands")
|
||||
.setDesc("Add custom commands to be executed before or after the gpg command calls")
|
||||
.addToggle((toggle) => {
|
||||
// Toggle component default value is false
|
||||
toggle.setValue(this.plugin.settings.pgpAditionalCommands);
|
||||
// Toggle component is created with onChange event
|
||||
toggle.onChange((value: boolean) => {
|
||||
// Call method to show/hide aditional commands
|
||||
this.RefreshAditionalCommands(value);
|
||||
});
|
||||
});
|
||||
// Div to show an advance users wraning
|
||||
this.gpgAditionalCommandsWarning = this.gpgAditionalCommands.descEl.createDiv();
|
||||
this.gpgAditionalCommandsWarning.setText('Warning: Only advance users');
|
||||
// Change to red color
|
||||
this.gpgAditionalCommandsWarning.className = "text-color-red";
|
||||
// Create the Aditional Commands Before/After
|
||||
this.gpgAditionalCommandsBefore = new Setting(containerEl);
|
||||
this.gpgAditionalCommandsAfter = new Setting(containerEl);
|
||||
// Call method to show/hide aditional commands
|
||||
this.RefreshAditionalCommands(this.plugin.settings.pgpAditionalCommands);
|
||||
// ---------- Aditional Commands ----------
|
||||
}
|
||||
|
||||
// Function to check if GPG Path exits
|
||||
|
|
@ -293,4 +322,46 @@ export class GpgSettingsTab extends PluginSettingTab {
|
|||
await new Settings(this.plugin).saveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
// Function to refresh List of Sign Keys ID
|
||||
private async RefreshAditionalCommands(aditionalCommands: boolean) {
|
||||
// Clear gpgAditionalCommands setting
|
||||
this.gpgAditionalCommandsBefore.clear();
|
||||
this.gpgAditionalCommandsAfter.clear();
|
||||
// Re-Create gpgAditionalCommands setting
|
||||
this.gpgAditionalCommandsBefore.setName("Additional Commands (Before)");
|
||||
this.gpgAditionalCommandsAfter.setName("Additional Commands (After)");
|
||||
this.gpgAditionalCommandsBefore.setDesc("Enter the commands to be executed before running the gpg commands (Note: If you need to nest more than one command use &&, DO NOT include closing characters && as these will be added automatically)");
|
||||
this.gpgAditionalCommandsAfter.setDesc("Enter the commands to be executed after running the gpg commands (Note: If you need to nest more than one command use &&, DO NOT include closing characters && as these will be added automatically)");
|
||||
// Show or Hide gpgAditionalCommands settings according aditionalCommands flag
|
||||
aditionalCommands ? this.gpgAditionalCommandsBefore.settingEl.show() : this.gpgAditionalCommandsBefore.settingEl.hide();
|
||||
aditionalCommands ? this.gpgAditionalCommandsAfter.settingEl.show() : this.gpgAditionalCommandsAfter.settingEl.hide();
|
||||
// Added the text inputs
|
||||
this.gpgAditionalCommandsBefore.addText(text => text
|
||||
.setPlaceholder('command')
|
||||
.setValue(this.plugin.settings.pgpAditionalCommandsBefore)
|
||||
.onChange(async (value: string) => {
|
||||
// Set settig variable pgpAditionalCommandsBefore with new value
|
||||
this.plugin.settings.pgpAditionalCommandsBefore = value;
|
||||
// Save settings with change
|
||||
await new Settings(this.plugin).saveSettings();
|
||||
// Run a script to check gpg path with pgpAditionalCommandsBefore
|
||||
await this.checkGpgPath(this.plugin.settings.pgpExecPath);
|
||||
}));
|
||||
this.gpgAditionalCommandsAfter.addText(text => text
|
||||
.setPlaceholder('command')
|
||||
.setValue(this.plugin.settings.pgpAditionalCommandsAfter)
|
||||
.onChange(async (value: string) => {
|
||||
// Set settig variable pgpAditionalCommandsAfter with new value
|
||||
this.plugin.settings.pgpAditionalCommandsAfter = value;
|
||||
// Save settings with change
|
||||
await new Settings(this.plugin).saveSettings();
|
||||
// Run a script to check gpg path with pgpAditionalCommandsAfter
|
||||
await this.checkGpgPath(this.plugin.settings.pgpExecPath);
|
||||
}));
|
||||
// Set settig variable pgpAditionalCommands with new value
|
||||
this.plugin.settings.pgpAditionalCommands = aditionalCommands;
|
||||
// Save settings with change
|
||||
await new Settings(this.plugin).saveSettings();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
src/gpg.ts
15
src/gpg.ts
|
|
@ -34,12 +34,25 @@ export default function spawnGPG(settings: GpgEncryptSettings, input: string |
|
|||
// Create an empty args array
|
||||
args = [];
|
||||
}
|
||||
let fullArgs: string[] = globalArgs.concat(args);
|
||||
|
||||
// Initial variables
|
||||
const buffers: Buffer[] = [];
|
||||
let buffersLength = 0;
|
||||
let error = "";
|
||||
const gpg = spawn(settings.pgpExecPath, globalArgs.concat(args));
|
||||
|
||||
let command = "";
|
||||
if (settings.pgpAditionalCommands && settings.pgpAditionalCommandsBefore !== '') {
|
||||
command = settings.pgpAditionalCommandsBefore + " && ";
|
||||
}
|
||||
command += settings.pgpExecPath;
|
||||
fullArgs.forEach(arg => {
|
||||
command += " " + arg;
|
||||
});
|
||||
if (settings.pgpAditionalCommands && settings.pgpAditionalCommandsAfter !== '') {
|
||||
command += " && " + settings.pgpAditionalCommandsAfter;
|
||||
}
|
||||
const gpg = spawn(command, { shell: true });
|
||||
|
||||
gpg.stdout.on("data", (buf: Buffer) => {
|
||||
buffers.push(buf);
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@
|
|||
"1.0.4": "0.15.0",
|
||||
"1.0.5": "0.15.0",
|
||||
"1.0.6": "0.15.0",
|
||||
"1.0.7": "0.15.0"
|
||||
"1.0.7": "0.15.0",
|
||||
"1.0.8": "0.15.0"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue