Files
discord-decomp/_bundle/endSession.js
T
2026-11-01 12:12:55 +02:00

227 lines
6.4 KiB
JavaScript

// Metro module 6416 (f6417).
import { getIsolationScope, getCurrentScope, getClient, withIsolationScope } from "./Module6395";
import { parseEventHintOrCaptureContext } from "./applyClientOptions_6417";
import { DEBUG_BUILD } from "./Module6396";
import { logger } from "./consoleSandbox_6368";
import { uuid4 } from "./Module6379";
import { timestampInSeconds } from "./Module6382";
import { isThenable } from "./isInstanceOf_6375";
import { DEFAULT_ENVIRONMENT } from "./Module6405";
import { GLOBAL_OBJ } from "./Module6369";
import { closeSession, makeSession, updateSession } from "./updateSession_6391";
const endSession = function endSession() {
const isolationScope = getIsolationScope();
const currentScope = getCurrentScope();
const r7 = currentScope.getSession() || isolationScope.getSession();
if (r7) {
closeSession(r7);
}
const isolationScope2 = getIsolationScope();
const currentScope2 = getCurrentScope();
const client = getClient();
const r32 = currentScope2.getSession() || isolationScope2.getSession();
if (r32 && client) {
client.captureSession(r32);
}
isolationScope.setSession();
currentScope.setSession();
};
export function addEventProcessor(a0) {
getIsolationScope().addEventProcessor(a0);
}
export function captureCheckIn(a0, a1) {
const currentScope = getCurrentScope();
const client = getClient();
if (client) {
if (client.captureCheckIn) {
return client.captureCheckIn(a0, a1, currentScope);
}
if (DEBUG_BUILD) {
logger.warn("Cannot capture check-in. Client does not support sending check-ins.");
}
} else if (DEBUG_BUILD) {
logger.warn("Cannot capture check-in. No client defined.");
}
return uuid4();
}
export function captureEvent(a0, a1) {
return getCurrentScope().captureEvent(a0, a1);
}
export function captureException(a0, a1) {
return getCurrentScope().captureException(a0, parseEventHintOrCaptureContext(a1));
}
export function captureMessage(a0, a1) {
const r5 = typeof a1 === "string" ? a1 : void 0;
const r4 = typeof a1 !== "string" ? {
captureContext: a1
} : void 0;
return getCurrentScope().captureMessage(a0, r5, r4);
}
export function captureSession(r3 = false) {
if (r3) {
endSession();
} else {
const isolationScope = getIsolationScope();
const currentScope = getCurrentScope();
const client = getClient();
const r19 = currentScope.getSession() || isolationScope.getSession();
if (r19 && client) {
client.captureSession(r19);
}
}
}
export async function close(c25856_0) {
let r24;
const client = getClient();
if (client) {
r24 = client.close(c25856_0);
} else {
if (DEBUG_BUILD) {
logger.warn("Cannot flush events and disable SDK. No client defined.");
}
r24 = Promise.resolve(false);
}
return r24;
}
export { endSession };
export async function flush(c25855_0) {
let r24;
const client = getClient();
if (client) {
r24 = client.flush(c25855_0);
} else {
if (DEBUG_BUILD) {
logger.warn("Cannot flush events. No client defined.");
}
r24 = Promise.resolve(false);
}
return r24;
}
export function isEnabled() {
const client = getClient();
return !!client && client.getOptions().enabled !== false && !!client.getTransport();
}
export function isInitialized() {
return !!getClient();
}
export function lastEventId() {
return getIsolationScope().lastEventId();
}
export function setContext(a0, a1) {
getIsolationScope().setContext(a0, a1);
}
export function setExtra(a0, a1) {
getIsolationScope().setExtra(a0, a1);
}
export function setExtras(a0) {
getIsolationScope().setExtras(a0);
}
export function setTag(a0, a1) {
getIsolationScope().setTag(a0, a1);
}
export function setTags(a0) {
getIsolationScope().setTags(a0);
}
export function setUser(a0) {
getIsolationScope().setUser(a0);
}
export function startSession(a0) {
const client = getClient();
const isolationScope = getIsolationScope();
const currentScope = getCurrentScope();
const r23 = client && client.getOptions() || {};
const { release, environment = DEFAULT_ENVIRONMENT } = r23;
const userAgent = (GLOBAL_OBJ.navigator || {}).userAgent;
const r44 = makeSession({
release,
environment,
user: currentScope.getUser() || isolationScope.getUser(),
...userAgent && {
userAgent
},
...a0
});
const session = isolationScope.getSession();
if (session && session.status === "ok") {
updateSession(session, {
status: "exited"
});
}
endSession();
isolationScope.setSession(r44);
currentScope.setSession(r44);
return r44;
}
export function withMonitor(a0, a1, a2) {
let r39;
let monitorSlug, c15718_1, checkInId, c15718_3, finishCheckIn2;
L8: {
monitorSlug = a0;
c15718_1 = a1;
finishCheckIn2 = function finishCheckIn(a0) {
L8: {
const r4 = {
monitorSlug,
status: a0,
checkInId,
duration: timestampInSeconds() - c15718_3
};
const currentScope = getCurrentScope();
const client = getClient();
if (client) {
if (client.captureCheckIn) {
client.captureCheckIn(r4, void 0, currentScope);
break L8;
}
if (DEBUG_BUILD) {
logger.warn("Cannot capture check-in. Client does not support sending check-ins.");
}
} else if (DEBUG_BUILD) {
logger.warn("Cannot capture check-in. No client defined.");
}
uuid4();
}
};
const r9 = {
monitorSlug: a0,
status: "in_progress"
};
const currentScope = getCurrentScope();
const client = getClient();
if (client) {
if (client.captureCheckIn) {
r39 = client.captureCheckIn(r9, a2, currentScope);
break L8;
}
if (DEBUG_BUILD) {
logger.warn("Cannot capture check-in. Client does not support sending check-ins.");
}
} else if (DEBUG_BUILD) {
logger.warn("Cannot capture check-in. No client defined.");
}
r39 = uuid4();
}
checkInId = r39;
c15718_3 = timestampInSeconds();
return withIsolationScope(() => {
let r7;
try {
r7 = c15718_1();
} catch (r25) {
finishCheckIn2("error");
throw r25;
}
if (isThenable(r7)) {
Promise.resolve(r7).then(() => {
finishCheckIn2("ok");
}, (a0) => {
finishCheckIn2("error");
throw a0;
});
} else {
finishCheckIn2("ok");
}
return r7;
});
}