mirror of
https://github.com/vector-im/element-call.git
synced 2024-11-15 00:04:59 +08:00
couple of cleanups
ModalProps fixes LogEntry interface missing return promise
This commit is contained in:
parent
190c57e853
commit
23098131b8
@ -50,8 +50,8 @@ const MAX_LOG_SIZE = 1024 * 1024 * 5; // 5 MB
|
||||
|
||||
interface LogEntry {
|
||||
id: string;
|
||||
lines: Array<string>;
|
||||
index: number;
|
||||
lines: string;
|
||||
index?: number;
|
||||
}
|
||||
|
||||
interface Cursor {
|
||||
@ -59,9 +59,6 @@ interface Cursor {
|
||||
ts: number;
|
||||
}
|
||||
|
||||
// interface CustomEventTarget extends EventTarget {
|
||||
// result: Cursor;
|
||||
// }
|
||||
export class ConsoleLogger {
|
||||
logs = "";
|
||||
|
||||
@ -86,6 +83,7 @@ export class ConsoleLogger {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// these functions get overwritten by the monkey patch
|
||||
error(...args: unknown[]): void {}
|
||||
warn(...args: unknown[]): void {}
|
||||
@ -203,7 +201,7 @@ export class IndexedDBLogStore {
|
||||
logObjStore.createIndex("id", "id", { unique: false });
|
||||
|
||||
logObjStore.add(
|
||||
this.generateLogEntry([new Date() + " ::: Log database was created."])
|
||||
this.generateLogEntry(new Date() + " ::: Log database was created.")
|
||||
);
|
||||
|
||||
const lastModifiedStore = db.createObjectStore("logslastmod", {
|
||||
@ -273,7 +271,7 @@ export class IndexedDBLogStore {
|
||||
// @ts-ignore
|
||||
reject(new Error("Failed to write logs: " + event.target.errorCode));
|
||||
};
|
||||
objStore.add(this.generateLogEntry(lines.split("\n")));
|
||||
objStore.add(this.generateLogEntry(lines));
|
||||
const lastModStore = txn.objectStore("logslastmod");
|
||||
lastModStore.put(this.generateLastModifiedTime());
|
||||
}).then(() => {
|
||||
@ -424,7 +422,7 @@ export class IndexedDBLogStore {
|
||||
return logs;
|
||||
}
|
||||
|
||||
generateLogEntry(lines: string[]): LogEntry {
|
||||
generateLogEntry(lines: string): LogEntry {
|
||||
return {
|
||||
id: this.id,
|
||||
lines: lines,
|
||||
@ -432,7 +430,7 @@ export class IndexedDBLogStore {
|
||||
};
|
||||
}
|
||||
|
||||
generateLastModifiedTime() {
|
||||
generateLastModifiedTime(): Cursor {
|
||||
return {
|
||||
id: this.id,
|
||||
ts: Date.now(),
|
||||
@ -539,7 +537,7 @@ export function tryInitStorage(): Promise<void> {
|
||||
return global.mx_rage_initStoragePromise;
|
||||
}
|
||||
|
||||
export function flush() {
|
||||
export function flush(): Promise<void> {
|
||||
if (!global.mx_rage_store) {
|
||||
return;
|
||||
}
|
||||
@ -550,7 +548,7 @@ export function flush() {
|
||||
* Clean up old logs.
|
||||
* @return {Promise} Resolves if cleaned logs.
|
||||
*/
|
||||
export async function cleanup() {
|
||||
export async function cleanup(): Promise<void> {
|
||||
if (!global.mx_rage_store) {
|
||||
return;
|
||||
}
|
||||
@ -560,9 +558,9 @@ export async function cleanup() {
|
||||
/**
|
||||
* Get a recent snapshot of the logs, ready for attaching to a bug report
|
||||
*
|
||||
* @return {Array<{lines: string, id, string}>} list of log data
|
||||
* @return {LogEntry[]} list of log data
|
||||
*/
|
||||
export async function getLogsForReport() {
|
||||
export async function getLogsForReport(): Promise<LogEntry[]> {
|
||||
if (!global.mx_rage_logger) {
|
||||
throw new Error("No console logger, did you forget to call init()?");
|
||||
}
|
||||
@ -571,13 +569,13 @@ export async function getLogsForReport() {
|
||||
if (global.mx_rage_store) {
|
||||
// flush most recent logs
|
||||
await global.mx_rage_store.flush();
|
||||
return await global.mx_rage_store.consume();
|
||||
return (await global.mx_rage_store.consume()) as LogEntry[];
|
||||
} else {
|
||||
return [
|
||||
{
|
||||
lines: global.mx_rage_logger.flush(true),
|
||||
id: "-",
|
||||
},
|
||||
];
|
||||
] as LogEntry[];
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,10 @@ limitations under the License.
|
||||
|
||||
import { useCallback, useContext, useEffect, useState } from "react";
|
||||
import pako from "pako";
|
||||
import { ClientEvent, MatrixClient, MatrixEvent } from "matrix-js-sdk";
|
||||
import { MatrixEvent } from "matrix-js-sdk";
|
||||
import { OverlayTriggerState } from "@react-stately/overlays";
|
||||
import { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client";
|
||||
import { stringToBase } from "matrix-js-sdk/src/utils";
|
||||
|
||||
import { getLogsForReport } from "./rageshake";
|
||||
import { useClient } from "../ClientContext";
|
||||
@ -223,12 +225,7 @@ export function useSubmitRageshake(): {
|
||||
|
||||
for (const entry of logs) {
|
||||
// encode as UTF-8
|
||||
let buf = new TextEncoder().encode(
|
||||
typeof entry.lines == "string"
|
||||
? entry.lines
|
||||
: entry.lines.join("\n")
|
||||
);
|
||||
|
||||
let buf = new TextEncoder().encode(entry.lines);
|
||||
// compress
|
||||
buf = pako.gzip(buf);
|
||||
|
||||
@ -315,14 +312,24 @@ export function useRageshakeRequest(): (
|
||||
|
||||
return sendRageshakeRequest;
|
||||
}
|
||||
interface ModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
}
|
||||
interface ModalPropsWithId extends ModalProps {
|
||||
rageshakeRequestId: string;
|
||||
}
|
||||
|
||||
export function useRageshakeRequestModal(roomId: string): {
|
||||
modalState: OverlayTriggerState;
|
||||
modalProps: any;
|
||||
modalProps: ModalPropsWithId;
|
||||
} {
|
||||
const { modalState, modalProps } = useModalTriggerState();
|
||||
const { modalState, modalProps } = useModalTriggerState() as {
|
||||
modalState: OverlayTriggerState;
|
||||
modalProps: ModalProps;
|
||||
};
|
||||
const client: MatrixClient = useClient().client;
|
||||
const [rageshakeRequestId, setRageshakeRequestId] = useState();
|
||||
const [rageshakeRequestId, setRageshakeRequestId] = useState<string>();
|
||||
|
||||
useEffect(() => {
|
||||
const onEvent = (event: MatrixEvent) => {
|
||||
|
Loading…
Reference in New Issue
Block a user