-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from meld-cp/dev
Merge with dev
- Loading branch information
Showing
26 changed files
with
924 additions
and
537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ package-lock.json | |
dist | ||
*.map | ||
test-vault | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import esbuild from "esbuild"; | ||
import process from "process"; | ||
import copyStaticFiles from 'esbuild-copy-static-files'; | ||
|
||
const prod = (process.argv[2] === 'production'); | ||
|
||
esbuild.build({ | ||
entryPoints: ['src/tools/offline-decrypt.ts'], | ||
bundle: true, | ||
format: 'iife', | ||
watch: !prod, | ||
target: 'es2018', | ||
logLevel: "info", | ||
sourcemap: prod ? false : 'inline', | ||
treeShaking: prod, | ||
minify: prod, | ||
outfile: './tools/offline-decrypt.js', | ||
plugins:[ | ||
copyStaticFiles({ | ||
src: './src/tools/decrypt.html', | ||
dest: './tools/decrypt.html', | ||
}), | ||
] | ||
}).catch(() => process.exit(1)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
import { App, Modal, Setting, TextComponent } from 'obsidian'; | ||
import { UiHelper } from 'src/services/UiHelper'; | ||
import { IPasswordAndHint } from './services/SessionPasswordService'; | ||
|
||
export default class PluginPasswordModal extends Modal { | ||
|
||
// input | ||
private title: string; | ||
private defaultPassword: IPasswordAndHint | null; | ||
//private defaultHint?: string | null = null; | ||
private confirmPassword: boolean; | ||
private isEncrypting: boolean; | ||
|
||
// output | ||
public resultConfirmed = false; | ||
public resultPassword: IPasswordAndHint; | ||
|
||
constructor( | ||
app: App, | ||
title: string, | ||
isEncrypting:boolean, | ||
confirmPassword: boolean, | ||
defaultPassword: IPasswordAndHint | null, | ||
) { | ||
super(app); | ||
this.title = title; | ||
this.defaultPassword = defaultPassword; | ||
this.confirmPassword = confirmPassword; | ||
this.isEncrypting = isEncrypting; | ||
} | ||
|
||
onOpen() { | ||
const { contentEl } = this; | ||
|
||
contentEl.empty(); | ||
|
||
this.invalidate(); | ||
|
||
let password = this.defaultPassword?.password ?? ''; | ||
let confirmPass = ''; | ||
let hint = this.defaultPassword?.hint ?? ''; | ||
|
||
new Setting(contentEl).setHeading().setName( this.title ); | ||
|
||
/* Main password input*/ | ||
|
||
UiHelper.buildPasswordSetting({ | ||
container: contentEl, | ||
name: 'Password:', | ||
placeholder: this.isEncrypting ? '' : `Hint: ${hint}`, | ||
initialValue: password, | ||
autoFocus: password == '', | ||
onChangeCallback: (value) => { | ||
password = value; | ||
this.invalidate(); | ||
}, | ||
onEnterCallback: (value) =>{ | ||
password = value; | ||
this.invalidate(); | ||
|
||
if (password.length > 0){ | ||
if (sConfirmPassword.settingEl.isShown()){ | ||
//tcConfirmPassword.inputEl.focus(); | ||
const elInp = sConfirmPassword.components.find( (bc) => bc instanceof TextComponent ); | ||
if ( elInp instanceof TextComponent ){ | ||
elInp.inputEl.focus(); | ||
} | ||
|
||
}else if (sHint.settingEl.isShown()){ | ||
//tcHint.inputEl.focus(); | ||
const elInp = sHint.components.find( (bc) => bc instanceof TextComponent ); | ||
if ( elInp instanceof TextComponent ){ | ||
elInp.inputEl.focus(); | ||
} | ||
}else if( validate() ){ | ||
this.close(); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
/* End Main password input row */ | ||
|
||
/* Confirm password input row */ | ||
const sConfirmPassword = UiHelper.buildPasswordSetting({ | ||
container : contentEl, | ||
name: 'Confirm Password:', | ||
autoFocus: password != '', | ||
onChangeCallback: (value) => { | ||
confirmPass = value; | ||
this.invalidate(); | ||
}, | ||
onEnterCallback: (value) =>{ | ||
confirmPass = value; | ||
this.invalidate(); | ||
if (confirmPass.length > 0){ | ||
if ( validate() ){ | ||
if ( sHint.settingEl.isShown() ){ | ||
//tcHint.inputEl.focus(); | ||
const elInp = sHint.components.find( (bc) => bc instanceof TextComponent ); | ||
if ( elInp instanceof TextComponent ){ | ||
elInp.inputEl.focus(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
if ( !this.confirmPassword ){ | ||
sConfirmPassword.settingEl.hide(); | ||
} | ||
|
||
/* End Confirm password input row */ | ||
|
||
/* Hint input row */ | ||
const sHint = new Setting(contentEl) | ||
.setName('Optional Password Hint') | ||
.addText( tc=>{ | ||
//tcHint = tc; | ||
tc.inputEl.placeholder = `Password Hint`; | ||
tc.setValue(hint); | ||
tc.onChange( v=> hint = v ); | ||
tc.inputEl.on('keypress', '*', (ev, target) => { | ||
if ( | ||
ev.key == 'Enter' | ||
&& target instanceof HTMLInputElement | ||
&& target.value.length > 0 | ||
) { | ||
ev.preventDefault(); | ||
if ( validate() ){ | ||
this.close(); | ||
} | ||
} | ||
}); | ||
}) | ||
; | ||
if (!this.isEncrypting){ | ||
sHint.settingEl.hide(); | ||
} | ||
|
||
/* END Hint text row */ | ||
|
||
new Setting(contentEl).addButton( cb=>{ | ||
cb | ||
.setButtonText('Confirm') | ||
.onClick( evt =>{ | ||
if (validate()){ | ||
this.close(); | ||
} | ||
}) | ||
; | ||
}); | ||
|
||
const validate = () : boolean => { | ||
this.invalidate(); | ||
|
||
sConfirmPassword.setDesc(''); | ||
|
||
if ( this.confirmPassword ){ | ||
if (password != confirmPass){ | ||
// passwords don't match | ||
sConfirmPassword.setDesc('Passwords don\'t match'); | ||
return false; | ||
} | ||
} | ||
|
||
this.resultConfirmed = true; | ||
this.resultPassword = { password, hint }; | ||
|
||
return true; | ||
} | ||
|
||
} | ||
|
||
openAsync(): Promise<IPasswordAndHint> { | ||
return new Promise<IPasswordAndHint>( (resolve, reject) =>{ | ||
|
||
this.onClose = () =>{ | ||
if (this.resultConfirmed == true){ | ||
resolve( this.resultPassword ); | ||
}else{ | ||
reject(); | ||
} | ||
} | ||
|
||
this.open(); | ||
|
||
} ); | ||
} | ||
|
||
private invalidate(){ | ||
this.resultConfirmed = false; | ||
this.resultPassword = { password: '', hint: '' }; | ||
} | ||
|
||
} |
Oops, something went wrong.