优化桌面端界面布局
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import router from "../router";
|
||||
import { useAuthStore } from "../store/auth";
|
||||
import { useSessionStore } from "../store/session";
|
||||
import { isTauriRuntime } from "../runtime";
|
||||
import { getToken, setToken } from "../utils/auth";
|
||||
import { extendToken } from "../api/authClient";
|
||||
import { parseJwtExp } from "./jwt";
|
||||
@@ -24,11 +25,17 @@ let extendPromise: Promise<{ token: string | null; authFailed: boolean }> | null
|
||||
let initialized = false;
|
||||
const channel = typeof BroadcastChannel !== "undefined" ? new BroadcastChannel("ctms-auth") : null;
|
||||
|
||||
const shouldEnforceIdleTimeout = () => !isTauriRuntime();
|
||||
|
||||
const getTimeoutAt = (session: ReturnType<typeof useSessionStore>) =>
|
||||
session.lastUserActiveAt + IDLE_TIMEOUT_MINUTES * 60 * 1000;
|
||||
|
||||
const reconcileSessionState = (now: number = Date.now()) => {
|
||||
const session = useSessionStore();
|
||||
if (!shouldEnforceIdleTimeout()) {
|
||||
session.clearTimeoutWarning();
|
||||
return true;
|
||||
}
|
||||
if (now >= getTimeoutAt(session)) {
|
||||
void forceLogout(LOGOUT_REASON_TIMEOUT);
|
||||
return false;
|
||||
@@ -70,6 +77,10 @@ const scheduleIdleCheck = () => {
|
||||
window.clearTimeout(idleTimer);
|
||||
}
|
||||
const session = useSessionStore();
|
||||
if (!shouldEnforceIdleTimeout()) {
|
||||
session.clearTimeoutWarning();
|
||||
return;
|
||||
}
|
||||
const now = Date.now();
|
||||
const timeoutAt = getTimeoutAt(session);
|
||||
const warningAt = timeoutAt - TIMEOUT_WARNING_SECONDS * 1000;
|
||||
@@ -224,7 +235,7 @@ export const startTokenKeepAlive = () => {
|
||||
const remaining = expAt - Date.now();
|
||||
const timeoutMs = IDLE_TIMEOUT_MINUTES * 60 * 1000;
|
||||
const active = Date.now() - session.lastUserActiveAt < timeoutMs;
|
||||
if (active && remaining < EXTEND_EARLY_SECONDS * 1000) {
|
||||
if ((!shouldEnforceIdleTimeout() || active) && remaining < EXTEND_EARLY_SECONDS * 1000) {
|
||||
void extendAccessToken("early");
|
||||
}
|
||||
}, 10000);
|
||||
|
||||
Reference in New Issue
Block a user