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