Skip to content

Commit 81cb879

Browse files
Enhance session synchronization by introducing suppress warning functionality in sessionSync.js
1 parent cf6ce9b commit 81cb879

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

resources/js/common/sessionSync.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const initSessionSync = ({
2323
const sessionWarningKey = "pm:session:warning";
2424
// Track keep-alive progress across tabs.
2525
const sessionRenewingKey = "pm:session:renewing";
26+
const sessionSuppressKey = "pm:session:suppress-warning";
2627
const sessionMessageKey = "pm:session:message";
2728
const sessionTabId = `${Date.now()}-${Math.random().toString(16).slice(2)}`;
2829
const leaderHeartbeatMs = 4000;
@@ -103,11 +104,18 @@ export const initSessionSync = ({
103104

104105
let warningState = readStorageJson(sessionWarningKey);
105106
let renewingState = readStorageJson(sessionRenewingKey);
107+
let suppressWarningState = readStorageJson(sessionSuppressKey);
106108

107109
const refreshWarningStateFromStorage = () => {
108110
const storedWarningState = readStorageJson(sessionWarningKey);
109111
if (storedWarningState?.time && storedWarningState?.ts) {
110-
warningState = storedWarningState;
112+
// Clear stale warning from previous session.
113+
if (sessionState?.startedAt && storedWarningState.ts < sessionState.startedAt) {
114+
warningState = null;
115+
removeStorageKey(sessionWarningKey);
116+
} else {
117+
warningState = storedWarningState;
118+
}
111119
} else {
112120
warningState = null;
113121
}
@@ -154,10 +162,24 @@ export const initSessionSync = ({
154162
} else {
155163
renewingState = null;
156164
removeStorageKey(sessionRenewingKey);
165+
setSuppressWarning(1000);
157166
}
158167
syncRenewingUi();
159168
};
160169

170+
const refreshSuppressWarningState = () => {
171+
const storedSuppressState = readStorageJson(sessionSuppressKey);
172+
suppressWarningState = storedSuppressState?.until ? storedSuppressState : null;
173+
return suppressWarningState;
174+
};
175+
176+
const setSuppressWarning = (durationMs) => {
177+
suppressWarningState = {
178+
until: Date.now() + durationMs,
179+
};
180+
writeStorageJson(sessionSuppressKey, suppressWarningState);
181+
};
182+
161183
const sessionChannel = "BroadcastChannel" in window ? new BroadcastChannel(sessionChannelName) : null;
162184
const recentMessageIds = new Map();
163185
const recentMessageTtlMs = 5000;
@@ -294,6 +316,10 @@ export const initSessionSync = ({
294316
if (renewingState?.isRenewing) {
295317
return;
296318
}
319+
refreshSuppressWarningState();
320+
if (suppressWarningState?.until && Date.now() < suppressWarningState.until) {
321+
return;
322+
}
297323
sessionDebugLog("warning:show", { remainingTime });
298324
const sessionModal = resolveSessionModal();
299325
// Guard for layouts that don't include the session modal.
@@ -344,6 +370,7 @@ export const initSessionSync = ({
344370
const timeout = Number(message.data?.timeout) || accountTimeoutLength;
345371
clearWarningState();
346372
setRenewingState(false);
373+
setSuppressWarning(1000);
347374
setSessionState(timeout);
348375
const closeSessionModal = resolveCloseSessionModal();
349376
if (closeSessionModal) {
@@ -555,6 +582,7 @@ export const initSessionSync = ({
555582
isLeader,
556583
setSessionState,
557584
clearWarningState,
585+
setRenewingState,
558586
},
559587
};
560588
};

resources/js/components/Session.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ export default {
163163
if (window.ProcessMaker.sessionSync?.broadcast) {
164164
window.ProcessMaker.sessionSync.broadcast("renewing", { isRenewing });
165165
}
166+
if (window.ProcessMaker.sessionSync?.setRenewingState) {
167+
window.ProcessMaker.sessionSync.setRenewingState(isRenewing);
168+
}
166169
},
167170
broadcastExpired() {
168171
// Sync timeout state across tabs.

0 commit comments

Comments
 (0)