A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
Feat/image compression setting (#9542)
Ammar Ahmed6efd1af0e93a
diff --git a/apps/mobile/.detoxrc.js b/apps/mobile/.detoxrc.jsindex 5bb53788f..5ec66fb5b 100644--- a/apps/mobile/.detoxrc.js+++ b/apps/mobile/.detoxrc.js@@ -30,7 +30,7 @@ module.exports = {testBinaryPath:"android/app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk",build:- "cd android ; ENVFILE=.env.test ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug && cd ..",+ "cd android ; ENVFILE=.env.test ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug -PreactNativeArchitectures=arm64-v8a && cd ..",reversePorts: [8081]},"android.release": {diff --git a/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx b/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsxindex f2c0207ad..b76f5a2a0 100644--- a/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx+++ b/apps/mobile/app/components/dialogs/attach-image-dialog/index.tsx@@ -35,6 +35,7 @@ import { Button } from "../../ui/button";import { IconButton } from "../../ui/icon-button";import { Notice } from "../../ui/notice";import Paragraph from "../../ui/typography/paragraph";+import SettingsService from "../../../services/settings";export default function AttachImage({response,@@ -201,6 +202,17 @@ AttachImage.present = (response: ImageType[], context?: string) => {| undefined>((resolve) => {let resolved = false;++ const imageCompressionSetting =+ SettingsService.getProperty("imageCompression");++ if (imageCompressionSetting !== "ask-every-time") {+ resolve({+ compress: imageCompressionSetting === "enabled" ? true : false+ });+ return;+ }+presentSheet({context: context,component: (ref, close, update) => (diff --git a/apps/mobile/app/components/paywall/index.tsx b/apps/mobile/app/components/paywall/index.tsxindex 609b364f0..c785aa33a 100644--- a/apps/mobile/app/components/paywall/index.tsx+++ b/apps/mobile/app/components/paywall/index.tsx@@ -183,6 +183,7 @@ const PayWall = (props: NavigationProps<"PayWall">) => {><IconButtonname="close"+ testID="paywall-close"color={colors.primary.icon}onPress={() => {Navigation.navigate("FluidPanelsView", {});@@ -1008,8 +1009,8 @@ const PricingPlanCard = ({: "monthly"}`: pricingPlans.isGithubRelease- ? (WebPlan?.period as string)- : (product?.productId as string)+ ? (WebPlan?.period as string)+ : (product?.productId as string));setStep(Steps.buy);}}diff --git a/apps/mobile/app/screens/editor/tiptap/picker.ts b/apps/mobile/app/screens/editor/tiptap/picker.tsindex a6d095fb4..231915c23 100644--- a/apps/mobile/app/screens/editor/tiptap/picker.ts+++ b/apps/mobile/app/screens/editor/tiptap/picker.ts@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.import Sodium from "@ammarahmed/react-native-sodium";import { isFeatureAvailable } from "@notesnook/common";-import { isImage } from "@notesnook/core";import { strings } from "@notesnook/intl";import {DocumentPickerOptions,diff --git a/apps/mobile/app/screens/settings/components.tsx b/apps/mobile/app/screens/settings/components.tsxindex e3e9cd7cf..ce752a963 100644--- a/apps/mobile/app/screens/settings/components.tsx+++ b/apps/mobile/app/screens/settings/components.tsx@@ -36,6 +36,7 @@ import {WeekFormatPicker,FontPicker,HomePicker,+ ImageCompressionPicker,SidebarTabPicker,TimeFormatPicker,TrashIntervalPicker@@ -62,6 +63,7 @@ export const components: { [name: string]: ReactElement } = {"time-format-selector": <TimeFormatPicker />,"day-format-selector": <DayFormatPicker />,"week-format-selector": <WeekFormatPicker />,+ "image-compression-picker": <ImageCompressionPicker />,"theme-selector": <ThemeSelector />,"applock-timer": <ApplockTimerPicker />,autobackupsattachments: <BackupWithAttachmentsReminderPicker />,diff --git a/apps/mobile/app/screens/settings/picker/index.tsx b/apps/mobile/app/screens/settings/picker/index.tsxindex 02176e755..e9bfa0cf7 100644--- a/apps/mobile/app/screens/settings/picker/index.tsx+++ b/apps/mobile/app/screens/settings/picker/index.tsx@@ -32,11 +32,11 @@ import { sleep } from "../../../utils/time";import { verifyUser } from "../functions";import { DefaultAppStyles } from "../../../utils/styles";-interface PickerOptions<T> {- getValue: () => T;+interface PickerOptions<T, B = any> {+ getValue: () => B;updateValue: (item: T) => Promise<void>;formatValue: (item: T) => any;- compareValue: (current: T, item: T) => boolean;+ compareValue: (current: B, item: T) => boolean;getItemKey: (item: T) => string;options: T[];isFeatureAvailable: () => Promise<boolean>;@@ -170,7 +170,7 @@ export function SettingsPicker<T>({);}-export function createSettingsPicker<T>(props: PickerOptions<T>) {+export function createSettingsPicker<T, B>(props: PickerOptions<T, B>) {const Selector = () => {return <SettingsPicker {...props} />;};diff --git a/apps/mobile/app/screens/settings/picker/pickers.jsx b/apps/mobile/app/screens/settings/picker/pickers.tsxsimilarity index 70%rename from apps/mobile/app/screens/settings/picker/pickers.jsxrename to apps/mobile/app/screens/settings/picker/pickers.tsxindex 8107ee1fa..602f9973b 100644--- a/apps/mobile/app/screens/settings/picker/pickers.jsx+++ b/apps/mobile/app/screens/settings/picker/pickers.tsx@@ -17,14 +17,21 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/-import { DATE_FORMATS, TIME_FORMATS } from "@notesnook/core";+import {+ DATE_FORMATS,+ DayFormat,+ TIME_FORMATS,+ TimeFormat,+ TrashCleanupInterval,+ WeekFormat+} from "@notesnook/core";import { getFontById, getFonts } from "@notesnook/editor/dist/cjs/utils/font";import dayjs from "dayjs";import { createSettingsPicker } from ".";import { db } from "../../../common/database";import { ToastManager } from "../../../services/event-manager";import SettingsService from "../../../services/settings";-import { useSettingStore } from "../../../stores/use-setting-store";+import { Settings, useSettingStore } from "../../../stores/use-setting-store";import { useUserStore } from "../../../stores/use-user-store";import { MenuItemsList } from "../../../utils/menu-items";import { verifyUserWithApplock } from "../functions";@@ -44,26 +51,29 @@ const WeekFormatNames = {Mon: "Monday"};-export const FontPicker = createSettingsPicker({+export const FontPicker = createSettingsPicker<+ ReturnType<typeof getFonts>[0],+ Settings["defaultFontFamily"]+>({getValue: () => useSettingStore.getState().settings.defaultFontFamily,- updateValue: (item) => {+ updateValue: async (item) => {SettingsService.set({defaultFontFamily: item.id});},formatValue: (item) => {- return getFontById(typeof item === "object" ? item.id : item).title;+ return getFontById(typeof item === "object" ? item.id : item)?.title;},getItemKey: (item) => item.id,options: getFonts(),compareValue: (current, item) => current === item.id,- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});export const HomePicker = createSettingsPicker({getValue: () => useSettingStore.getState().settings.homepage,- updateValue: (item) => {+ updateValue: async (item) => {SettingsService.set({ homepage: item.title });ToastManager.show({heading: strings.homePageChangedTo(item.title),@@ -72,18 +82,22 @@ export const HomePicker = createSettingsPicker({});},formatValue: (item) => {- return strings.routes[typeof item === "object" ? item.title : item]?.();+ return strings.routes[+ (typeof item === "object"+ ? item.title+ : item) as keyof typeof strings.routes+ ]?.();},getItemKey: (item) => item.title,options: MenuItemsList.slice(0, MenuItemsList.length - 1),compareValue: (current, item) => current === item.title,- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});export const SidebarTabPicker = createSettingsPicker({getValue: () => useSettingStore.getState().settings.defaultSidebarTab,- updateValue: (item) => {+ updateValue: async (item) => {SettingsService.set({ defaultSidebarTab: item });},formatValue: (item) => {@@ -94,7 +108,7 @@ export const SidebarTabPicker = createSettingsPicker({];return SidebarTabs[item];},- getItemKey: (item) => item,+ getItemKey: (item) => `side-bar-tab-picker-${item}`,options: [0, 1, 2],compareValue: (current, item) => current === item,isFeatureAvailable: async () => {@@ -111,12 +125,12 @@ export const SidebarTabPicker = createSettingsPicker({}return result.isAllowed;},- isOptionAvailable: () => true+ isOptionAvailable: async () => true});export const TrashIntervalPicker = createSettingsPicker({getValue: () => db.settings.getTrashCleanupInterval(),- updateValue: (item) => {+ updateValue: async (item) => {db.settings.setTrashCleanupInterval(item);},formatValue: (item) => {@@ -127,9 +141,9 @@ export const TrashIntervalPicker = createSettingsPicker({: strings.days(item);},getItemKey: (item) => item.toString(),- options: [-1, 1, 7, 30, 365],+ options: [-1, 1, 7, 30, 365] as TrashCleanupInterval[],compareValue: (current, item) => current === item,- isFeatureAvailable: () => true,+ isFeatureAvailable: async () => true,isOptionAvailable: async () => {const disableTrashFeature = await isFeatureAvailable("disableTrashCleanup");if (!disableTrashFeature.isAllowed) {@@ -148,7 +162,7 @@ export const TrashIntervalPicker = createSettingsPicker({export const DateFormatPicker = createSettingsPicker({getValue: () => db.settings.getDateFormat(),- updateValue: (item) => {+ updateValue: async (item) => {db.settings.setDateFormat(item);useSettingStore.setState({dateFormat: item@@ -160,13 +174,13 @@ export const DateFormatPicker = createSettingsPicker({getItemKey: (item) => item,options: DATE_FORMATS,compareValue: (current, item) => current === item,- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});export const DayFormatPicker = createSettingsPicker({getValue: () => db.settings.getDayFormat(),- updateValue: (item) => {+ updateValue: async (item) => {db.settings.setDayFormat(item);useSettingStore.setState({dayFormat: item@@ -176,15 +190,15 @@ export const DayFormatPicker = createSettingsPicker({return `${strings.dayFormat()} (${dayjs().format(DayFormatFormats[item])})`;},getItemKey: (item) => item,- options: DAY_FORMATS,+ options: DAY_FORMATS as DayFormat[],compareValue: (current, item) => current === item,- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});export const WeekFormatPicker = createSettingsPicker({getValue: () => db.settings.getWeekFormat(),- updateValue: (item) => {+ updateValue: async (item) => {db.settings.setWeekFormat(item);useSettingStore.setState({weekFormat: item@@ -194,10 +208,10 @@ export const WeekFormatPicker = createSettingsPicker({return `${WeekFormatNames[item]}`;},getItemKey: (item) => item,- options: WEEK_FORMATS,+ options: WEEK_FORMATS as WeekFormat[],compareValue: (current, item) => current === item,- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});const TimeFormats = {@@ -207,7 +221,7 @@ const TimeFormats = {export const TimeFormatPicker = createSettingsPicker({getValue: () => db.settings.getTimeFormat(),- updateValue: (item) => {+ updateValue: async (item) => {db.settings.setTimeFormat(item);useSettingStore.setState({timeFormat: item@@ -217,15 +231,18 @@ export const TimeFormatPicker = createSettingsPicker({return `${strings[item]()} (${dayjs().format(TimeFormats[item])})`;},getItemKey: (item) => item,- options: TIME_FORMATS,+ options: TIME_FORMATS as TimeFormat[],compareValue: (current, item) => current === item,- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});-export const BackupReminderPicker = createSettingsPicker({+export const BackupReminderPicker = createSettingsPicker<+ Settings["reminder"],+ Settings["reminder"]+>({getValue: () => useSettingStore.getState().settings.reminder,- updateValue: (item) => {+ updateValue: async (item) => {SettingsService.set({ reminder: item });},formatValue: (item) => {@@ -237,39 +254,40 @@ export const BackupReminderPicker = createSettingsPicker({requiresVerification: () => {return (!useSettingStore.getState().settings.encryptedBackup &&- useUserStore.getState().user+ !!useUserStore.getState().user);},- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});export const BackupWithAttachmentsReminderPicker = createSettingsPicker({getValue: () => useSettingStore.getState().settings.fullBackupReminder,- updateValue: (item) => {+ updateValue: async (item) => {SettingsService.set({ fullBackupReminder: item });},formatValue: (item) => {+ //@ts-ignorereturn item === "useroff" || item === "off" || item === "never"? "Off": item.slice(0, 1).toUpperCase() + item.slice(1);},getItemKey: (item) => item,- options: ["never", "weekly", "monthly"],+ options: ["never", "weekly", "monthly"] as Settings["fullBackupReminder"][],compareValue: (current, item) => current === item,requiresVerification: () => {return (!useSettingStore.getState().settings.encryptedBackup &&- useUserStore.getState().user+ !!useUserStore.getState().user);},- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true});export const ApplockTimerPicker = createSettingsPicker({getValue: () => useSettingStore.getState().settings.appLockTimer,- updateValue: (item) => {+ updateValue: async (item) => {SettingsService.set({ appLockTimer: item });},formatValue: (item) => {@@ -287,6 +305,45 @@ export const ApplockTimerPicker = createSettingsPicker({onVerify: () => {return verifyUserWithApplock();},- isFeatureAvailable: () => true,- isOptionAvailable: () => true+ isFeatureAvailable: async () => true,+ isOptionAvailable: async () => true+});++export const ImageCompressionPicker = createSettingsPicker({+ getValue: () => useSettingStore.getState().settings.imageCompression,+ updateValue: async (item) => {+ SettingsService.set({ imageCompression: item });+ },+ formatValue: (item) => {+ return item === "ask-every-time"+ ? strings.askEveryTime()+ : item === "enabled"+ ? strings.enableRecommended()+ : strings.disable();+ },+ getItemKey: (item) => item,+ options: [+ "ask-every-time",+ "enabled",+ "disabled"+ ] as Settings["imageCompression"][],+ compareValue: (current, item) => current === item,+ isFeatureAvailable: async () => true,+ isOptionAvailable: async (item) => {+ const feature = await isFeatureAvailable("fullQualityImages");++ if (!feature.isAllowed && item === "enabled") {+ ToastManager.show({+ message: feature.error,+ type: "info",+ actionText: strings.upgrade(),+ func: () => {+ PaywallSheet.present(feature);+ }+ });+ return false;+ }++ return true;+ }});diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsxindex ffd7f51d4..89fbe9731 100644--- a/apps/mobile/app/screens/settings/settings-data.tsx+++ b/apps/mobile/app/screens/settings/settings-data.tsx@@ -874,6 +874,14 @@ export const settingsGroups: SettingSection[] = [description: strings.autoUpdateCheckDesc(),property: "checkForUpdates",icon: "update"+ },+ {+ id: "image-compression",+ type: "component",+ name: strings.imageCompression(),+ description: strings.imageCompressionDesc(),+ component: "image-compression-picker",+ icon: "image-area"}]},diff --git a/apps/mobile/app/stores/use-setting-store.ts b/apps/mobile/app/stores/use-setting-store.tsindex 247671859..c3ba7af62 100644--- a/apps/mobile/app/stores/use-setting-store.ts+++ b/apps/mobile/app/stores/use-setting-store.ts@@ -102,6 +102,7 @@ export type Settings = {defaultSidebarTab: number;checkForUpdates?: boolean;defaultLineHeight: number;+ imageCompression: "ask-every-time" | "enabled" | "disabled";};type DimensionsType = {@@ -207,7 +208,8 @@ export const defaultSettings: SettingStore["settings"] = {fullBackupReminder: "never",lastFullBackupDate: 0,checkForUpdates: true,- defaultLineHeight: EDITOR_LINE_HEIGHT.DEFAULT+ defaultLineHeight: EDITOR_LINE_HEIGHT.DEFAULT,+ imageCompression: "ask-every-time"};export const useSettingStore = create<SettingStore>((set, get) => ({diff --git a/apps/mobile/e2e/tests/auth.e2e.ts b/apps/mobile/e2e/tests/auth.e2e.tsindex 6eed4f246..8069c3e94 100644--- a/apps/mobile/e2e/tests/auth.e2e.ts+++ b/apps/mobile/e2e/tests/auth.e2e.ts@@ -56,24 +56,26 @@ const USER = {async function login() {await TestBuilder.create().waitAndTapByText("Login to encrypt and sync notes")- .typeTextById("input.email", USER.login.email!)+ .replaceTextById("input.email", USER.login.email!).tapReturnKeyById("input.email").wait(3000)- .typeTextById("input.totp", authenticator.generate(USER.login.totpSecret!))+ .replaceTextById(+ "input.totp",+ authenticator.generate(USER.login.totpSecret!)+ ).waitAndTapByText("Next").wait(3000)- .typeTextById("input.password", USER.login.password!)+ .replaceTextById("input.password", USER.login.password!).tapReturnKeyById("input.password")+ .wait(4000)+ .tapById("paywall-close")+ .wait(3000)+ .isVisibleById("Search in Notes").run();}describe("AUTH", () => {it("Login", async () => {- await TestBuilder.create()- .prepare()- .addStep(login)- .wait(3000)- .isNotVisibleByText("Notesnook Plans")- .run();+ await TestBuilder.create().prepare().addStep(login).run();});});diff --git a/apps/mobile/e2e/tests/utils.ts b/apps/mobile/e2e/tests/utils.tsindex 12779deee..02d678127 100644--- a/apps/mobile/e2e/tests/utils.ts+++ b/apps/mobile/e2e/tests/utils.ts@@ -315,6 +315,12 @@ class TestBuilder {});}+ replaceTextById(id: string, text: string) {+ return this.addStep(async () => {+ await Element.fromId(id).element.replaceText(text);+ });+ }+clearTextById(id: string) {return this.addStep(async () => {await Element.fromId(id).element.clearText();diff --git a/apps/mobile/fonts/MaterialCommunityIcons.ttf b/apps/mobile/fonts/MaterialCommunityIcons.ttfindex 92e2fc8c2..b3dda3db1 100644Binary files a/apps/mobile/fonts/MaterialCommunityIcons.ttf and b/apps/mobile/fonts/MaterialCommunityIcons.ttf differdiff --git a/apps/mobile/scripts/optimize-fonts.mjs b/apps/mobile/scripts/optimize-fonts.mjsindex 19b77aa9b..14689cf80 100644--- a/apps/mobile/scripts/optimize-fonts.mjs+++ b/apps/mobile/scripts/optimize-fonts.mjs@@ -124,7 +124,8 @@ const EXTRA_ICON_NAMES = ["bomb-off","cancel","inbox",- "identifier"+ "identifier",+ "image-area"];const __filename = fileURLToPath(import.meta.url);diff --git a/apps/mobile/tsconfig.json b/apps/mobile/tsconfig.jsonindex 55a0586cd..9ac72b771 100644--- a/apps/mobile/tsconfig.json+++ b/apps/mobile/tsconfig.json@@ -18,6 +18,9 @@],"@notesnook/editor/dist/cjs/toolbar/icons": ["../../packages/editor/dist/cjs/toolbar/icons.js"+ ],+ "@notesnook/editor/dist/cjs/utils/font": [+ "../../packages/editor/dist/cjs/utils/font.js"]}},