Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: do not run sync on file picker closed

Abdullah Atta6c4672037c9f
diff --git a/apps/web/src/utils/file-picker.ts b/apps/web/src/utils/file-picker.ts
index fdb9706fd..840d47924 100644
--- a/apps/web/src/utils/file-picker.ts
+++ b/apps/web/src/utils/file-picker.ts
@@ -17,12 +17,15 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+import { PAGE_VISIBILITY_CHANGE } from "./page-visibility";
+
type FilePickerOptions = { acceptedFileTypes: string };
export function showFilePicker({
acceptedFileTypes
}: FilePickerOptions): Promise<File | undefined> {
return new Promise((resolve) => {
+ PAGE_VISIBILITY_CHANGE.ignore = true;
const input = document.createElement("input");
input.setAttribute("type", "file");
input.setAttribute("accept", acceptedFileTypes);
diff --git a/apps/web/src/utils/page-visibility.ts b/apps/web/src/utils/page-visibility.ts
index e3de2cdf0..1512db11e 100644
--- a/apps/web/src/utils/page-visibility.ts
+++ b/apps/web/src/utils/page-visibility.ts
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { debounce } from "@notesnook/common";
+export const PAGE_VISIBILITY_CHANGE = { ignore: false };
function visibilityChange() {
return "msHidden" in document
? "msvisibilityChange"
@@ -58,6 +59,10 @@ export function onPageVisibilityChanged(
document.addEventListener(
visibilityChange(),
debounce((_) => {
+ if (PAGE_VISIBILITY_CHANGE.ignore) {
+ PAGE_VISIBILITY_CHANGE.ignore = false;
+ return;
+ }
handler("visibilitychange", isDocumentHidden());
}, 1000)
);
@@ -66,7 +71,11 @@ export function onPageVisibilityChanged(
"focus",
debounce((_) => {
if (!window.document.hasFocus()) return;
+ if (PAGE_VISIBILITY_CHANGE.ignore) {
+ PAGE_VISIBILITY_CHANGE.ignore = false;
+ return;
+ }
handler("focus", false);
}, 1000)
);
-}
\ No newline at end of file
+}