Skip to content

Commit

Permalink
fix bug: If the AutoLock interval is set in mobile device, when the O…
Browse files Browse the repository at this point in the history
…bsidian is brought to the backend, after a while, it is brought to the frontend again, the Autolock protection action don't valid.
  • Loading branch information
qing3962 committed Aug 20, 2023
1 parent 4991fce commit 49f1d62
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
9 changes: 4 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ var zh_cn_default = {
auto_lock_interval_desc: "\u4ECE\u4E0A\u6B21\u5173\u95ED\u5BC6\u7801\u4FDD\u62A4\u6216\u4E0A\u6B21\u6253\u5F00\u4E00\u4E2A\u53D7\u4FDD\u62A4\u7684\u6587\u4EF6\u5F00\u59CB\u8BA1\u7B97\uFF0C0 \u4EE3\u8868\u4E0D\u81EA\u52A8\u6253\u5F00\u5BC6\u7801\u4FDD\u62A4, \u5355\u4F4D\uFF1A\u5206\u949F",
forbid_close_verify_modal_name: "\u7981\u6B62\u5173\u95ED\u5BC6\u7801\u9A8C\u8BC1\u6846 (\u5F53\u5BC6\u7801\u4E0D\u6B63\u786E)",
forbid_close_verify_modal_desc: "\u8FD9\u5C06\u4FDD\u62A4\u66F4\u591A\u9690\u79C1\uFF0C\u4F46\u662F\u5982\u679C\u4F60\u5FD8\u8BB0\u4E86\u5BC6\u7801\uFF0C\u4F60\u53EF\u80FD\u5C06\u65E0\u6CD5\u8FDB\u5165Obsidian.",
before_open_protection: "\u6253\u5F00\u5BC6\u7801\u4FDD\u62A4\u5F00\u5173\u540E\uFF0C\u4E0A\u9762\u7684\u8BBE\u7F6E\u5C06\u4E0D\u53EF\u4FEE\u6539."
before_open_protection: "\u6253\u5F00\u4E0B\u9762\u7684\u5BC6\u7801\u4FDD\u62A4\u5F00\u5173\u540E\uFF0C\u4E0A\u9762\u7684\u8BBE\u7F6E\u5C06\u4E0D\u53EF\u4FEE\u6539."
};

// langs/zh_tw.json
Expand Down Expand Up @@ -596,7 +596,7 @@ var zh_tw_default = {
auto_lock_interval_desc: "\u5F9E\u4E0A\u6B21\u95DC\u9589\u5BC6\u78BC\u4FDD\u8B77\u6216\u4E0A\u6B21\u6253\u958B\u4E00\u500B\u53D7\u4FDD\u8B77\u7684\u6587\u4EF6\u958B\u59CB\u8A08\u7B97\uFF0C0 \u8868\u793A\u4E0D\u81EA\u52D5\u6253\u958B\u5BC6\u78BC\u4FDD\u8B77\uFF0C\u55AE\u4F4D\uFF1A\u5206\u9418",
forbid_close_verify_modal_name: "\u7981\u6B62\u95DC\u9589\u5BC6\u78BC\u9A57\u8B49\u6846 (\u5F53\u5BC6\u78BC\u4E0D\u6B63\u78BA)",
forbid_close_verify_modal_desc: "\u9019\u5C07\u4FDD\u8B77\u66F4\u591A\u96B1\u79C1\uFF0C\u4F46\u662F\u5982\u679C\u4F60\u5FD8\u8A18\u4E86\u5BC6\u78BC\uFF0C\u4F60\u53EF\u80FD\u5C06\u7121\u6CD5\u9032\u5165Obsidian.",
before_open_protection: "\u6253\u958B\u5BC6\u78BC\u4FDD\u8B77\u958B\u95DC\u540E\uFF0C\u4E0A\u9762\u7684\u8A2D\u7F6E\u5C07\u4E0D\u53EF\u4FEE\u6539."
before_open_protection: "\u6253\u958B\u4E0B\u9762\u7684\u5BC6\u78BC\u4FDD\u8B77\u958B\u95DC\u540E\uFF0C\u4E0A\u9762\u7684\u8A2D\u7F6E\u5C07\u4E0D\u53EF\u4FEE\u6539."
};

