-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.tsx
More file actions
127 lines (116 loc) · 4.29 KB
/
Copy pathindex.tsx
File metadata and controls
127 lines (116 loc) · 4.29 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
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { definePluginSettings } from "@api/Settings";
import { getIntlMessage } from "@utils/discord";
import definePlugin, { OptionType } from "@utils/types";
import { Button, Forms, Menu } from "@webpack/common";
import { ReactElement } from "react";
import { preload, unload } from "./images";
import { cl } from "./ui";
import openQrModal from "./ui/modals/QrModal";
export default definePlugin({
name: "LoginWithQR",
description: "Allows you to login to another device by scanning a login QR code, just like on mobile!",
authors: [
{
name: "Nexpid",
id: 853550207039832084n,
},
],
settings: definePluginSettings({
scanQr: {
type: OptionType.COMPONENT,
description: "Scan a QR code",
component() {
if (!Vencord.Plugins.plugins.LoginWithQR.started)
return (
<Forms.FormText>
Enable the plugin and restart your client to scan a login QR code
</Forms.FormText>
);
return (
<Button size={Button.Sizes.SMALL} onClick={openQrModal}>
{getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")}
</Button>
);
},
},
}),
patches: [
// Prevent paste event from firing when the QRModal is open
{
find: ".clipboardData&&(",
// Find the handleGlobalPaste function and prevent it from firing when the modal is open.
// Does this have any side effects? Maybe
replacement: {
match: /handleGlobalPaste:(\i)/,
replace: "handleGlobalPaste:(...args)=>!$self.qrModalOpen&&$1(...args)",
},
},
// Insert a Scan QR Code button in the My Account tab
{
find: "UserSettingsAccountProfileCard",
replacement: {
// Find the Edit User Profile button and insert our custom button.
// A bit jank, but whatever
match: /,(\(.{1,90}#{intl::USER_SETTINGS_EDIT_USER_PROFILE}\)}\))/,
replace: ",$self.insertScanQrButton($1)",
},
},
// Insert a Scan QR Code MenuItem in the Swith Accounts popout
{
find: 'id:"manage-accounts"',
replacement: {
match: /(id:"manage-accounts",.*?)}\)\)(,\i)/,
replace: "$1}),$self.ScanQrMenuItem)$2"
}
},
// Insert a Scan QR Code button in the Settings sheet
{
find: "useGenerateUserSettingsSections",
replacement: {
match: /\.CONNECTIONS/,
replace: "$&,\"SCAN_QR_CODE\""
}
},
// Insert a Scan QR Code button in the Settings sheet (part 2)
{
find: ".PRIVACY_ENCRYPTION_VERIFIED_DEVICES_V2]",
replacement: {
match: /\.CLIPS]:{.*?},/,
replace: "$&\"SCAN_QR_CODE\":$self.ScanQrSettingsSheet,"
}
}
],
qrModalOpen: false,
insertScanQrButton: (button: ReactElement) => (
<div className={cl("settings-btns")}>
<Button size={Button.Sizes.SMALL} onClick={openQrModal}>
{getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")}
</Button>
{button}
</div>
),
get ScanQrMenuItem() {
return <Menu.MenuItem id="scan-qr" label={getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")} action={openQrModal} />;
},
get ScanQrSettingsSheet() {
return {
section: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE"),
onClick: openQrModal,
searchableTitles: [getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")],
label: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE"),
ariaLabel: getIntlMessage("USER_SETTINGS_SCAN_QR_CODE")
};
},
start() {
// Preload images
preload();
},
stop() {
unload?.();
},
});