mirror of
https://github.com/lajg-dev/Obsidian-Plugin-GPG-Inline-Encrypt.git
synced 2026-07-22 09:20:31 +00:00
Add extra info in decrypt
This commit is contained in:
parent
54e8b17307
commit
1a4c73fc76
3 changed files with 46 additions and 4 deletions
|
|
@ -5,7 +5,7 @@ import GpgEncryptPlugin from "main";
|
|||
export class DecryptModal extends Modal {
|
||||
|
||||
// Constructor of modal encrypt
|
||||
constructor(app: App, public plainText: string, public plugin: GpgEncryptPlugin, public from: number, public to: number) {
|
||||
constructor(app: App, public plainText: string, public extraInfo: string, public plugin: GpgEncryptPlugin, public from: number, public to: number) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
|
|
@ -13,8 +13,16 @@ export class DecryptModal extends Modal {
|
|||
async onOpen() {
|
||||
// Get an instance of this Element
|
||||
const {contentEl} = this;
|
||||
// A title div and text p is created
|
||||
// A title div is created
|
||||
contentEl.createEl("h1", { text: "Decrypted text" });
|
||||
// Check if extra info is not null nor empty
|
||||
if (this.extraInfo && this.extraInfo.trim() != "") {
|
||||
// P that shows extra info in decrypt process
|
||||
let extraInfoDiv: HTMLDivElement = contentEl.createEl("div");
|
||||
extraInfoDiv.className = "gpg-code-sign-ok";
|
||||
this.organizeOutText(this.extraInfo, extraInfoDiv);
|
||||
}
|
||||
// Text p is created
|
||||
contentEl.createEl("p").setText("Plain text preview of the decrypted message:");
|
||||
// Textarea that contains plain text decrypted
|
||||
let textArea: HTMLTextAreaElement = contentEl.createEl("textarea");
|
||||
|
|
@ -70,7 +78,7 @@ export class DecryptModal extends Modal {
|
|||
// The decrypted text is replaced according to the previous calculations.
|
||||
editor.replaceRange(this.plainText, editorPositionFrom, editorPositionTo)
|
||||
// The for is broken to deliver the result and not continue calculating
|
||||
break;
|
||||
return;
|
||||
}
|
||||
// In case the characters of the previous lines plus the characters of the current line still do not reach the characters of FROM and TO,
|
||||
// it means that this line is not and we continue with the next line
|
||||
|
|
@ -83,6 +91,26 @@ export class DecryptModal extends Modal {
|
|||
new Notice("The encrypted text was not found in the current document")
|
||||
}
|
||||
|
||||
// Organize out text into code elements
|
||||
organizeOutText(outText: string, divCode: any) {
|
||||
// Flag to check if is first line
|
||||
let isFirstLine: boolean = true;
|
||||
// Split lines by return
|
||||
let lines: string[] = outText.split("\n");
|
||||
// Iterate line by line
|
||||
lines.forEach((line) => {
|
||||
// Check if is not a first line
|
||||
if (!isFirstLine) {
|
||||
// Element type br to present a return in preview screen
|
||||
divCode.createEl("br");
|
||||
}
|
||||
// Element type code to present a preview of encrypted text
|
||||
divCode.createEl("code").setText(line);
|
||||
// Mark flag as false
|
||||
isFirstLine = false;
|
||||
});
|
||||
}
|
||||
|
||||
// OnClose Method
|
||||
onClose() {
|
||||
// Get an instance of this Element
|
||||
|
|
|
|||
|
|
@ -85,8 +85,15 @@ export class DecryptPreviewModal extends Modal {
|
|||
let decryptedTextResult: GpgResult = await gpgDecrypt(this.plugin.settings, this.encryptedMessage);
|
||||
// Check if result contains data
|
||||
if (decryptedTextResult.result) {
|
||||
// Extra info in decrypt process
|
||||
let extraInfo: string = "";
|
||||
// In case of any error happend
|
||||
if (decryptedTextResult.error) {
|
||||
// Show extra info in variable
|
||||
extraInfo = decryptedTextResult.error.message;
|
||||
}
|
||||
// Open a new decrypt modal with plain text
|
||||
new DecryptModal(this.app, decryptedTextResult.result.toString().trim(), this.plugin, this.from, this.to).open();
|
||||
new DecryptModal(this.app, decryptedTextResult.result.toString().trim(), extraInfo, this.plugin, this.from, this.to).open();
|
||||
// Close this modal
|
||||
this.close();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,4 +37,11 @@
|
|||
.gpg-plain-text-area {
|
||||
height: 200px;
|
||||
width: 100%;
|
||||
}
|
||||
.gpg-code-sign-ok {
|
||||
background-color: #e3f4e4;
|
||||
color: black;
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
font-size: 0.7em;
|
||||
}
|
||||
Loading…
Reference in a new issue