Skip to content

Commit

Permalink
Merge pull request #126 from meld-cp:dev-file-extensions
Browse files Browse the repository at this point in the history
change encrypted note file extension to .mdenc
  • Loading branch information
meld-cp authored Sep 29, 2023
2 parents fac096b + e3b7e31 commit e3c4ca0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You can install the plugin via the Community Plugins tab within Obsidian by sear
### 2.3.2
- add key-bindable command to toggle reading view for encrypted notes ([#116](https://github.com/meld-cp/obsidian-encrypt/issues/116))
- change to using `.mdenc` file extensions for encrypted notes ([#117](https://github.com/meld-cp/obsidian-encrypt/issues/117))

### 2.3.1
- fix encrypt/decrypt of notes don't update links (#118)
Expand Down
16 changes: 11 additions & 5 deletions src/features/feature-convert-note/FeatureConvertNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import PluginPasswordModal from "src/PluginPasswordModal";
import { IPasswordAndHint, SessionPasswordService } from "src/services/SessionPasswordService";
import { FileDataHelper, JsonFileEncoding } from "src/services/FileDataHelper";
import { Utils } from "src/services/Utils";
import { ENCRYPTED_FILE_EXTENSION } from "src/services/Constants";
import "src/services/Constants";
import { ENCRYPTED_FILE_EXTENSIONS, ENCRYPTED_FILE_EXTENSION_DEFAULT } from "src/services/Constants";

export default class FeatureConvertNote implements IMeldEncryptPluginFeature {

Expand Down Expand Up @@ -41,7 +42,7 @@ export default class FeatureConvertNote implements IMeldEncryptPluginFeature {
}
);
}
if ( file.extension == ENCRYPTED_FILE_EXTENSION ){
if ( ENCRYPTED_FILE_EXTENSIONS.contains( file.extension ) ){
menu.addItem( (item) => {
item
.setTitle('Decrypt note')
Expand Down Expand Up @@ -71,7 +72,7 @@ export default class FeatureConvertNote implements IMeldEncryptPluginFeature {
if ( file == null ){
return false;
}
return file.extension == ENCRYPTED_FILE_EXTENSION;
return ENCRYPTED_FILE_EXTENSIONS.contains( file.extension );
}

private processCommandEncryptNote( file:TFile ){
Expand Down Expand Up @@ -107,7 +108,7 @@ export default class FeatureConvertNote implements IMeldEncryptPluginFeature {
});
}

if ( file?.extension == ENCRYPTED_FILE_EXTENSION ){
if ( file && ENCRYPTED_FILE_EXTENSIONS.contains( file.extension ) ){
this.getPasswordAndDecryptFile( file ).catch( reason => {
if (reason){
new Notice(reason, 10000);
Expand All @@ -130,7 +131,12 @@ export default class FeatureConvertNote implements IMeldEncryptPluginFeature {

const encryptedFileContent = await this.encryptFile(file, pw);

await this.closeUpdateRememberPasswordThenReopen( file, ENCRYPTED_FILE_EXTENSION, encryptedFileContent, pw );
await this.closeUpdateRememberPasswordThenReopen(
file,
ENCRYPTED_FILE_EXTENSION_DEFAULT,
encryptedFileContent,
pw
);

new Notice( '🔐 Note was encrypted 🔐' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { UiHelper } from 'src/services/UiHelper';
import { IFeatureWholeNoteEncryptSettings } from './IFeatureWholeNoteEncryptSettings';
import { ObsidianEx } from 'src/services/ObsidianEx';
import { FileDataHelper, JsonFileEncoding } from 'src/services/FileDataHelper';
import { ENCRYPTED_FILE_EXTENSION } from 'src/services/Constants';
import 'src/services/Constants';
import { ENCRYPTED_FILE_EXTENSIONS } from 'src/services/Constants';

enum EncryptedFileContentViewStateEnum{
init,
Expand Down Expand Up @@ -573,8 +574,7 @@ export class EncryptedFileContentView extends TextFileView {

// important
canAcceptExtension(extension: string): boolean {
//console.debug('EncryptedFileContentView.canAcceptExtension', {extension});
return extension == ENCRYPTED_FILE_EXTENSION;
return ENCRYPTED_FILE_EXTENSIONS.contains( extension );
}

// important
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { IMeldEncryptPluginFeature } from "../IMeldEncryptPluginFeature";
import MeldEncrypt from "../../main";
import { IMeldEncryptPluginSettings } from "../../settings/MeldEncryptPluginSettings";
import { IFeatureWholeNoteEncryptSettings } from "./IFeatureWholeNoteEncryptSettings";
import { ENCRYPTED_FILE_EXTENSION } from "src/services/Constants";
import "src/services/Constants";
import { ENCRYPTED_FILE_EXTENSIONS, ENCRYPTED_FILE_EXTENSION_DEFAULT } from "src/services/Constants";

export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeature {

Expand All @@ -24,7 +25,10 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur
(leaf) => new EncryptedFileContentView(leaf, this.settings )
);

this.plugin.registerExtensions([ENCRYPTED_FILE_EXTENSION], VIEW_TYPE_ENCRYPTED_FILE_CONTENT);
this.plugin.registerExtensions(
ENCRYPTED_FILE_EXTENSIONS,
VIEW_TYPE_ENCRYPTED_FILE_CONTENT
);

this.plugin.addCommand({
id: 'meld-encrypt-create-new-note',
Expand Down Expand Up @@ -53,7 +57,7 @@ export default class FeatureWholeNoteEncrypt implements IMeldEncryptPluginFeatur

private processCreateNewEncryptedNoteCommand() {
try{
const newFilename = moment().format('[Untitled] YYYYMMDD hhmmss[.encrypted]');
const newFilename = moment().format( `[Untitled] YYYYMMDD hhmmss[.${ENCRYPTED_FILE_EXTENSION_DEFAULT}]`);

let newFileFolder : TFolder;
const activeFile = this.plugin.app.workspace.getActiveFile();
Expand Down
11 changes: 10 additions & 1 deletion src/services/Constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
export const ENCRYPTED_FILE_EXTENSION = 'encrypted';
const ENCRYPTED_FILE_EXTENSION_ENCRYPTED = 'encrypted';
const ENCRYPTED_FILE_EXTENSION_MDENC = 'mdenc';

export const ENCRYPTED_FILE_EXTENSION_DEFAULT = ENCRYPTED_FILE_EXTENSION_MDENC;


export const ENCRYPTED_FILE_EXTENSIONS = [
ENCRYPTED_FILE_EXTENSION_MDENC,
ENCRYPTED_FILE_EXTENSION_ENCRYPTED
];

0 comments on commit e3c4ca0

Please sign in to comment.