feat: detach Sidebar patches as they
causes crash on settings page on newest alpha
This commit is contained in:
parent
59f239f7c1
commit
ecd97c7018
4 changed files with 4 additions and 80 deletions
|
|
@ -26,7 +26,6 @@ import {
|
||||||
friendInviteRevokeCommand,
|
friendInviteRevokeCommand,
|
||||||
} from "./src/commands/friendinvites";
|
} from "./src/commands/friendinvites";
|
||||||
import settings from "./settings/settings";
|
import settings from "./settings/settings";
|
||||||
import patchSidebar from "./sidebar";
|
|
||||||
|
|
||||||
if (!storage.factSettings) {
|
if (!storage.factSettings) {
|
||||||
storage.factSettings = {
|
storage.factSettings = {
|
||||||
|
|
@ -77,10 +76,6 @@ if (!storage.hiddenSettings) {
|
||||||
konochanBypassNsfw: false,
|
konochanBypassNsfw: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// sidebar enabled setting
|
|
||||||
if (storage.sidebarEnabled === undefined) {
|
|
||||||
storage.sidebarEnabled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const commandMap = {
|
const commandMap = {
|
||||||
catfact: catFactCommand,
|
catfact: catFactCommand,
|
||||||
|
|
@ -107,22 +102,11 @@ const commandMap = {
|
||||||
};
|
};
|
||||||
|
|
||||||
let commands: Array<() => void> = [];
|
let commands: Array<() => void> = [];
|
||||||
let sidebarUnpatch: (() => void) | undefined;
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
onLoad: () => {
|
onLoad: () => {
|
||||||
console.log("[Commands Plugin] Loading...");
|
console.log("[Commands Plugin] Loading...");
|
||||||
|
|
||||||
// Patch sidebar if enabled
|
|
||||||
if (storage.sidebarEnabled !== false) {
|
|
||||||
try {
|
|
||||||
sidebarUnpatch = patchSidebar();
|
|
||||||
console.log("[Commands Plugin] Sidebar patched successfully");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[Commands Plugin] Failed to patch sidebar:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register commands
|
// Register commands
|
||||||
for (const [key, command] of Object.entries(commandMap)) {
|
for (const [key, command] of Object.entries(commandMap)) {
|
||||||
if (storage.enabledCommands[key]) {
|
if (storage.enabledCommands[key]) {
|
||||||
|
|
@ -150,17 +134,6 @@ export default {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
commands = [];
|
commands = [];
|
||||||
|
|
||||||
// Unpatch sidebar
|
|
||||||
if (sidebarUnpatch) {
|
|
||||||
try {
|
|
||||||
sidebarUnpatch();
|
|
||||||
sidebarUnpatch = undefined;
|
|
||||||
console.log("[Commands Plugin] Sidebar unpatched");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[Commands Plugin] Failed to unpatch sidebar:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
settings,
|
settings,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,8 @@ storage.hiddenSettings ??= {
|
||||||
konochanBypassNsfw: false,
|
konochanBypassNsfw: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sidebar setting (enabled by default)
|
// Sidebar setting
|
||||||
storage.sidebarEnabled ??= true;
|
storage.sidebarEnabled ??= false;
|
||||||
|
|
||||||
// MAIN SETTINGS COMPONENT
|
// MAIN SETTINGS COMPONENT
|
||||||
export default function Settings() {
|
export default function Settings() {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import { UserStore } from "./modules";
|
||||||
import { serviceFactory } from "./services/ServiceFactory";
|
import { serviceFactory } from "./services/ServiceFactory";
|
||||||
|
|
||||||
import Settings from "./ui/pages/Settings";
|
import Settings from "./ui/pages/Settings";
|
||||||
import patchSidebar from "./sidebar";
|
|
||||||
|
|
||||||
export const pluginState = {
|
export const pluginState = {
|
||||||
pluginStopped: false,
|
pluginStopped: false,
|
||||||
|
|
@ -22,8 +21,6 @@ export const pluginState = {
|
||||||
lastTrackUrl?: string;
|
lastTrackUrl?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
let sidebarUnpatch: (() => void) | undefined;
|
|
||||||
|
|
||||||
// Initialize default settings
|
// Initialize default settings
|
||||||
const defaultSettings: LFMSettings = Constants.DEFAULT_SETTINGS;
|
const defaultSettings: LFMSettings = Constants.DEFAULT_SETTINGS;
|
||||||
Object.keys(defaultSettings).forEach((key) => {
|
Object.keys(defaultSettings).forEach((key) => {
|
||||||
|
|
@ -31,8 +28,6 @@ Object.keys(defaultSettings).forEach((key) => {
|
||||||
plugin.storage[key] ?? defaultSettings[key as keyof typeof defaultSettings];
|
plugin.storage[key] ?? defaultSettings[key as keyof typeof defaultSettings];
|
||||||
});
|
});
|
||||||
|
|
||||||
plugin.storage.addToSidebar ??= false;
|
|
||||||
|
|
||||||
export const currentSettings = new Proxy(plugin.storage, {
|
export const currentSettings = new Proxy(plugin.storage, {
|
||||||
get(target, prop: string) {
|
get(target, prop: string) {
|
||||||
return target[prop];
|
return target[prop];
|
||||||
|
|
@ -124,16 +119,6 @@ export default {
|
||||||
console.log("[Multi-Scrobbler] Loading...");
|
console.log("[Multi-Scrobbler] Loading...");
|
||||||
pluginState.pluginStopped = false;
|
pluginState.pluginStopped = false;
|
||||||
|
|
||||||
// Patch sidebar if enabled
|
|
||||||
if (currentSettings.addToSidebar !== false) {
|
|
||||||
try {
|
|
||||||
sidebarUnpatch = patchSidebar();
|
|
||||||
console.log("[Multi-Scrobbler] Sidebar patched successfully");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[Multi-Scrobbler] Failed to patch sidebar:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
validateAndInitialize();
|
validateAndInitialize();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -141,50 +126,15 @@ export default {
|
||||||
console.log("[Multi-Scrobbler] Unloading...");
|
console.log("[Multi-Scrobbler] Unloading...");
|
||||||
pluginState.pluginStopped = true;
|
pluginState.pluginStopped = true;
|
||||||
|
|
||||||
// Unpatch sidebar
|
|
||||||
if (sidebarUnpatch) {
|
|
||||||
try {
|
|
||||||
sidebarUnpatch();
|
|
||||||
sidebarUnpatch = undefined;
|
|
||||||
console.log("[Multi-Scrobbler] Sidebar unpatched");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[Multi-Scrobbler] Failed to unpatch sidebar:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
},
|
},
|
||||||
|
|
||||||
async onSettingsUpdate(newSettings: any) {
|
async onSettingsUpdate(newSettings: any) {
|
||||||
const oldService = currentSettings.service;
|
const oldService = currentSettings.service;
|
||||||
const newService = newSettings.service;
|
const newService = newSettings.service;
|
||||||
const oldSidebar = currentSettings.addToSidebar;
|
|
||||||
const newSidebar = newSettings.addToSidebar;
|
|
||||||
|
|
||||||
Object.assign(currentSettings, newSettings);
|
Object.assign(currentSettings, newSettings);
|
||||||
|
|
||||||
// Check if sidebar setting changed
|
|
||||||
if (oldSidebar !== newSidebar) {
|
|
||||||
if (newSidebar) {
|
|
||||||
try {
|
|
||||||
sidebarUnpatch = patchSidebar();
|
|
||||||
console.log("[Multi-Scrobbler] Sidebar enabled");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("[Multi-Scrobbler] Failed to enable sidebar:", error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (sidebarUnpatch) {
|
|
||||||
try {
|
|
||||||
sidebarUnpatch();
|
|
||||||
} catch (e) {
|
|
||||||
console.error("[Multi-Scrobbler] Failed to unpatch sidebar:", e);
|
|
||||||
}
|
|
||||||
sidebarUnpatch = undefined;
|
|
||||||
console.log("[Multi-Scrobbler] Sidebar disabled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldService !== newService && newService) {
|
if (oldService !== newService && newService) {
|
||||||
console.log(`[Multi-Scrobbler] Service changed from ${oldService || "none"} to ${newService}`);
|
console.log(`[Multi-Scrobbler] Service changed from ${oldService || "none"} to ${newService}`);
|
||||||
try {
|
try {
|
||||||
|
|
@ -212,4 +162,4 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -283,6 +283,7 @@ export default function Settings() {
|
||||||
setStorage("addToSidebar", value);
|
setStorage("addToSidebar", value);
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}}
|
}}
|
||||||
|
disabled={true}
|
||||||
/>
|
/>
|
||||||
</TableRowGroup>
|
</TableRowGroup>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue