-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenRecorder.vencordDesktop.tsx
98 lines (91 loc) · 3.67 KB
/
screenRecorder.vencordDesktop.tsx
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
/*
* Vencord, a Discord client mod
* Copyright (c) 2023 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { addContextMenuPatch, removeContextMenuPatch } from "@api/ContextMenu";
import { ScreenshareIcon } from "@components/Icons";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { Menu, UploadHandler } from "@webpack/common";
const OptionClasses = findByPropsLazy("optionName", "optionIcon", "optionLabel");
let recoder: MediaRecorder;
export default definePlugin({
name: "ScreenRecorder",
description: "epic screen recorder lol",
authors: [Devs.AutumnVN],
contextMenus: {
"channel-attach": startRecording
}
});
function startRecording(children) {
children.push(
<Menu.MenuItem
id="start-recording"
label={
<div className={OptionClasses.optionLabel}>
<ScreenshareIcon className={OptionClasses.optionIcon} height={24} width={24} />
<div className={OptionClasses.optionName}>Start Recording</div>
</div>
}
action={async () => {
const stream = await navigator.mediaDevices.getDisplayMedia({ audio: true, video: { frameRate: { ideal: 60 } } });
recoder = new MediaRecorder(stream);
recoder.start();
removeContextMenuPatch("channel-attach", startRecording);
addContextMenuPatch("channel-attach", uploadRecording);
addContextMenuPatch("channel-attach", saveRecording);
}}
/>
);
}
function uploadRecording(children, props) {
children.push(
<Menu.MenuItem
id="upload-recording"
label={
<div className={OptionClasses.optionLabel}>
<ScreenshareIcon className={OptionClasses.optionIcon} height={24} width={24} />
<div className={OptionClasses.optionName}>Upload Recording</div>
</div>
}
action={() => {
recoder.ondataavailable = e => {
const file = new File([e.data], "watch if cute.webm", { type: "video/webm" });
UploadHandler.promptToUpload([file], props.channel, 0);
};
recoder.stop();
removeContextMenuPatch("channel-attach", uploadRecording);
removeContextMenuPatch("channel-attach", saveRecording);
addContextMenuPatch("channel-attach", startRecording);
}}
/>
);
}
function saveRecording(children, props) {
children.push(
<Menu.MenuItem
id="save-recording"
label={
<div className={OptionClasses.optionLabel}>
<ScreenshareIcon className={OptionClasses.optionIcon} height={24} width={24} />
<div className={OptionClasses.optionName}>Save Recording</div>
</div>
}
action={() => {
recoder.ondataavailable = e => {
const file = new File([e.data], "watch if cute.webm", { type: "video/webm" });
const a = document.createElement("a");
a.href = URL.createObjectURL(file);
a.download = "watch if cute.webm";
a.click();
};
recoder.stop();
removeContextMenuPatch("channel-attach", uploadRecording);
removeContextMenuPatch("channel-attach", saveRecording);
addContextMenuPatch("channel-attach", startRecording);
}}
/>
);
}