Plugin

KeepCurrentChannel

Attempt to navigate to the channel you were in before switching accounts or loading Discord.

Utility Organisation
index.ts
Download

Source

src/plugins/keepCurrentChannel/index.ts
1/*
2 * FiveCord — a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import * as DataStore from "@api/DataStore";
8import { Devs } from "@utils/constants";
9import definePlugin from "@utils/types";
10import { ChannelRouter, ChannelStore, NavigationRouter, SelectedChannelStore, SelectedGuildStore } from "@webpack/common";
11
12export interface LogoutEvent {
13 type: "LOGOUT";
14 isSwitchingAccount: boolean;
15}
16
17interface ChannelSelectEvent {
18 type: "CHANNEL_SELECT";
19 channelId: string | null;
20 guildId: string | null;
21}
22
23interface PreviousChannel {
24 guildId: string | null;
25 channelId: string | null;
26}
27
28let isSwitchingAccount = false;
29let previousCache: PreviousChannel | undefined;
30
31export default definePlugin({
32 name: "KeepCurrentChannel",
33 description: "Attempt to navigate to the channel you were in before switching accounts or loading Discord.",
34 tags: ["Utility", "Organisation"],
35 authors: [Devs.Nuckyz],
36
37 patches: [
38 {
39 find: '"Switching accounts"',
40 replacement: {
41 match: /goHomeAfterSwitching:\i/,
42 replace: "goHomeAfterSwitching:!1"
43 }
44 }
45 ],
46
47 flux: {
48 LOGOUT(e: LogoutEvent) {
49 ({ isSwitchingAccount } = e);
50 },
51
52 CONNECTION_OPEN() {
53 if (!isSwitchingAccount) return;
54 isSwitchingAccount = false;
55
56 if (previousCache?.channelId) {
57 if (ChannelStore.hasChannel(previousCache.channelId)) {
58 ChannelRouter.transitionToChannel(previousCache.channelId);
59 } else {
60 NavigationRouter.transitionToGuild("@me");
61 }
62 }
63 },
64
65 async CHANNEL_SELECT({ guildId, channelId }: ChannelSelectEvent) {
66 if (isSwitchingAccount) return;
67
68 previousCache = {
69 guildId,
70 channelId
71 };
72 await DataStore.set("KeepCurrentChannel_previousData", previousCache);
73 }
74 },
75
76 async start() {
77 previousCache = await DataStore.get<PreviousChannel>("KeepCurrentChannel_previousData");
78 if (!previousCache) {
79 previousCache = {
80 guildId: SelectedGuildStore.getGuildId(),
81 channelId: SelectedChannelStore.getChannelId() ?? null
82 };
83
84 await DataStore.set("KeepCurrentChannel_previousData", previousCache);
85 } else if (previousCache.channelId) {
86 ChannelRouter.transitionToChannel(previousCache.channelId);
87 }
88 }
89});
90