// langs/index.ts
Expand Down Expand Up @@ -692,6 +692,7 @@ var PasswordPlugin = class extends import_obsidian2.Plugin {
});
this.registerEvent(this.app.workspace.on("file-open", (file) => {
if (file != null) {
this.autoLockCheck();
if (this.settings.protectEnabled && !this.isVerifyPasswordCorrect && this.isProtectedFile(file)) {
this.closeLeave(file);
this.closePasswordProtection(file);
Expand All @@ -712,7 +713,6 @@ var PasswordPlugin = class extends import_obsidian2.Plugin {
let curTime = (0, import_obsidian2.moment)();
if (curTime.diff(this.lastUnlockOrOpenFileTime, "minute") >= this.settings.autoLockInterval) {
this.isVerifyPasswordCorrect = false;
this.lastUnlockOrOpenFileTime = curTime;
}
}
}
Expand Down Expand Up @@ -912,7 +912,6 @@ var PasswordSettingTab = class extends import_obsidian2.PluginSettingTab {
if (this.plugin.settings.protectEnabled) {
this.plugin.saveSettings();
this.plugin.openPasswordProtection();
this.plugin.lastUnlockOrOpenFileTime = (0, import_obsidian2.moment)();
}
this.display();
}).open();
Expand Down Expand Up @@ -1088,8 +1087,8 @@ var VerifyPasswordModal = class extends import_obsidian2.Modal {
if (!goodToGo) {
return;
}
this.plugin.isVerifyPasswordCorrect = true;
this.plugin.lastUnlockOrOpenFileTime = (0, import_obsidian2.moment)();
this.plugin.isVerifyPasswordCorrect = true;
this.close();
};
pwInputEl.addEventListener("keypress", (event) => {
Expand Down
6 changes: 3 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ export default class PasswordPlugin extends Plugin {
// when the file opened, check if it need to be protected, if so, close it, and show the password dialog
this.registerEvent(this.app.workspace.on('file-open', (file: TFile | null) => {
if (file != null) {
this.autoLockCheck();
if (this.settings.protectEnabled && !this.isVerifyPasswordCorrect && this.isProtectedFile(file)) {
// firstly close the file, then show the password dialog
this.closeLeave(file);
this.closePasswordProtection(file);
}
// update the time of last open file, the file may be protected and may be not.
if (this.settings.protectEnabled && this.isVerifyPasswordCorrect) {
this.lastUnlockOrOpenFileTime = moment();
}
Expand All @@ -111,7 +113,6 @@ export default class PasswordPlugin extends Plugin {
let curTime = moment();
if (curTime.diff(this.lastUnlockOrOpenFileTime, 'minute') >= this.settings.autoLockInterval) {
this.isVerifyPasswordCorrect = false;
this.lastUnlockOrOpenFileTime = curTime;
}
}
}
Expand Down Expand Up @@ -369,7 +370,6 @@ class PasswordSettingTab extends PluginSettingTab {
if (this.plugin.settings.protectEnabled) {
this.plugin.saveSettings();
this.plugin.openPasswordProtection();
this.plugin.lastUnlockOrOpenFileTime = moment();
}
this.display();
}).open();
Expand Down Expand Up @@ -622,8 +622,8 @@ class VerifyPasswordModal extends Modal {
}

// if all checks pass, save to settings
this.plugin.isVerifyPasswordCorrect = true;
this.plugin.lastUnlockOrOpenFileTime = moment();
this.plugin.isVerifyPasswordCorrect = true;
this.close();
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "password-protection",
"name": "Password Protection",
"version": "1.1.13",
"version": "1.1.14",
"minAppVersion": "0.15.0",
"description": "Protect your private notes and diary with a password, no encrypt, no decrypt.",
"author": "Qing Li",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "password-protection",
"version": "1.1.13",
"version": "1.1.14",
"description": "Protect your private notes and diary with a password, no encrypt, no decrypt.",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 49f1d62

Please sign in to comment.