Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix(applock):supress-on-lang-change

Aswin Asok9b11184e30e7
diff --git a/web/apps/photos/src/components/Sidebar.tsx b/web/apps/photos/src/components/Sidebar.tsx
index 6ec7d6616d..b397e387a8 100644
--- a/web/apps/photos/src/components/Sidebar.tsx
+++ b/web/apps/photos/src/components/Sidebar.tsx
@@ -83,7 +83,10 @@ import {
useSettingsSnapshot,
useUserDetailsSnapshot,
} from "ente-new/photos/components/utils/use-snapshot";
-import { reauthenticateWithAppLock } from "ente-new/photos/services/app-lock";
+import {
+ reauthenticateWithAppLock,
+ suppressAppLockRefreshFromSessionForTrustedReload,
+} from "ente-new/photos/services/app-lock";
import {
PseudoCollectionID,
type CollectionSummaries,
@@ -1288,6 +1291,8 @@ const LanguageSelector = () => {
const locale = getLocaleInUse();
const updateCurrentLocale = (newLocale: SupportedLocale) => {
+ if (newLocale === locale) return;
+
void setLocaleInUse(newLocale).then(() => {
// [Note: Changing locale causes a full reload]
//
@@ -1297,6 +1302,12 @@ const LanguageSelector = () => {
// We also rely on this behaviour by caching various formatters in
// module static variables that not get updated if the i18n.language
// changes unless there is a full reload.
+ //
+ // Mark this as a trusted app-initiated reload so desktop app-lock
+ // setup does not force an immediate lock screen.
+ if (globalThis.electron) {
+ suppressAppLockRefreshFromSessionForTrustedReload();
+ }
window.location.reload();
});
};
diff --git a/web/packages/new/photos/services/app-lock.ts b/web/packages/new/photos/services/app-lock.ts
index 5e6be5f22c..47605786f7 100644
--- a/web/packages/new/photos/services/app-lock.ts
+++ b/web/packages/new/photos/services/app-lock.ts
@@ -137,6 +137,8 @@ const lsKeyEnabled = "appLock.enabled";
// Stores the selected app-lock method ("pin" | "password" | "device" | "none").
const lsKeyAppLockMethod = "appLock.lockType";
const lsKeyAutoLockTimeMs = "appLock.autoLockTimeMs";
+const ssKeySuppressNextSessionRefreshLock =
+ "appLock.suppressNextSessionRefreshLock";
// -- KV DB keys (IndexedDB, async) --
@@ -180,6 +182,34 @@ export const clearAutoLockBlurSuppression = () => {
clearMainWindowBlurSuppression();
};
+/**
+ * Suppress one app-lock refresh cycle after a trusted app-initiated reload.
+ */
+export const suppressAppLockRefreshFromSessionForTrustedReload = () => {
+ try {
+ if (localStorage.getItem(lsKeyEnabled) !== "true") return;
+ sessionStorage.setItem(ssKeySuppressNextSessionRefreshLock, "true");
+ } catch {
+ // Ignore storage write errors; fallback to regular app-lock behavior.
+ }
+};
+
+const consumeAppLockRefreshSuppressionFromSession = () => {
+ try {
+ if (
+ sessionStorage.getItem(ssKeySuppressNextSessionRefreshLock) !== "true"
+ ) {
+ return false;
+ }
+
+ sessionStorage.removeItem(ssKeySuppressNextSessionRefreshLock);
+ return true;
+ } catch {
+ // Ignore storage read errors; fallback to regular app-lock behavior.
+ return false;
+ }
+};
+
export type DeviceLockMode = "native";
export type DeviceLockFailureReason = "native-prompt-failed" | "unknown";
@@ -549,7 +579,12 @@ const unlockLocally = () => {
*/
export const refreshAppLockStateFromSession = () => {
const config = readPersistedAppLockConfig();
- const isLocked = config.enabled && haveMasterKeyInSession();
+ const shouldSuppressLockForTrustedReload =
+ consumeAppLockRefreshSuppressionFromSession();
+ const isLocked =
+ config.enabled &&
+ haveMasterKeyInSession() &&
+ !shouldSuppressLockForTrustedReload;
setSnapshotFromPersistedConfig(config, isLocked);
};