Skip to content

Commit

Permalink
Resolved the conflict with the HomePage plugin: when popuping verify …
Browse files Browse the repository at this point in the history
…password modal after startup, enter the right password, open a homepage.
  • Loading branch information
qing3962 committed Sep 22, 2023
1 parent 824ca0e commit b7bbe3e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ var PasswordPlugin = class extends import_obsidian2.Plugin {
this.isVerifyPasswordWaitting = false;
this.isVerifyPasswordCorrect = false;
this.lastUnlockOrOpenFileTime = null;
this.startupFile = [];
this.isLayoutReady = true;
this.t = (x, vars) => {
return this.i18n.t(x, vars);
};
Expand Down Expand Up @@ -694,6 +696,9 @@ var PasswordPlugin = class extends import_obsidian2.Plugin {
if (file != null) {
this.autoLockCheck();
if (this.settings.protectEnabled && !this.isVerifyPasswordCorrect && this.isProtectedFile(file)) {
if (this.isLayoutReady && this.isVerifyPasswordWaitting) {
this.startupFile.push(file);
}
this.closeLeave(file);
this.closePasswordProtection(file);
}
Expand Down Expand Up @@ -823,6 +828,15 @@ var PasswordPlugin = class extends import_obsidian2.Plugin {
(0, import_obsidian2.setIcon)(this.passwordRibbonBtn, "lock");
this.passwordRibbonBtn.ariaLabel = this.t("open_password_protection");
new import_obsidian2.Notice(this.t("password_protection_closed"));
if (this.isLayoutReady) {
this.isLayoutReady = false;
for (const file of this.startupFile) {
if (file != null) {
this.openLeave(file);
}
}
this.startupFile = [];
}
}
}).open();
}
Expand Down
16 changes: 15 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export default class PasswordPlugin extends Plugin {
isVerifyPasswordWaitting: boolean = false;
isVerifyPasswordCorrect: boolean = false;
lastUnlockOrOpenFileTime: moment.Moment | null = null;
startupFile: TFile[] = [];
isLayoutReady: boolean = true;

passwordRibbonBtn: HTMLElement;
i18n: I18n;
Expand Down Expand Up @@ -88,7 +90,10 @@ export default class PasswordPlugin extends Plugin {
if (file != null) {
this.autoLockCheck();
if (this.settings.protectEnabled && !this.isVerifyPasswordCorrect && this.isProtectedFile(file)) {
// firstly close the file, then show the password dialog
// firstly cache the file if startuping, close the file, then show the password dialog
if (this.isLayoutReady && this.isVerifyPasswordWaitting) {
this.startupFile.push(file);
}
this.closeLeave(file);
this.closePasswordProtection(file);
}
Expand Down Expand Up @@ -240,6 +245,15 @@ export default class PasswordPlugin extends Plugin {
setIcon(this.passwordRibbonBtn, "lock");
this.passwordRibbonBtn.ariaLabel = this.t("open_password_protection");
new Notice(this.t("password_protection_closed"));
if (this.isLayoutReady) {
this.isLayoutReady = false;
for (const file of this.startupFile) {
if (file != null) {
this.openLeave(file);
}
}
this.startupFile = [];
}
}
}).open();
}
Expand Down

0 comments on commit b7bbe3e

Please sign in to comment.