Plugin

CustomIdle

Allows you to set the time before Discord goes idle (or disable auto-idle)

Activity Customisation
index.ts
Download

Source

src/plugins/customIdle/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 { currentNotice, noticesQueue, popNotice, showNotice } from "@api/Notices";
8import { definePluginSettings } from "@api/Settings";
9import { Devs } from "@utils/constants";
10import definePlugin, { makeRange, OptionType } from "@utils/types";
11import { FluxDispatcher } from "@webpack/common";
12
13const settings = definePluginSettings({
14 idleTimeout: {
15 description: "Minutes before Discord goes idle (0 to disable auto-idle)",
16 type: OptionType.SLIDER,
17 markers: makeRange(0, 60, 5),
18 default: 10,
19 stickToMarkers: false,
20 restartNeeded: true class="ts-cmt">// Because of the setInterval patch
21 },
22 remainInIdle: {
23 description: "When you come back to Discord, remain idle until you confirm you want to go online",
24 type: OptionType.BOOLEAN,
25 default: true
26 }
27});
28
29export default definePlugin({
30 name: "CustomIdle",
31 description: "Allows you to set the time before Discord goes idle (or disable auto-idle)",
32 tags: ["Activity", "Customisation"],
33 authors: [Devs.newwares],
34 settings,
35 patches: [
36 {
37 find: 'type:"IDLE",idle:',
38 replacement: [
39 {
40 match: /(?<=Date\.now\(\)-\i>)\i\.\i\|\|/,
41 replace: "$self.getIdleTimeout()||"
42 },
43 {
44 match: /Math\.min\((\i\*\i\.\i\.\i\.SECOND),\i\.\i\)/,
45 replace: "$1" class="ts-cmt">// Decouple idle from afk (phone notifications will remain at user setting or 10 min maximum)
46 },
47 {
48 match: /\i\.\i\.dispatch\({type:"IDLE",idle:!1}\)/,
49 replace: "$self.handleOnline()"
50 }
51 ]
52 }
53 ],
54
55 handleOnline() {
56 if (!settings.store.remainInIdle) {
57 FluxDispatcher.dispatch({
58 type: "IDLE",
59 idle: false
60 });
61 return;
62 }
63
64 const backOnlineMessage = "Welcome back! Click the button to go online. Click the X to stay idle until reload.";
65 if (
66 currentNotice?.[1] === backOnlineMessage ||
67 noticesQueue.some(([, noticeMessage]) => noticeMessage === backOnlineMessage)
68 ) return;
69
70 showNotice(backOnlineMessage, "Exit idle", () => {
71 popNotice();
72 FluxDispatcher.dispatch({
73 type: "IDLE",
74 idle: false
75 });
76 });
77 },
78
79 getIdleTimeout() { class="ts-cmt">// milliseconds, default is 6e5
80 const { idleTimeout } = settings.store;
81 return idleTimeout === 0 ? Infinity : idleTimeout * 60000;
82 }
83});
84