feat: reset logs on client restart for MLE (#968)
* feat: read the branch name * how did i miss this lmfao
This commit is contained in:
parent
32f7f66fc5
commit
785bf059e9
6 changed files with 43 additions and 16 deletions
|
|
@ -16,8 +16,8 @@ import { type User } from "@vencord/discord-types";
|
|||
import { find, findByCode, findByCodeLazy } from "@webpack";
|
||||
import { Alerts, ChannelStore, ContextMenuApi, FluxDispatcher, GuildStore, Menu, NavigationRouter, React, TabBar, TextInput, Tooltip, useMemo, useRef, useState } from "@webpack/common";
|
||||
|
||||
import { clearMessagesIDB, DBMessageRecord, deleteMessageIDB, deleteMessagesBulkIDB } from "../db";
|
||||
import { cl, settings } from "../index";
|
||||
import { DBMessageRecord, deleteMessageIDB, deleteMessagesBulkIDB } from "../db";
|
||||
import { clearLogs, cl, settings } from "../index";
|
||||
import { LoggedMessage, LoggedMessageJSON } from "../types";
|
||||
import { messageJsonToMessageClass } from "../utils";
|
||||
import { importLogs } from "../utils/settingsUtils";
|
||||
|
|
@ -147,7 +147,7 @@ export function LogsModal({ modalProps, initalQuery }: Props) {
|
|||
confirmVariant: "critical-primary",
|
||||
cancelText: "Cancel",
|
||||
onConfirm: async () => {
|
||||
await clearMessagesIDB();
|
||||
await clearLogs();
|
||||
reset();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -304,14 +304,15 @@ export async function deleteMessagesBulkIDB(message_ids: string[]) {
|
|||
});
|
||||
}
|
||||
|
||||
export async function clearMessagesIDB() {
|
||||
export async function clearMessagesIDB(showToast = true) {
|
||||
cachedMessages.clear();
|
||||
await withDb(void 0, database => database.clear("messages"));
|
||||
|
||||
return withDb(void 0, database => database.clear("messages")).then(() => {
|
||||
Toasts.show({
|
||||
type: Toasts.Type.MESSAGE,
|
||||
message: "Cleared message log database and cache.",
|
||||
id: Toasts.genId()
|
||||
});
|
||||
if (!showToast) return;
|
||||
|
||||
Toasts.show({
|
||||
type: Toasts.Type.MESSAGE,
|
||||
message: "Cleared message log database and cache.",
|
||||
id: Toasts.genId()
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,15 @@ export const Flogger = new Logger("MessageLoggerEnhanced", "#f26c6c");
|
|||
export const cacheSentMessages = new LimitedMap<string, LoggedMessageJSON>();
|
||||
export const cl = classNameFactory("vc-msg-logger-enhanced-");
|
||||
|
||||
let didClearLogsOnStartup = false;
|
||||
|
||||
const cacheThing = findByPropsLazy("commit", "getOrCreate");
|
||||
|
||||
export async function clearLogs(showToast = true) {
|
||||
await idb.clearMessagesIDB(showToast);
|
||||
cacheSentMessages.clear();
|
||||
}
|
||||
|
||||
let oldGetMessage: typeof MessageStore.getMessage;
|
||||
|
||||
const handledMessageIds = new Set();
|
||||
|
|
@ -396,6 +403,15 @@ export default definePlugin({
|
|||
|
||||
Native.init();
|
||||
|
||||
if (settings.store.clearLogsOnRestart && !didClearLogsOnStartup) {
|
||||
try {
|
||||
await clearLogs(false);
|
||||
didClearLogsOnStartup = true;
|
||||
} catch (e) {
|
||||
Flogger.error("Failed to clear logs on restart", e);
|
||||
}
|
||||
}
|
||||
|
||||
const { imageCacheDir, logsDir } = await Native.getSettings();
|
||||
settings.store.imageCacheDir = imageCacheDir;
|
||||
settings.store.logsDir = logsDir;
|
||||
|
|
|
|||
|
|
@ -11,10 +11,9 @@ import { OptionType } from "@utils/types";
|
|||
import { Alerts, useState } from "@webpack/common";
|
||||
import { Settings } from "Vencord";
|
||||
|
||||
import { Native } from ".";
|
||||
import { clearLogs, Native } from ".";
|
||||
import { ImageCacheDir, LogsDir } from "./components/FolderSelectInput";
|
||||
import { openLogModal } from "./components/LogsModal";
|
||||
import { clearMessagesIDB } from "./db";
|
||||
import { blockedExts } from "./list";
|
||||
import { DEFAULT_IMAGE_CACHE_DIR } from "./utils/constants";
|
||||
import { exportLogs, importLogs } from "./utils/settingsUtils";
|
||||
|
|
@ -260,6 +259,13 @@ export const settings = definePluginSettings({
|
|||
component: ExportLogsButton
|
||||
},
|
||||
|
||||
clearLogsOnRestart: {
|
||||
type: OptionType.BOOLEAN,
|
||||
description: "Clear logs when Discord restarts.",
|
||||
default: false,
|
||||
restartNeeded: true,
|
||||
},
|
||||
|
||||
openLogs: {
|
||||
type: OptionType.COMPONENT,
|
||||
description: "Open Logs",
|
||||
|
|
@ -298,7 +304,7 @@ export const settings = definePluginSettings({
|
|||
confirmText: "Clear",
|
||||
cancelText: "Cancel",
|
||||
onConfirm: async () => {
|
||||
await clearMessagesIDB();
|
||||
await clearLogs();
|
||||
},
|
||||
})}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -33,4 +33,8 @@ export class LimitedMap<K, V> {
|
|||
get(key: K) {
|
||||
return this.map.get(key);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.map.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ import { chooseFile as chooseFileWeb } from "@utils/web";
|
|||
import { Toasts } from "@webpack/common";
|
||||
import { showSaveFilePicker } from "native-file-system-adapter";
|
||||
|
||||
import { Native } from "..";
|
||||
import { addMessagesBulkIDB, clearMessagesIDB, iterateAllMessagesIDB } from "../db";
|
||||
import { Native, clearLogs } from "..";
|
||||
import { addMessagesBulkIDB, iterateAllMessagesIDB } from "../db";
|
||||
import { LoggedMessageJSON } from "../types";
|
||||
|
||||
export async function importLogs() {
|
||||
|
|
@ -34,7 +34,7 @@ export async function importLogs() {
|
|||
|
||||
for await (const logItems of iterateLogItems()) {
|
||||
if (!cleared) {
|
||||
await clearMessagesIDB();
|
||||
await clearLogs(false);
|
||||
cleared = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue