π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
logs
Manav Rathif3efad60f3c0
diff --git a/web/apps/accounts/src/pages/_app.tsx b/web/apps/accounts/src/pages/_app.tsxindex 707d214923..2f31c07541 100644--- a/web/apps/accounts/src/pages/_app.tsx+++ b/web/apps/accounts/src/pages/_app.tsx@@ -3,28 +3,22 @@ import { CustomHead } from "@/base/components/Head";import { LoadingOverlay } from "@/base/components/LoadingOverlay";import { AttributedMiniDialog } from "@/base/components/MiniDialog";import { useAttributedMiniDialog } from "@/base/components/utils/dialog";-import { useSetupI18n } from "@/base/components/utils/hooks-i18n";+import { useSetupI18n, useSetupLogs } from "@/base/components/utils/hooks-app";import { getTheme, THEME_COLOR } from "@/base/components/utils/theme";-import { disableDiskLogs } from "@/base/log";-import { logUnhandledErrorsAndRejections } from "@/base/log-web";import "@fontsource-variable/inter";import { CssBaseline } from "@mui/material";import { ThemeProvider } from "@mui/material/styles";import { t } from "i18next";import type { AppProps } from "next/app";-import React, { useEffect, useMemo } from "react";+import React, { useMemo } from "react";import { AppContext } from "../types/context";const App: React.FC<AppProps> = ({ Component, pageProps }) => {+ useSetupLogs({ disableDiskLogs: true });+const isI18nReady = useSetupI18n();const { showMiniDialog, miniDialogProps } = useAttributedMiniDialog();- useEffect(() => {- disableDiskLogs();- logUnhandledErrorsAndRejections(true);- return () => logUnhandledErrorsAndRejections(false);- }, []);-const appContext = useMemo(() => ({ showMiniDialog }), [showMiniDialog]);const title = isI18nReady ? t("title_accounts") : staticAppTitle;diff --git a/web/apps/auth/src/pages/_app.tsx b/web/apps/auth/src/pages/_app.tsxindex 05fa832c74..5c4f237d25 100644--- a/web/apps/auth/src/pages/_app.tsx+++ b/web/apps/auth/src/pages/_app.tsx@@ -5,12 +5,9 @@ import { LoadingOverlay } from "@/base/components/LoadingOverlay";import { AttributedMiniDialog } from "@/base/components/MiniDialog";import { AppNavbar } from "@/base/components/Navbar";import { useAttributedMiniDialog } from "@/base/components/utils/dialog";-import { useSetupI18n } from "@/base/components/utils/hooks-i18n";+import { useSetupI18n, useSetupLogs } from "@/base/components/utils/hooks-app";import { THEME_COLOR, getTheme } from "@/base/components/utils/theme";-import {- logStartupBanner,- logUnhandledErrorsAndRejections,-} from "@/base/log-web";+import { logStartupBanner } from "@/base/log-web";import { useLocalState } from "@ente/shared/hooks/useLocalState";import HTTPService from "@ente/shared/network/HTTPService";import {@@ -31,6 +28,8 @@ import { AppContext } from "types/context";import "styles/global.css";const App: React.FC<AppProps> = ({ Component, pageProps }) => {+ useSetupLogs();+const router = useRouter();const [loading, setLoading] = useState(false);const [showNavbar, setShowNavBar] = useState(false);@@ -47,8 +46,6 @@ const App: React.FC<AppProps> = ({ Component, pageProps }) => {void migrateKVToken(user);logStartupBanner(user?.id);HTTPService.setHeaders({ "X-Client-Package": clientPackageName });- logUnhandledErrorsAndRejections(true);- return () => logUnhandledErrorsAndRejections(false);}, []);useEffect(() => {diff --git a/web/apps/cast/src/pages/_app.tsx b/web/apps/cast/src/pages/_app.tsxindex 2c7f0d57d3..a3905828e2 100644--- a/web/apps/cast/src/pages/_app.tsx+++ b/web/apps/cast/src/pages/_app.tsx@@ -1,19 +1,14 @@import { staticAppTitle } from "@/base/app";import { CustomHead } from "@/base/components/Head";+import { useSetupLogs } from "@/base/components/utils/hooks-app";import { getTheme, THEME_COLOR } from "@/base/components/utils/theme";-import { disableDiskLogs } from "@/base/log";-import { logUnhandledErrorsAndRejections } from "@/base/log-web";import "@fontsource-variable/inter";import { CssBaseline, ThemeProvider } from "@mui/material";import type { AppProps } from "next/app";-import React, { useEffect } from "react";+import React from "react";const App: React.FC<AppProps> = ({ Component, pageProps }) => {- useEffect(() => {- disableDiskLogs();- logUnhandledErrorsAndRejections(true);- return () => logUnhandledErrorsAndRejections(false);- }, []);+ useSetupLogs({ disableDiskLogs: true });return (<>diff --git a/web/apps/photos/src/pages/_app.tsx b/web/apps/photos/src/pages/_app.tsxindex 4f9fc8d072..ba64c4dc80 100644--- a/web/apps/photos/src/pages/_app.tsx+++ b/web/apps/photos/src/pages/_app.tsx@@ -7,13 +7,10 @@ import {genericErrorDialogAttributes,useAttributedMiniDialog,} from "@/base/components/utils/dialog";-import { useSetupI18n } from "@/base/components/utils/hooks-i18n";+import { useSetupI18n, useSetupLogs } from "@/base/components/utils/hooks-app";import { THEME_COLOR, getTheme } from "@/base/components/utils/theme";import log from "@/base/log";-import {- logStartupBanner,- logUnhandledErrorsAndRejections,-} from "@/base/log-web";+import { logStartupBanner } from "@/base/log-web";import { AppUpdate } from "@/base/types/ipc";import {updateAvailableForDownloadDialogAttributes,@@ -52,6 +49,8 @@ import { NotificationAttributes } from "types/Notification";import "styles/global.css";export default function App({ Component, pageProps }: AppProps) {+ useSetupLogs();+const router = useRouter();const [loading, setLoading] = useState(false);const [showNavbar, setShowNavBar] = useState(false);@@ -76,9 +75,7 @@ export default function App({ Component, pageProps }: AppProps) {void migrateKVToken(user);logStartupBanner(user?.id);HTTPService.setHeaders({ "X-Client-Package": clientPackageName });- logUnhandledErrorsAndRejections(true);void runMigrations();- return () => logUnhandledErrorsAndRejections(false);}, []);useEffect(() => {diff --git a/web/packages/base/components/utils/hooks-app.ts b/web/packages/base/components/utils/hooks-app.tsnew file mode 100644index 0000000000..122c4f9105--- /dev/null+++ b/web/packages/base/components/utils/hooks-app.ts@@ -0,0 +1,44 @@+import { setupI18n } from "@/base/i18n";+import { disableDiskLogs } from "@/base/log";+import { logUnhandledErrorsAndRejections } from "@/base/log-web";+import { useEffect, useState } from "react";++/**+ * A hook that initializes the localization library that we use.+ *+ * This is only meant to be called from the top level `_app.tsx`, as this+ * initialization is intended to happen only once for the lifetime of the app.+ *+ * @returns a boolean which will be set to true when the localized strings have+ * been loaded.+ */+export const useSetupI18n = () => {+ const [isI18nReady, setIsI18nReady] = useState(false);++ useEffect(() => {+ void setupI18n().finally(() => setIsI18nReady(true));+ }, []);++ return isI18nReady;+};++interface SetupLoggingOptions {+ /** If true, then the logs will not be saved to local storage. */+ disableDiskLogs?: boolean;+}++/**+ * A hook that initializes the logging subsystem.+ *+ * This is only meant to be called from the top level `_app.tsx`, as this+ * initialization is intended to happen only once for the lifetime of the app.+ *+ * @param opts Optional {@link SetupLoggingOptions} to customize the setup.+ */+export const useSetupLogs = (opts?: SetupLoggingOptions) => {+ useEffect(() => {+ if (opts?.disableDiskLogs) disableDiskLogs();+ logUnhandledErrorsAndRejections(true);+ return () => logUnhandledErrorsAndRejections(false);+ }, []);+};diff --git a/web/packages/base/components/utils/hooks-i18n.ts b/web/packages/base/components/utils/hooks-i18n.tsdeleted file mode 100644index 1f7accce96..0000000000--- a/web/packages/base/components/utils/hooks-i18n.ts+++ /dev/null@@ -1,21 +0,0 @@-import { setupI18n } from "@/base/i18n";-import { useEffect, useState } from "react";--/**- * A hook that initializes the localization library that we use.- *- * This is only meant to be called from the top level `_app.tsx`, as this- * initialization is expected to only happen once for the lifetime of the page.- *- * @returns a boolean which will be set to true when the localized strings have- * been loaded.- */-export const useSetupI18n = () => {- const [isI18nReady, setIsI18nReady] = useState(false);-- useEffect(() => {- void setupI18n().finally(() => setIsI18nReady(true));- }, []);-- return isI18nReady;-};