π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Clean up Ensu Tauri runtime imports
Manav Rathi77f1e5f34869
diff --git a/web/apps/ensu/src/pages/chat.tsx b/web/apps/ensu/src/pages/chat.tsxindex 34ca1d515d..0c597b0533 100644--- a/web/apps/ensu/src/pages/chat.tsx+++ b/web/apps/ensu/src/pages/chat.tsx@@ -10,7 +10,6 @@ import {useMediaQuery,} from "@mui/material";import { getLuminance, useTheme } from "@mui/material/styles";-import { open as openFileDialog, save } from "@tauri-apps/plugin-dialog";import { ChatComposer } from "components/chat/ChatComposer";import { ChatDialogs } from "components/chat/ChatDialogs";import { ChatMessageList } from "components/chat/ChatMessageList";@@ -3333,6 +3332,7 @@ const Page: React.FC = () => {if (isTauriRuntime) {try {+ const { save } = await import("@tauri-apps/plugin-dialog");const filename = `ensu-web-logs-${Date.now()}.txt`;const path = await save({defaultPath: filename,@@ -3701,6 +3701,9 @@ const Page: React.FC = () => {closeAttachmentMenu();if (imageAttachmentSlotsRemaining <= 0) return;try {+ const { open: openFileDialog } = await import(+ "@tauri-apps/plugin-dialog"+ );const selection = await openFileDialog({directory: false,multiple: true,diff --git a/web/apps/ensu/src/services/app-update.ts b/web/apps/ensu/src/services/app-update.tsindex 3a72fdec21..4402f995f1 100644--- a/web/apps/ensu/src/services/app-update.ts+++ b/web/apps/ensu/src/services/app-update.ts@@ -1,6 +1,6 @@import type { MiniDialogAttributes } from "ente-base/components/MiniDialog";import log from "ente-base/log";-import { isTauriAppRuntime } from "services/secure-storage";+import { isTauriRuntime } from "services/tauri-runtime";const oneDay = 24 * 60 * 60 * 1000;@@ -17,7 +17,7 @@ type AppUpdateCheckResult =| { kind: "error" };export const checkForAppUpdates = async (): Promise<AppUpdateCheckResult> => {- if (!isTauriAppRuntime()) return { kind: "not-supported" };+ if (!isTauriRuntime()) return { kind: "not-supported" };if (inFlightUpdateCheck) return inFlightUpdateCheck;const run = async (): Promise<AppUpdateCheckResult> => {@@ -113,7 +113,7 @@ export const handleManualAppUpdateCheck = async (export const setupAutoAppUpdates = (showMiniDialog: ShowMiniDialog) => {if (- !isTauriAppRuntime() ||+ !isTauriRuntime() ||process.env.NODE_ENV !== "production" ||intervalId) {diff --git a/web/apps/ensu/src/services/chat/chatKey.ts b/web/apps/ensu/src/services/chat/chatKey.tsindex 9a55ca2ce7..df75d8d560 100644--- a/web/apps/ensu/src/services/chat/chatKey.ts+++ b/web/apps/ensu/src/services/chat/chatKey.ts@@ -1,8 +1,8 @@import { savedLocalUser } from "ente-accounts/services/accounts-db";import { HTTPError } from "ente-base/http";import log from "ente-base/log";+import { isTauriRuntime } from "services/tauri-runtime";import {- isTauriAppRuntime,secureStorageDelete,secureStorageGet,secureStorageSet,@@ -83,7 +83,7 @@ const nativeChatKeyPath = async () => {};const readNativeChatKeys = async (): Promise<PersistedChatKeys> => {- if (!isTauriAppRuntime()) return {};+ if (!isTauriRuntime()) return {};const [{ exists, readFile }, path] = await Promise.all([import("@tauri-apps/plugin-fs"),@@ -111,7 +111,7 @@ const readNativeChatKeys = async (): Promise<PersistedChatKeys> => {};const persistNativeChatKeys = async () => {- if (!isTauriAppRuntime()) return;+ if (!isTauriRuntime()) return;const operations: Promise<void>[] = [];const remoteStorageKey = scopedRemoteChatKeySecureStorageKey();@@ -163,7 +163,7 @@ const cleanupLegacyChatKeyCopies = async () => {};export const initChatKeyStore = async () => {- if (!isTauriAppRuntime()) return;+ if (!isTauriRuntime()) return;const userID = savedLocalUser()?.id;if (_chatKeyStoreInitPromise && _chatKeyStoreInitUserID === userID) {@@ -280,7 +280,7 @@ export const initChatKeyStore = async () => {};const setCachedChatKey = (chatKey: string) => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {_persistedChatKeys.remoteChatKey = chatKey;persistNativeChatKeysSoon();return;@@ -293,7 +293,7 @@ const setCachedChatKey = (chatKey: string) => {};const setCachedLocalChatKey = (chatKey: string) => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {_persistedChatKeys.localChatKey = chatKey;persistNativeChatKeysSoon();return;@@ -306,7 +306,7 @@ const setCachedLocalChatKey = (chatKey: string) => {* Return the cached chat key (base64), if present.*/export const cachedChatKey = (): string | undefined => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {return _persistedChatKeys.remoteChatKey;}@@ -316,7 +316,7 @@ export const cachedChatKey = (): string | undefined => {};export const legacyCachedChatKey = (): string | undefined => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {return _legacyPersistedChatKeys.remoteChatKey;}@@ -328,7 +328,7 @@ export const legacyCachedChatKey = (): string | undefined => {* Return the cached local-only chat key (base64), if present.*/export const cachedLocalChatKey = (): string | undefined => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {return _persistedChatKeys.localChatKey;}@@ -336,7 +336,7 @@ export const cachedLocalChatKey = (): string | undefined => {};export const legacyLocalChatKey = (): string | undefined => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {return _legacyPersistedChatKeys.localChatKey;}@@ -377,7 +377,7 @@ export const legacyAttachmentChatKey = (): string | undefined =>export const setLegacyAttachmentChatKey = async (chatKey?: string) => {_legacyAttachmentChatKey = chatKey;- if (!isTauriAppRuntime()) return;+ if (!isTauriRuntime()) return;if (chatKey) {await secureStorageSet(LEGACY_ATTACHMENT_KEY_SECURE_STORAGE_KEY,@@ -389,7 +389,7 @@ export const setLegacyAttachmentChatKey = async (chatKey?: string) => {};export const clearCachedChatKey = () => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {delete _persistedChatKeys.remoteChatKey;persistNativeChatKeysSoon();}@@ -399,7 +399,7 @@ export const clearCachedChatKey = () => {};export const clearLocalChatKey = () => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {delete _persistedChatKeys.localChatKey;persistNativeChatKeysSoon();return;diff --git a/web/apps/ensu/src/services/logout.ts b/web/apps/ensu/src/services/logout.tsindex 6cfe1a5e88..bf66234b8f 100644--- a/web/apps/ensu/src/services/logout.ts+++ b/web/apps/ensu/src/services/logout.ts@@ -1,4 +1,3 @@-import { invoke } from "@tauri-apps/api/core";import { accountLogout } from "ente-accounts/services/logout";import log from "ente-base/log";import { isTauriRuntime } from "services/tauri-runtime";@@ -16,6 +15,7 @@ export const ensuLogout = async () => {if (isTauriRuntime()) {try {+ const { invoke } = await import("@tauri-apps/api/core");await invoke("chat_db_reset");} catch (e) {ignoreError("Tauri chat DB", e);diff --git a/web/apps/ensu/src/services/secure-storage.ts b/web/apps/ensu/src/services/secure-storage.tsindex a6c10261a9..21d079462a 100644--- a/web/apps/ensu/src/services/secure-storage.ts+++ b/web/apps/ensu/src/services/secure-storage.ts@@ -24,5 +24,3 @@ export const secureStorageDelete = async (key: string) => {if (!isTauriRuntime()) return;await tauriInvoke("secure_storage_delete", { key });};--export const isTauriAppRuntime = isTauriRuntime;diff --git a/web/apps/ensu/src/services/session.ts b/web/apps/ensu/src/services/session.tsindex f603120af1..ccb9860e3f 100644--- a/web/apps/ensu/src/services/session.ts+++ b/web/apps/ensu/src/services/session.ts@@ -1,6 +1,6 @@import log from "ente-base/log";+import { isTauriRuntime } from "services/tauri-runtime";import {- isTauriAppRuntime,secureStorageDelete,secureStorageGet,secureStorageSet,@@ -36,7 +36,7 @@ const sessionKeyData = async (keyDataB64: string): Promise<SessionKeyData> => {/** Return the decrypted master key (base64) from session storage, if present. */export const masterKeyFromSession = async (): Promise<string | undefined> => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {if (_tauriMasterKeyCache) return _tauriMasterKeyCache;try {const masterKey = await secureStorageGet(@@ -62,7 +62,7 @@ export const masterKeyFromSession = async (): Promise<string | undefined> => {await ensureCryptoInit();const wasm = await enteWasm();const masterKey = await wasm.crypto_decrypt_box(encryptedData, nonce, key);- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {_tauriMasterKeyCache = masterKey;}return masterKey;@@ -70,7 +70,7 @@ export const masterKeyFromSession = async (): Promise<string | undefined> => {/** Save the master key (base64) in session storage and secure storage on Tauri. */export const saveMasterKeyInSession = async (masterKeyB64: string) => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {_tauriMasterKeyCache = masterKeyB64;try {await secureStorageSet(MASTER_KEY_SECURE_STORAGE_KEY, masterKeyB64);@@ -87,7 +87,7 @@ export const saveMasterKeyInSession = async (masterKeyB64: string) => {/** Remove the master key from session storage. */export const clearMasterKeyFromSession = () => {- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {_tauriMasterKeyCache = undefined;}sessionStorage.removeItem(MASTER_KEY_SESSION_KEY);@@ -96,7 +96,7 @@ export const clearMasterKeyFromSession = () => {/** Remove the master key from session storage and Tauri secure storage. */export const clearMasterKeyFromEverywhere = async () => {clearMasterKeyFromSession();- if (isTauriAppRuntime()) {+ if (isTauriRuntime()) {try {await secureStorageDelete(MASTER_KEY_SECURE_STORAGE_KEY);} catch (error) {@@ -107,7 +107,7 @@ export const clearMasterKeyFromEverywhere = async () => {/** Hydrate session storage from Tauri secure storage when possible. */export const updateSessionFromTauriSecureStorageIfNeeded = async () => {- if (!isTauriAppRuntime()) return;+ if (!isTauriRuntime()) return;if (_tauriMasterKeyCache) return;try {diff --git a/web/apps/ensu/src/services/whats-new.ts b/web/apps/ensu/src/services/whats-new.tsindex 7716899721..5726f0be8b 100644--- a/web/apps/ensu/src/services/whats-new.ts+++ b/web/apps/ensu/src/services/whats-new.ts@@ -1,4 +1,4 @@-import { isTauriAppRuntime } from "services/secure-storage";+import { isTauriRuntime } from "services/tauri-runtime";import {whatsNewEntries,whatsNewVersion,@@ -15,7 +15,7 @@ export interface PendingDesktopWhatsNew {export const getPendingDesktopWhatsNew = ():| PendingDesktopWhatsNew| undefined => {- if (!isTauriAppRuntime()) return undefined;+ if (!isTauriRuntime()) return undefined;const seenVersion = readSeenVersion();if (seenVersion >= whatsNewVersion) return undefined;@@ -29,7 +29,7 @@ export const getPendingDesktopWhatsNew = ():};export const markDesktopWhatsNewSeen = () => {- if (!isTauriAppRuntime()) return;+ if (!isTauriRuntime()) return;try {window.localStorage.setItem(storageKey, String(whatsNewVersion));