Skip to content

Commit 8d83c1d

Browse files
committed
1.4.3 Antied
Added 2 new option and alternative way to change alpha value, fixes some issue, refactor updateRows and fluxdispatcher
1 parent e49aa30 commit 8d83c1d

File tree

12 files changed

+599
-577
lines changed

12 files changed

+599
-577
lines changed

angel/antied/Settings.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useProxy } from "@vendetta/storage";
44
import { storage } from "@vendetta/plugin";
55
import { semanticColors } from "@vendetta/ui";
66
import { Forms, General } from "@vendetta/ui/components";
7+
import { getAssetIDByName } from "@vendetta/ui/assets"
78

89
import PatchesComponent from './components/patches';
910
import TextComponent from './components/texts';
@@ -150,13 +151,13 @@ export default function SettingPage() {
150151
<FormRow
151152
label={element?.label}
152153
subLabel={element?.subLabel}
154+
onPress={() => {
155+
storage.setting[element?.id] = !storage.setting[element?.id];
156+
}}
153157
trailing={
154-
<FormSwitch
155-
value={storage.setting[element?.id]}
156-
onValueChange={(value) => {
157-
storage.setting[element?.id] = value
158-
}}
159-
/>
158+
(storage.setting[element?.id] == true) ?
159+
(<FormRow.Icon source={getAssetIDByName("ic_arrow_down")} />) :
160+
(<FormRow.Icon source={getAssetIDByName("ic_arrow_right")} />)
160161
}
161162
/>
162163
{

angel/antied/components/colorpick.jsx

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { colorConverter, convert, openSheet, transparentBase64 } from "../../../
1111

1212
const CustomColorPickerActionSheet = findByName("CustomColorPickerActionSheet");
1313

14-
const { alphaToHex, hexAlphaToPercent, toPercentage, toDecimal, formatDecimal } = convert;
14+
const { alphaToHex, hexAlphaToPercent } = convert;
1515

1616
const { ScrollView, View, Text, TouchableOpacity, TextInput, Pressable, Image, Animated } = General;
1717
const { FormLabel, FormIcon, FormArrow, FormRow, FormSwitch, FormSwitchRow, FormSection, FormDivider, FormInput, FormSliderRow } = Forms;
@@ -40,16 +40,18 @@ const customizeableColors = [
4040
export default function ColorPickComponent({ styles }) {
4141
useProxy(storage)
4242

43+
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
44+
4345
const [BGAlpha, setBGAlpha] = React.useState(
44-
toDecimal( hexAlphaToPercent(storage?.colors?.backgroundColorAlpha) ?? 100 )
45-
);
46+
clamp((hexAlphaToPercent(storage?.colors?.backgroundColorAlpha) ?? 100), 0, 100)
47+
)
4648
const [gutterAlpha, setGutterAlpha] = React.useState(
47-
toDecimal( hexAlphaToPercent(storage?.colors?.gutterColorAlpha) ?? 100 )
48-
);
49+
clamp((hexAlphaToPercent(storage?.colors?.gutterColorAlpha) ?? 100), 0, 100)
50+
)
4951

50-
const navigation = NavigationNative.useNavigation();
52+
const [useText, setUseText] = React.useState(false);
5153

52-
const parseColorPercentage = clr => alphaToHex(toPercentage(clr));
54+
const navigation = NavigationNative.useNavigation();
5355

5456
const handleSemRaw = prefix => {
5557
if(!prefix) return null;
@@ -132,26 +134,32 @@ export default function ColorPickComponent({ styles }) {
132134
<View style={
133135
{
134136
width: "2%",
135-
backgroundColor: `${storage.colors.gutterColor}${parseColorPercentage(gutterAlpha)}`,
137+
backgroundColor: `${storage.colors.gutterColor}${storage.colors.gutterColorAlpha}`,
136138
}
137139
}/>
140+
141+
{
142+
// console.log(`${storage.colors.gutterColor} ${storage.colors.gutterColor}`)
143+
}
144+
{
145+
// console.log(`${storage.switches.useSemRawColors ? (handleSemRaw(storage?.colors?.semRawColorPrefix) || storage.colors.backgroundColor) : storage.colors.backgroundColor}${storage.colors.backgroundColorAlpha}`)
146+
}
147+
138148
<View style={
139149
{
140150
flex: 1,
141151
backgroundColor: `${
142-
143152
storage.switches.useSemRawColors ?
144153
(handleSemRaw(storage?.colors?.semRawColorPrefix) || storage.colors.backgroundColor) :
145154
storage.colors.backgroundColor
146-
147-
}${parseColorPercentage(BGAlpha)}`,
155+
}${storage.colors.backgroundColorAlpha}`,
148156
justifyContent: 'center',
149157
alignItems: 'center',
150158
}
151159
}>
152160
<Text style={{
153161
fontSize: 20,
154-
color: storage?.switches?.darkMode ? "white" : "black"
162+
color: storage?.switches?.darkMode ? "black" : "white"
155163
}
156164
}> Low Effort Normal Example Message </Text>
157165
<Text style={{
@@ -162,27 +170,73 @@ export default function ColorPickComponent({ styles }) {
162170
</View>
163171
</View>
164172

165-
<FormSliderRow
166-
label={`Background Color Alpha: ${toPercentage(BGAlpha)}%`}
167-
value={BGAlpha}
168-
style={{ width: "90%" }}
169-
onValueChange={(v) => {
170-
setBGAlpha(Number(formatDecimal(v)))
171-
storage.colors.backgroundColorAlpha = alphaToHex(toPercentage(v));
173+
<FormRow
174+
label="Click to switch input type"
175+
subLabel="Switch from slider to number and vise versa"
176+
onPress={() => {
177+
setUseText(!useText)
172178
}}
173179
/>
180+
181+
{
182+
useText ? (<>
183+
<FormInput
184+
title={`Background Color Alpha: ${BGAlpha}%`}
185+
keyboardType="numeric"
186+
style={{ width: "90%" }}
187+
value={`${BGAlpha}`}
188+
onChange={(val) => {
189+
val = clamp(val, 0, 100)
190+
191+
setBGAlpha(Number(val))
192+
storage.colors.backgroundColorAlpha = alphaToHex(val);
193+
}}
194+
/>
195+
</>) : (<>
196+
<FormSliderRow
197+
label={`Background Color Alpha: ${BGAlpha}%`}
198+
value={BGAlpha}
199+
minVal={0}
200+
maxVal={100}
201+
style={{ width: "90%" }}
202+
onValueChange={(v) => {
203+
setBGAlpha(Number(v))
204+
storage.colors.backgroundColorAlpha = alphaToHex(v);
205+
}}
206+
/>
207+
</>)
208+
}
174209

175210
<FormDivider/>
176-
177-
<FormSliderRow
178-
label={`Background Gutter Alpha: ${toPercentage(gutterAlpha)}%`}
179-
value={gutterAlpha}
180-
style={{ width: "90%" }}
181-
onValueChange={(v) => {
182-
setGutterAlpha(Number(formatDecimal(v)))
183-
storage.colors.gutterColorAlpha = alphaToHex(toPercentage(v));
184-
}}
185-
/>
211+
212+
{
213+
useText ? (<>
214+
<FormInput
215+
title={`Background Gutter Alpha: ${gutterAlpha}%`}
216+
keyboardType="numeric"
217+
style={{ width: "90%" }}
218+
value={`${gutterAlpha}`}
219+
onChange={(val) => {
220+
val = clamp(val, 0, 100)
221+
222+
setGutterAlpha(Number(val))
223+
storage.colors.gutterColorAlpha = alphaToHex(val);
224+
}}
225+
/>
226+
</>) : (<>
227+
<FormSliderRow
228+
label={`Background Gutter Alpha: ${gutterAlpha}%`}
229+
value={gutterAlpha}
230+
minVal={0}
231+
maxVal={100}
232+
style={{ width: "90%" }}
233+
onValueChange={(v) => {
234+
setGutterAlpha(Number(v))
235+
storage.colors.gutterColorAlpha = alphaToHex(v);
236+
}}
237+
/>
238+
</>)
239+
}
186240

187241
</View>
188242
</View>

angel/antied/components/customize.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ const customizeableSwitches = [
6464
default: false,
6565
label: "Remove Ephemeral Indicator",
6666
subLabel: "When messages got deleted it'll have indicator under the text like 'only you can see this' and this remove those.",
67+
},
68+
{
69+
id: "useCustomPluginName",
70+
default: false,
71+
label: "Override Plugin Name with custom one",
72+
subLabel: "Replace plugin name with custom one when enabled"
6773
}
6874
]
6975

angel/antied/index.jsx

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import messageRecordDefault from "./patches/messageRecordDefault";
88
import updateMessageRecord from "./patches/updateMessageRecord";
99

1010
import { FluxDispatcher } from "@vendetta/metro/common";
11-
import { storage } from "@vendetta/plugin";
11+
import { storage, id } from "@vendetta/plugin";
1212
import { plugin } from "@vendetta";
1313
import { findByProps } from '@vendetta/metro';
1414
import * as Assets from "@vendetta/ui/assets";
15+
import { stopPlugin } from "@vendetta/plugins";
16+
import { showToast } from "@vendetta/ui/toasts";
1517

1618
import actionsheet from "./patches/actionsheet";
1719
import SettingPage from "./Settings";
@@ -21,7 +23,7 @@ const ChannelMessages = findByProps("_channelMessages");
2123
export const regexEscaper = string => string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2224
export const stripVersions = (str) => str.replace(/\s?v\d+.\d+.\w+/, "");
2325
export const vendettaUiAssets = Object.keys(Assets.all).map(x => x?.name)
24-
26+
export let isEnabled = false;
2527

2628
makeDefaults(storage, {
2729
setting: {
@@ -47,7 +49,8 @@ makeDefaults(storage, {
4749
timestampStyle: 'R',
4850
useEphemeralForDeleted: true,
4951
overrideIndicator: false,
50-
useIndicatorForDeleted: false
52+
useIndicatorForDeleted: false,
53+
useCustomPluginName: false
5154
},
5255
colors: {
5356
textColor: "#E40303",
@@ -73,35 +76,69 @@ makeDefaults(storage, {
7376
debugUpdateRows: false
7477
})
7578

76-
let deletedMessageArray = {};
77-
const patches = []
79+
let deletedMessageArray = new Map();
80+
let unpatch = null;
81+
82+
// these value are hardocoded simply i dont trust users would actively keep it low. for their own sake tbf
83+
// old code doesnt have cache limit crash things, yet you expect me makes it customizeable?
84+
let intervalPurge;
85+
const KEEP_NEWEST = 5; // how many we want to keep (newest entry on the list)
86+
const DELETE_EACH_CYCLE = 95; // how many we purge for each cycle
87+
88+
// timers
89+
let intReg, intTs;
90+
91+
// [Function, ArrayOfArguments]
92+
const patches = [
93+
[fluxDispatchPatch, [deletedMessageArray]],
94+
[updateRowsPatch, [deletedMessageArray]],
95+
[selfEditPatch, []], // no args
96+
[createMessageRecord, []],
97+
[messageRecordDefault, []],
98+
[updateMessageRecord, []],
99+
[actionsheet, [deletedMessageArray]]
100+
];
101+
102+
103+
// helper func
104+
const patcher = () => patches.forEach(([fn, args]) => fn(...args));
78105

79106
export default {
80107
onLoad: () => {
81-
patches.push(
82-
fluxDispatchPatch(deletedMessageArray),
83-
updateRowsPatch(deletedMessageArray),
84-
selfEditPatch(),
85-
createMessageRecord(),
86-
messageRecordDefault(),
87-
updateMessageRecord(),
88-
actionsheet(deletedMessageArray)
89-
)
90-
91-
if(plugin?.manifest?.name != storage?.inputs?.customPluginName) {
92-
plugin.manifest.name = storage?.inputs?.customPluginName
108+
isEnabled = true;
109+
try {
110+
unpatch = patcher()
93111
}
112+
catch(err) {
113+
console.log("[ANTIED], Crash On Load.\n\n", err)
114+
showToast("[ANTIED], Crashing On Load. Please check debug log for more info.")
115+
stopPlugin(id)
116+
};
117+
118+
intervalPurge = setInterval(() => {
119+
if (deletedMessageArray.size <= KEEP_NEWEST) return;
120+
121+
const toDelete = Math.min(DELETE_EACH_CYCLE, deletedMessageArray.size - KEEP_NEWEST);
122+
let i = 0;
123+
124+
for (const key of deletedMessageArray.keys()) {
125+
deletedMessageArray.delete(key);
126+
if (++i >= toDelete) break;
127+
}
128+
}, 15 * 60 * 1000); // 15 min check to purge caches
129+
130+
// apply custom name if override enabled
131+
plugin.manifest.name = storage?.switches?.useCustomPluginName ? storage?.inputs?.customPluginName : plugin.manifest.name;
132+
94133
},
95134
onUnload: () => {
135+
isEnabled = false;
96136

97-
for (const unpatch of patches) {
98-
unpatch();
99-
}
100-
101-
if(plugin?.manifest?.name != storage?.inputs?.customPluginName) {
102-
plugin.manifest.name = storage?.inputs?.customPluginName
103-
}
137+
clearInterval(intervalPurge);
138+
139+
unpatch?.()
104140

141+
// cleaning records
105142
for (const channelId in ChannelMessages._channelMessages) {
106143
for (const message of ChannelMessages._channelMessages[channelId]._array) {
107144
if(message.was_deleted) {
@@ -114,6 +151,7 @@ export default {
114151
}
115152
}
116153
}
154+
117155
},
118156
settings: SettingPage
119157
}

angel/antied/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name":"Antied v1.4.2a",
2+
"name":"Cute Moodle should get lot of hugs v1.4.3",
33
"description":"Keeps deleted messages and logs edited messages, until you restart/reloads the app",
44
"main": "index.jsx",
55
"authors": [

0 commit comments

Comments
 (0)