From 2ba638b1231a7661a2be5679c8dc494b11f58378 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 25 Apr 2023 14:47:13 +0500 Subject: [PATCH 01/13] web: fix font family on input field labels --- apps/web/src/components/field/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/web/src/components/field/index.js b/apps/web/src/components/field/index.js index be2839154..97ea3174f 100644 --- a/apps/web/src/components/field/index.js +++ b/apps/web/src/components/field/index.js @@ -92,6 +92,7 @@ function Field(props) { sx={{ fontSize: "subtitle", fontWeight: "bold", + fontFamily: "body", color: "icon", flexDirection: "column", ...styles.label From 21c896014604b2357e9a7710051c97857a6d33a1 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Wed, 26 Apr 2023 11:37:56 +0500 Subject: [PATCH 02/13] web: fix "Unauthorized" error on subscription cancel --- packages/core/api/subscriptions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/api/subscriptions.js b/packages/core/api/subscriptions.js index 682555ebc..8aa15cf39 100644 --- a/packages/core/api/subscriptions.js +++ b/packages/core/api/subscriptions.js @@ -29,13 +29,13 @@ export default class Subscriptions { } async cancel() { - const token = this._tokenManager.getAccessToken(); + const token = await this._tokenManager.getAccessToken(); if (!token) return; await http.delete(`${hosts.SUBSCRIPTIONS_HOST}/subscriptions`, token); } async updateUrl() { - const token = this._tokenManager.getAccessToken(); + const token = await this._tokenManager.getAccessToken(); if (!token) return; return await http.get( `${hosts.SUBSCRIPTIONS_HOST}/subscriptions/update_url`, From a28beb62c66f60f23e458fab09f3a4f2a9e90c77 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 25 Apr 2023 11:07:50 +0500 Subject: [PATCH 03/13] core: deep clone note when duplicating --- packages/core/models/note.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/models/note.js b/packages/core/models/note.js index 3148e36d3..c1f79e62a 100644 --- a/packages/core/models/note.js +++ b/packages/core/models/note.js @@ -24,6 +24,7 @@ import { getContentFromData } from "../content-types"; import { CHECK_IDS, checkIsUserPremium } from "../common"; import { addItem, deleteItem } from "../utils/array"; import { formatDate } from "../utils/date"; +import qclone from "qclone"; export default class Note { /** @@ -135,7 +136,7 @@ export default class Note { async duplicate() { const content = await this._db.content.raw(this._note.contentId); return await this._db.notes.add({ - ...this._note, + ...qclone(this._note), id: undefined, content: { type: content.type, From 4875cfa1087253567f33af82f461da7ca52ab1b6 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 25 Apr 2023 11:12:34 +0500 Subject: [PATCH 04/13] core: duplicate note without content --- packages/core/models/note.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/core/models/note.js b/packages/core/models/note.js index c1f79e62a..d33a4001f 100644 --- a/packages/core/models/note.js +++ b/packages/core/models/note.js @@ -138,10 +138,12 @@ export default class Note { return await this._db.notes.add({ ...qclone(this._note), id: undefined, - content: { - type: content.type, - data: content.data - }, + content: content + ? { + type: content.type, + data: content.data + } + : undefined, readonly: false, favorite: false, pinned: false, From 69bb0e3656360f8e3337477874b89125d83d8076 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 26 Apr 2023 10:08:20 +0500 Subject: [PATCH 05/13] editor: fix toolbar dropdown buttons size on mobile --- packages/editor/src/toolbar/components/dropdown.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/editor/src/toolbar/components/dropdown.tsx b/packages/editor/src/toolbar/components/dropdown.tsx index da7134b6a..1657f0719 100644 --- a/packages/editor/src/toolbar/components/dropdown.tsx +++ b/packages/editor/src/toolbar/components/dropdown.tsx @@ -64,6 +64,7 @@ export function Dropdown(props: DropdownProps) { m: 0, bg: isPopupOpen ? "hover" : "transparent", mr: 1, + flexShrink: 0, display: "flex", alignItems: "center", ":hover": { bg: "hover" }, @@ -75,7 +76,9 @@ export function Dropdown(props: DropdownProps) { onMouseDown={(e) => e.preventDefault()} > {typeof selectedItem === "string" ? ( - + {selectedItem} ) : ( From 3d7c1fa1e71eb9084ded191f1446f4187d24f622 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 25 Apr 2023 11:17:40 +0500 Subject: [PATCH 06/13] mobile: fix configure toolbar sheet close with swipe --- apps/mobile/app/components/sheets/sort/index.js | 2 -- .../app/screens/settings/editor/tool-sheet.tsx | 13 ++++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/apps/mobile/app/components/sheets/sort/index.js b/apps/mobile/app/components/sheets/sort/index.js index 766b6418e..1e26410da 100644 --- a/apps/mobile/app/components/sheets/sort/index.js +++ b/apps/mobile/app/components/sheets/sort/index.js @@ -25,7 +25,6 @@ import Navigation from "../../../services/navigation"; import { useThemeStore } from "../../../stores/use-theme-store"; import { GROUP, SORT } from "../../../utils/constants"; import { refreshNotesPage } from "../../../utils/events"; -import layoutmanager from "../../../utils/layout-manager"; import { SIZE } from "../../../utils/size"; import { Button } from "../../ui/button"; import Seperator from "../../ui/seperator"; @@ -39,7 +38,6 @@ const Sort = ({ type, screen }) => { const updateGroupOptions = async (_groupOptions) => { await db.settings.setGroupOptions(type, _groupOptions); - layoutmanager.withSpringAnimation(600); setGroupOptions(_groupOptions); setTimeout(() => { if (screen !== "TopicSheet") Navigation.queueRoutesForUpdate(screen); diff --git a/apps/mobile/app/screens/settings/editor/tool-sheet.tsx b/apps/mobile/app/screens/settings/editor/tool-sheet.tsx index acc58f7d6..4e66fd419 100644 --- a/apps/mobile/app/screens/settings/editor/tool-sheet.tsx +++ b/apps/mobile/app/screens/settings/editor/tool-sheet.tsx @@ -20,8 +20,6 @@ along with this program. If not, see . import { ToolId } from "@notesnook/editor/dist/toolbar"; import React, { RefObject } from "react"; import { View } from "react-native"; -import ActionSheet from "react-native-actions-sheet"; -import { ScrollView } from "react-native-gesture-handler"; import { PressableButton } from "../../../components/ui/pressable"; import { SvgView } from "../../../components/ui/svg"; import Paragraph from "../../../components/ui/typography/paragraph"; @@ -34,13 +32,14 @@ import { getToolIcon, getUngroupedTools } from "./toolbar-definition"; +import { ActionSheetRef, ScrollView } from "react-native-actions-sheet"; export default function ToolSheet({ group, fwdRef }: { group: DraggableItem; - fwdRef: RefObject; + fwdRef: RefObject; }) { const colors = useThemeStore((state) => state.colors); const data = useDragState((state) => state.data); @@ -50,6 +49,7 @@ export default function ToolSheet({ (item: ToolId) => { const tool = findToolById(item); const iconSvgString = tool ? getToolIcon(tool.icon as ToolId) : null; + if (item === "none") return; return ( - { - fwdRef.current?.handleChildScrollEnd(); - }} - nestedScrollEnabled={true} - > + {!ungrouped || ungrouped.length === 0 ? ( Date: Tue, 25 Apr 2023 15:19:49 +0500 Subject: [PATCH 07/13] mobile: fix note options ui --- apps/mobile/app/components/properties/items.js | 12 ++++-------- apps/mobile/app/hooks/use-actions.js | 4 ++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/mobile/app/components/properties/items.js b/apps/mobile/app/components/properties/items.js index ecc4af752..1c8ab6e4e 100644 --- a/apps/mobile/app/components/properties/items.js +++ b/apps/mobile/app/components/properties/items.js @@ -116,11 +116,11 @@ export const Items = ({ item, buttons, close }) => { key={item.id} testID={"icon-" + item.id} customStyle={{ - alignItems: "center", + alignSelf: "flex-start", width: topBarItemWidth, - marginBottom: 10, marginRight: isLast ? 0 : 10, - backgroundColor: "transparent" + backgroundColor: "transparent", + paddingHorizontal: 0 }} > { /> - + {item.title} diff --git a/apps/mobile/app/hooks/use-actions.js b/apps/mobile/app/hooks/use-actions.js index 3c2528b19..80da7c661 100644 --- a/apps/mobile/app/hooks/use-actions.js +++ b/apps/mobile/app/hooks/use-actions.js @@ -613,7 +613,7 @@ export const useActions = ({ close = () => null, item }) => { }, { id: "pin", - title: item.pinned ? "Unpin" : "Pin", + title: "Pin", icon: item.pinned ? "pin-off-outline" : "pin-outline", func: pinItem, close: false, @@ -623,7 +623,7 @@ export const useActions = ({ close = () => null, item }) => { }, { id: "favorite", - title: !item.favorite ? "Favorite" : "Unfavorite", + title: "Favorite", icon: item.favorite ? "star-off" : "star-outline", func: addToFavorites, close: false, From 152fee2c2978de693a5f0ac496ec40e0585c11bb Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Tue, 25 Apr 2023 19:52:04 +0500 Subject: [PATCH 08/13] mobile: reload editor if rendered view lost --- apps/mobile/app/screens/editor/tiptap/use-editor.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts index 3cb82af4f..c2cb56604 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -580,22 +580,21 @@ export const useEditor = ( const onReady = useCallback(async () => { if (!(await isEditorLoaded(editorRef, sessionIdRef.current))) { - overlay(true); - setLoading(true); + eSendEvent("webview_reset"); } else { isDefaultEditor && restoreEditorState(); } - }, [overlay, isDefaultEditor, restoreEditorState]); + }, [isDefaultEditor, restoreEditorState]); useEffect(() => { state.current.saveCount = 0; - async () => { + (async () => { await commands.setSessionId(sessionIdRef.current); if (sessionIdRef.current) { if (!state.current?.ready) return; await onReady(); } - }; + })(); }, [sessionId, loading, commands, onReady]); const onLoad = useCallback(async () => { From 46e03dd248a84e4e09d605d5484beac4a10b09b5 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 26 Apr 2023 08:20:36 +0500 Subject: [PATCH 09/13] mobile: only show app lock for main activity --- apps/mobile/app/components/launcher/index.js | 6 ++++++ .../com/streetwriters/notesnook/RCTNNativeModule.java | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/apps/mobile/app/components/launcher/index.js b/apps/mobile/app/components/launcher/index.js index a6a0fc007..a3a4a349f 100644 --- a/apps/mobile/app/components/launcher/index.js +++ b/apps/mobile/app/components/launcher/index.js @@ -37,6 +37,7 @@ import { useNoteStore } from "../../stores/use-notes-store"; import { useSettingStore } from "../../stores/use-setting-store"; import { useThemeStore } from "../../stores/use-theme-store"; import { useUserStore } from "../../stores/use-user-store"; +import { AndroidModule } from "../../utils"; import { eOpenAnnouncementDialog } from "../../utils/events"; import { getGithubVersion } from "../../utils/github-version"; import { SIZE } from "../../utils/size"; @@ -192,6 +193,11 @@ const Launcher = React.memo( const onUnlockBiometrics = useCallback(async () => { if (!(await BiometricService.isBiometryAvailable())) return; + if (Platform.OS === "android") { + const activityName = await AndroidModule.getActivityName(); + if (activityName !== "MainActivity") return; + } + let verified = await BiometricService.validateUser( "Unlock to access your notes", "" diff --git a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.java b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.java index ad980bd26..16709386d 100644 --- a/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.java +++ b/apps/mobile/native/android/app/src/main/java/com/streetwriters/notesnook/RCTNNativeModule.java @@ -4,6 +4,7 @@ package com.streetwriters.notesnook; import android.graphics.Color; import android.view.WindowManager; +import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactApplicationContext; @@ -36,6 +37,16 @@ public class RCTNNativeModule extends ReactContextBaseJavaModule { } } + @ReactMethod + public void getActivityName(Promise promise) { + try { + promise.resolve(getCurrentActivity().getClass().getSimpleName()); + } catch (Exception e) { + promise.resolve(null); + } + } + + @ReactMethod public void setSecureMode(final boolean mode) { From 39d74e80a90f52792c2366609ccc837bee91ce52 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 26 Apr 2023 08:21:10 +0500 Subject: [PATCH 10/13] mobile: ensure that overlay gets hidden when entering foreground --- apps/mobile/app/hooks/use-app-events.js | 2 +- apps/mobile/app/screens/editor/tiptap/use-editor.ts | 3 ++- apps/mobile/app/screens/editor/wrapper.js | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/mobile/app/hooks/use-app-events.js b/apps/mobile/app/hooks/use-app-events.js index c580168a7..7f7158e20 100644 --- a/apps/mobile/app/hooks/use-app-events.js +++ b/apps/mobile/app/hooks/use-app-events.js @@ -571,8 +571,8 @@ export const useAppEvents = () => { if (notesAddedFromIntent || shareExtensionOpened) { let id = useEditorStore.getState().currentEditingNote; let note = id && db.notes.note(id).data; - eSendEvent("loadingNote", note); eSendEvent("webview_reset"); + setTimeout(() => eSendEvent("loadingNote", note), 1); MMKV.removeItem("shareExtensionOpened"); } } catch (e) { diff --git a/apps/mobile/app/screens/editor/tiptap/use-editor.ts b/apps/mobile/app/screens/editor/tiptap/use-editor.ts index c2cb56604..9e31d3692 100644 --- a/apps/mobile/app/screens/editor/tiptap/use-editor.ts +++ b/apps/mobile/app/screens/editor/tiptap/use-editor.ts @@ -635,6 +635,7 @@ export const useEditor = ( saveContent, onContentChanged, editorId: editorId, - markImageLoaded + markImageLoaded, + overlay }; }; diff --git a/apps/mobile/app/screens/editor/wrapper.js b/apps/mobile/app/screens/editor/wrapper.js index 6b30acc11..b2671720a 100644 --- a/apps/mobile/app/screens/editor/wrapper.js +++ b/apps/mobile/app/screens/editor/wrapper.js @@ -51,6 +51,7 @@ export const EditorWrapper = ({ width }) => { if (editorState().movedAway) return; if (state === "active") { editorController.current.onReady(); + editorController.current.overlay(false); } }; From 536dead44ddbe3d7a65da3e43fb3aa3fe44b59ee Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 26 Apr 2023 08:53:27 +0500 Subject: [PATCH 11/13] mobile: always load notes on init --- apps/mobile/app/services/notifications.ts | 5 +++-- apps/mobile/share/store.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/mobile/app/services/notifications.ts b/apps/mobile/app/services/notifications.ts index c73d903f8..ced4f0177 100644 --- a/apps/mobile/app/services/notifications.ts +++ b/apps/mobile/app/services/notifications.ts @@ -86,8 +86,9 @@ async function getNextMonthlyReminderDate( } async function initDatabase(notes = true) { - if (db.isInitialized) return; - await db.initCollections(); + if (!db.isInitialized) { + await db.initCollections(); + } if (notes) { await db.notes?.init(); } diff --git a/apps/mobile/share/store.js b/apps/mobile/share/store.js index 395b416b3..1b95f9e86 100644 --- a/apps/mobile/share/store.js +++ b/apps/mobile/share/store.js @@ -31,8 +31,8 @@ export async function initDatabase() { if (!db.isInitialized) { // Only load collections in database. await db.initCollections(); - await db.notes.init(); } + await db.notes.init(); } const StorageKeys = { From 3621f95dbc851000b8b8306d296045f1b3532288 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 26 Apr 2023 09:13:00 +0500 Subject: [PATCH 12/13] web: obfuscate short emails --- apps/web/src/views/auth.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/web/src/views/auth.tsx b/apps/web/src/views/auth.tsx index 9a3a83d2b..7e2467d96 100644 --- a/apps/web/src/views/auth.tsx +++ b/apps/web/src/views/auth.tsx @@ -1019,13 +1019,14 @@ function openURL(url: string, force?: boolean) { function maskEmail(email: string) { if (!email) return ""; - const [username, domain] = email.split("@"); - const maskChars = "*".repeat( - username.substring(2, username.length - 2).length - ); - return `${username.substring(0, 2)}${maskChars}${username.substring( - username.length - 2 - )}@${domain}`; + const [username, provider] = email.split("@"); + if (username.length === 1) return `****@${provider}`; + return email.replace(/(.{1})(.*)(?=@)/, function (gp1, gp2, gp3) { + for (let i = 0; i < gp3.length; i++) { + gp2 += "*"; + } + return gp2; + }); } function isSessionExpired() { From f9bcfe2f7a03c93c9c25747eff74eb60e8731525 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 26 Apr 2023 09:13:17 +0500 Subject: [PATCH 13/13] mobile: obfuscate short emails --- apps/mobile/app/components/auth/session-expired.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/mobile/app/components/auth/session-expired.js b/apps/mobile/app/components/auth/session-expired.js index cb6bf2109..8b6a4f12e 100644 --- a/apps/mobile/app/components/auth/session-expired.js +++ b/apps/mobile/app/components/auth/session-expired.js @@ -44,8 +44,10 @@ import Paragraph from "../ui/typography/paragraph"; import { LoginSteps, useLogin } from "./use-login"; function getObfuscatedEmail(email) { - if (!email) return null; - return email.replace(/(.{2})(.*)(?=@)/, function (gp1, gp2, gp3) { + if (!email) return ""; + const [username, provider] = email.split("@"); + if (username.length === 1) return `****@${provider}`; + return email.replace(/(.{1})(.*)(?=@)/, function (gp1, gp2, gp3) { for (let i = 0; i < gp3.length; i++) { gp2 += "*"; }