Files
discord-decomp/lib/spellcheck/LanguageDetector.tsx
T
2026-11-01 12:12:55 +02:00

83 lines
2.4 KiB
TypeScript

// Metro module 5196 (f5197).
import DesktopNativeUtils from "../../utils/web/DesktopNativeUtils";
class LanguageDetector {
constructor(a0, a1) {
const r5 = {
__proto__: new.target.prototype,
_shouldProcess: false,
_processing: false,
_minimumTimeRemaining: 5
};
r5._language = a0;
r5._languageHint = a0;
r5._onChange = a1;
a1(a0);
return r5;
}
get language() {
return this._language;
}
set language(a0) {
if (this._language !== a0) {
this._language = a0;
this._onChange(a0);
}
}
set languageHint(a0) {
this._languageHint = a0;
}
process(c14724_0) {
if (!this._processing) {
this._processing = true;
requestIdleCallback((a0) => {
let c25380_0 = a0;
const r7 = a0.timeRemaining();
if (r7 <= this._minimumTimeRemaining) {
this._processEnd();
} else {
if (c14724_0.length > 256) {
c14724_0 = c14724_0.slice(0, 256);
}
const r8 = c14724_0;
const _languageHint2 = this._languageHint;
let c25381_0 = r8;
const _languageHint = _languageHint2;
DesktopNativeUtils.ensureModule("discord_spellcheck").then(() => {
const cld = DesktopNativeUtils.requireModule("discord_spellcheck").cld;
return new Promise((c31934_0, c31934_1) => {
cld.detect(c25381_0, {
httpHint: _languageHint,
encodingHint: "UTF8"
}, (a0, a1) => {
L7: {
if (a0 != null) {
c31934_1(new Error(a0.message));
} else {
if (a1.reliable && !(a1.languages[0].percent < 90) && !(a1.languages[0].score < 500)) {
c31934_0(a1.languages[0].code);
break L7;
}
c31934_1(new Error("Not enough reliable text."));
}
}
});
});
}).then((result) => {
this.language = result;
this._processEnd(c25380_0.didTimeout);
}, () => {
this._processEnd(c25380_0.didTimeout);
});
}
});
}
}
_processEnd(r2 = false) {
this._processing = false;
if (r2) {
this._minimumTimeRemaining = this._minimumTimeRemaining + 1;
}
}
}
export default LanguageDetector;