forked from yofukashino/BetterDiscordPlugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersistSettings.plugin.js
More file actions
370 lines (334 loc) · 12.3 KB
/
PersistSettings.plugin.js
File metadata and controls
370 lines (334 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/**
* @name PersistSettings
* @author Ahlawat
* @authorId 887483349369765930
* @version 1.0.4
* @invite SgKSKyh9gY
* @description Backs up your settings and restores them in case discord clears them after logouts or for other reasons.
* @website https://tharki-god.github.io/
* @source https://github.com/Tharki-God/BetterDiscordPlugins
* @updateUrl https://raw.githubusercontent.com/Tharki-God/BetterDiscordPlugins/master/PersistSettings.plugin.js
*/
/* PersistSettings, a powercord plugin to make sure you never lose your favourites again!
* Copyright (C) 2021 Vendicated
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Ported to BetterDiscord
* Copyright 2022 Ahlawat
*/
/*@cc_on
@if (@_jscript)
// Offer to self-install for clueless users that try to run this directly.
var shell = WScript.CreateObject("WScript.Shell");
var fs = new ActiveXObject("Scripting.FileSystemObject");
var pathPlugins = shell.ExpandEnvironmentStrings("%APPDATA%\BetterDiscord\plugins");
var pathSelf = WScript.ScriptFullName;
// Put the user at ease by addressing them in the first person
shell.Popup("It looks like you've mistakenly tried to run me directly. \n(Don't do that!)", 0, "I'm a plugin for BetterDiscord", 0x30);
if (fs.GetParentFolderName(pathSelf) === fs.GetAbsolutePathName(pathPlugins)) {
shell.Popup("I'm in the correct folder already.", 0, "I'm already installed", 0x40);
} else if (!fs.FolderExists(pathPlugins)) {
shell.Popup("I can't find the BetterDiscord plugins folder.\nAre you sure it's even installed?", 0, "Can't install myself", 0x10);
} else if (shell.Popup("Should I copy myself to BetterDiscord's plugins folder for you?", 0, "Do you need some help?", 0x34) === 6) {
fs.CopyFile(pathSelf, fs.BuildPath(pathPlugins, fs.GetFileName(pathSelf)), true);
// Show the user where to put plugins in the future
shell.Exec("explorer " + pathPlugins);
shell.Popup("I'm installed!", 0, "Successfully installed", 0x40);
}
WScript.Quit();
@else@*/
module.exports = (() => {
const config = {
info: {
name: "PersistSettings",
authors: [
{
name: "Ahlawat",
discord_id: "887483349369765930",
github_username: "Tharki-God",
},
],
version: "1.0.4",
description:
"Backs up your settings and restores them in case discord clears them after logouts or for other reasons",
github: "https://github.com/Tharki-God/BetterDiscordPlugins",
github_raw:
"https://raw.githubusercontent.com/Tharki-God/BetterDiscordPlugins/master/PersistSettings.plugin.js",
},
changelog: [
{
title: "v0.0.1",
items: [
"Idea in mind"
]
},
{
title: "v0.0.5",
items: [
"Base Model"
]
},
{
title: "Initial Release v1.0.0",
items: [
"This is the initial release of the plugin :)",
"Fuck You Discord (>'-'<)"
]
},
{
title: "v1.0.1",
items: [
"Bug Fixes",
"Library Handler fixed"
]
},
],
main: "PersistSettings.plugin.js",
};
return !global.ZeresPluginLibrary
? class {
constructor() {
this._config = config;
}
getName() {
return config.info.name;
}
getAuthor() {
return config.info.authors.map((a) => a.name).join(", ");
}
getDescription() {
return config.info.description;
}
getVersion() {
return config.info.version;
}
load() {
try {
global.ZeresPluginLibrary.PluginUpdater.checkForUpdate(config.info.name, config.info.version, config.info.github_raw);
}
catch (err) {
console.error(this.getName(), "Plugin Updater could not be reached.", err);
}
BdApi.showConfirmationModal(
"Library Missing",
`The library plugin needed for ${config.info.name} is missing. Please click Download Now to install it.`,
{
confirmText: "Download Now",
cancelText: "Cancel",
onConfirm: () => {
require("request").get(
"https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js",
async (error, response, body) => {
if (error) {
return BdApi.showConfirmationModal("Error Downloading",
[
"Library plugin download failed. Manually install plugin library from the link below.",
BdApi.React.createElement("a", { href: "https://rauenzi.github.io/BDPluginLibrary/release/0PluginLibrary.plugin.js", target: "_blank" }, "Plugin Link")
],
); }
await new Promise((r) =>
require("fs").writeFile(
require("path").join(
BdApi.Plugins.folder,
"0PluginLibrary.plugin.js"
),
body,
r
)
);
}
);
},
}
);
}
start() { }
stop() { }
}
: (([Plugin, Library]) => {
const { DiscordModules, Patcher, WebpackModules } = Library;
const FluxDispatcher = WebpackModules.getByProps("dirtyDispatch");
const AccessiblityEvents = [
'ACCESSIBILITY_SET_MESSAGE_GROUP_SPACING',
'ACCESSIBILITY_SET_PREFERS_REDUCED_MOTION',
'ACCESSIBILITY_DESATURATE_ROLES_TOGGLE',
'ACCESSIBILITY_DARK_SIDEBAR_TOGGLE',
'ACCESSIBILITY_SET_SATURATION',
'ACCESSIBILITY_SET_FONT_SIZE',
'ACCESSIBILITY_SET_ZOOM'
];
const VoiceEvents = [
'AUDIO_SET_DISPLAY_SILENCE_WARNING',
'AUDIO_SET_AUTOMATIC_GAIN_CONTROL',
'MEDIA_ENGINE_SET_HARDWARE_H264',
'MEDIA_ENGINE_SET_VIDEO_DEVICE',
'AUDIO_SET_NOISE_SUPPRESSION',
'AUDIO_SET_ECHO_CANCELLATION',
'MEDIA_ENGINE_SET_OPEN_H264',
'MEDIA_ENGINE_SET_AEC_DUMP',
'AUDIO_SET_OUTPUT_VOLUME',
'AUDIO_SET_OUTPUT_DEVICE',
'AUDIO_SET_INPUT_DEVICE',
'AUDIO_SET_ATTENUATION',
'AUDIO_SET_MODE',
'AUDIO_SET_QOS'
];
const NotificationEvents = [
'NOTIFICATIONS_SET_DISABLE_UNREAD_BADGE',
'NOTIFICATIONS_SET_PERMISSION_STATE',
'NOTIFICATIONS_SET_DISABLED_SOUNDS',
'NOTIFICATIONS_SET_TASKBAR_FLASH',
'NOTIFICATIONS_SET_DESKTOP_TYPE',
'NOTIFICATIONS_SET_TTS_TYPE'
];
return class PersistSettings extends Plugin {
constructor(...args) {
super(...args);
this.restore = this.restore.bind(this);
this.backupVoice = this.backupVoice.bind(this);
this.backupKeybinds = this.backupKeybinds.bind(this);
this.backupSettings = this.backupSettings.bind(this);
this.backupExperiments = this.backupExperiments.bind(this);
this.backupAccessibility = this.backupAccessibility.bind(this);
this.backupNotifications = this.backupNotifications.bind(this);
}
async onStart()
{ this.firstRun = BdApi.loadData(config.info.name, "firstRun") ?? true;
this.experiments = await WebpackModules.getByProps('hasRegisteredExperiment');
this.notifications = await WebpackModules.getByProps('getDesktopType');
this.accessibility = await WebpackModules.getByProps('isZoomedIn');
this.storage = await WebpackModules.getByProps('ObjectStorage');
this.keybinds = await WebpackModules.getByProps('hasKeybind');
this.voice = await WebpackModules.getByProps('isDeaf');
FluxDispatcher.subscribe('CONNECTION_OPEN', this.restore);
FluxDispatcher.subscribe('KEYBINDS_ADD_KEYBIND', this.backupKeybinds);
FluxDispatcher.subscribe('KEYBINDS_SET_KEYBIND', this.backupKeybinds);
FluxDispatcher.subscribe('USER_SETTINGS_UPDATE', this.backupSettings);
FluxDispatcher.subscribe('KEYBINDS_DELETE_KEYBIND', this.backupKeybinds);
FluxDispatcher.subscribe('KEYBINDS_ENABLE_ALL_KEYBINDS', this.backupKeybinds);
FluxDispatcher.subscribe('EXPERIMENT_OVERRIDE_BUCKET', this.backupExperiments);
for (const event of AccessiblityEvents) {
FluxDispatcher.subscribe(event, this.backupAccessibility);
}
for (const event of VoiceEvents) {
FluxDispatcher.subscribe(event, this.backupVoice);
}
for (const event of NotificationEvents) {
FluxDispatcher.subscribe(event, this.backupNotifications);
}
// Sometimes CONNECTION_OPEN will fire, other times not soooo lets just do this hack teehee
setTimeout(() => this.didRestore || this.restore(), 1000 * 10);
if (this.firstRun) {
this.backupKeybinds;
this.backupSettings;
this.backupExperiments;
this.backupAccessibility;
this.backupVoice;
this.backupNotifications;
BdApi.saveData(config.info.name, "firstRun", false);
}
}
onStop() {
FluxDispatcher.unsubscribe('CONNECTION_OPEN', this.restore);
FluxDispatcher.unsubscribe('KEYBINDS_ADD_KEYBIND', this.backupKeybinds);
FluxDispatcher.unsubscribe('KEYBINDS_SET_KEYBIND', this.backupKeybinds);
FluxDispatcher.unsubscribe('USER_SETTINGS_UPDATE', this.backupSettings);
FluxDispatcher.unsubscribe('KEYBINDS_DELETE_KEYBIND', this.backupKeybinds);
FluxDispatcher.unsubscribe('KEYBINDS_ENABLE_ALL_KEYBINDS', this.backupKeybinds);
FluxDispatcher.unsubscribe('EXPERIMENT_OVERRIDE_BUCKET', this.backupExperiments);
for (const event of AccessiblityEvents) {
FluxDispatcher.unsubscribe(event, this.backupAccessibility);
}
for (const event of VoiceEvents) {
FluxDispatcher.unsubscribe(event, this.backupVoice);
}
for (const event of NotificationEvents) {
FluxDispatcher.unsubscribe(event, this.backupNotifications);
}
}
backupKeybinds() {
const keybinds = this.keybinds.getState();
BdApi.saveData(config.info.name, "keybinds", keybinds);
}
backupAccessibility() {
const accessibility = this.accessibility.getState();
BdApi.saveData(config.info.name, "accessibility", accessibility);
}
backupNotifications() {
const notifications = this.notifications.getState();
BdApi.saveData(config.info.name, "notifications", notifications);
}
backupExperiments() {
const experiments = this.experiments.getSerializedState()?.experimentOverrides;
BdApi.saveData(config.info.name, "experiments", experiments);
}
backupVoice() {
const voice = this.voice.getState()?.settingsByContext;
BdApi.saveData(config.info.name, "voice", voice);
}
backupSettings() {
this.backupVoice();
this.backupKeybinds();
this.backupExperiments();
this.backupAccessibility();
this.backupNotifications();
}
restore() {
this.didRestore = true;
this.restoreVoice();
this.restoreKeybinds();
this.restoreExperiments();
this.restoreAccessibility();
this.restoreNotifications();
}
restoreKeybinds() {
const backup = BdApi.loadData(config.info.name, "keybinds");
if (!backup) return void this.backupKeybinds();
const store = {
_version: 2,
_state: backup
};
this.storage.impl.set('keybinds', store);
this.keybinds.initialize(store._state);
}
restoreExperiments() {
const backup = BdApi.loadData(config.info.name, "experiments");
if (!backup) return void this.backupExperiments();
// what the fuck discord...? you can't even spell experiments??
this.storage.impl.set('exerimentOverrides', backup);
this.experiments.initialize(backup);
}
restoreVoice() {
const backup = BdApi.loadData(config.info.name, "voice");
if (!backup) return void this.backupVoice();
this.storage.impl.set('MediaEngineStore', backup);
this.voice.initialize(backup);
}
restoreAccessibility() {
const backup = BdApi.loadData(config.info.name, "accessibility");
if (!backup) return void this.backupAccessibility();
const store = {
_version: 7,
_state: backup
};
this.storage.impl.set('AccessibilityStore', store);
this.accessibility.initialize(store._state);
}
restoreNotifications() {
const backup = BdApi.loadData(config.info.name, "notifications");
if (!backup) return void this.backupNotifications();
const store = {
_version: 1,
_state: backup
};
this.storage.impl.set('notifications', store);
this.notifications.initialize(store._state);
}
};
return plugin(Plugin, Library);
})(global.ZeresPluginLibrary.buildPlugin(config));
})();
/*@end@*/