Skip to content

Commit 5dbd3cd

Browse files
committed
fix: obscure password for ssh passphrase prompt
close #845
1 parent 2340576 commit 5dbd3cd

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/gitManager/simpleGit.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export class SimpleGit extends GitManager {
197197
}
198198
const response = await new GeneralModal(this.plugin, {
199199
allowEmpty: true,
200+
obscure: true,
200201
placeholder:
201202
data.length > 60
202203
? "Enter a response to the message."

src/ui/modals/generalModal.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ export interface OptionalGeneralModalConfig {
77
allowEmpty?: boolean;
88
onlySelection?: boolean;
99
initialValue?: string;
10+
obscure?: boolean;
1011
}
1112
interface GeneralModalConfig {
1213
options: string[];
1314
placeholder: string;
1415
allowEmpty: boolean;
1516
onlySelection: boolean;
1617
initialValue?: string;
18+
obscure: boolean;
1719
}
1820

1921
const generalModalConfigDefaults: GeneralModalConfig = {
@@ -22,6 +24,7 @@ const generalModalConfigDefaults: GeneralModalConfig = {
2224
allowEmpty: false,
2325
onlySelection: false,
2426
initialValue: undefined,
27+
obscure: false,
2528
};
2629

2730
export class GeneralModal extends SuggestModal<string> {
@@ -34,6 +37,29 @@ export class GeneralModal extends SuggestModal<string> {
3437
super(plugin.app);
3538
this.config = { ...generalModalConfigDefaults, ...config };
3639
this.setPlaceholder(this.config.placeholder);
40+
if (this.config.obscure) {
41+
this.inputEl.type = "password";
42+
const promptContainer = this.containerEl.querySelector(
43+
".prompt-input-container"
44+
)!;
45+
promptContainer.addClass("git-obscure-prompt");
46+
promptContainer.setAttr("git-is-obscured", "true");
47+
const obscureSwitchButton = promptContainer?.createDiv({
48+
cls: "search-input-clear-button",
49+
});
50+
obscureSwitchButton.style.marginRight = "32px";
51+
obscureSwitchButton.id = "git-show-password";
52+
obscureSwitchButton.addEventListener("click", () => {
53+
const isObscured = promptContainer.getAttr("git-is-obscured");
54+
if (isObscured === "true") {
55+
this.inputEl.type = "text";
56+
promptContainer.setAttr("git-is-obscured", "false");
57+
} else {
58+
this.inputEl.type = "password";
59+
promptContainer.setAttr("git-is-obscured", "true");
60+
}
61+
});
62+
}
3763
}
3864

3965
openAndGetResult(): Promise<string> {
@@ -64,7 +90,11 @@ export class GeneralModal extends SuggestModal<string> {
6490
}
6591

6692
renderSuggestion(value: string, el: HTMLElement): void {
67-
el.setText(value);
93+
if (this.config.obscure) {
94+
el.hide();
95+
} else {
96+
el.setText(value);
97+
}
6898
}
6999

70100
onChooseSuggestion(value: string, _: MouseEvent | KeyboardEvent) {

styles.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,3 +582,11 @@
582582
position: relative;
583583
height: 100%;
584584
}
585+
586+
.git-obscure-prompt[git-is-obscured="true"] #git-show-password:after {
587+
-webkit-mask-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-eye"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"></path><circle cx="12" cy="12" r="3"></circle></svg>');
588+
}
589+
590+
.git-obscure-prompt[git-is-obscured="false"] #git-show-password:after {
591+
-webkit-mask-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-eye-off"><path d="M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49"></path><path d="M14.084 14.158a3 3 0 0 1-4.242-4.242"></path><path d="M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143"></path><path d="m2 2 20 20"></path></svg>');
592+
}

0 commit comments

Comments
 (0)