Files
discord-decomp/modules/app_icons/native/AppIconPremiumManager.tsx
T
2026-11-01 12:12:55 +02:00

85 lines
2.9 KiB
TypeScript

// Metro module 16133 (f16134).
import UserStore from "../../../stores/UserStore";
import { getIconById } from "./AppIconConstants";
import { AnalyticEvents } from "../../../Constants";
import Logger from "../../debug/Logger";
import { FreemiumAppIconIds } from "../AppIconTypes";
import AutomaticLifecycleManager from "../../../lib/AutomaticLifecycleManager";
import * as _PlatformUtils from "../../../utils/PlatformUtils";
import { fetchCurrentAppIcon, setAppIcon } from "./AppIconUtils";
import PremiumUtils from "../../../utils/PremiumUtils";
import AnalyticsUtils from "../../../utils/AnalyticsUtils";
let c11554_7 = new Logger("AppIconPremiumManager");
const DEFAULT = FreemiumAppIconIds.DEFAULT;
let c11554_9 = {
ORPHANED: "orphaned",
PREMIUM_LOST: "premium_lost"
};
class AppIconPremiumManager extends AutomaticLifecycleManager {
actions = {
APP_STATE_UPDATE: (a0) => this.handleAppStateUpdate(a0)
};
handleAppStateUpdate(a0) {
const isIOS = _PlatformUtils.isIOS();
const state = a0.state;
if (isIOS ? state === "active" : state === "background") {
this.validateAndResetIfNeeded();
}
}
async validateAndResetIfNeeded() {
const _this = this;
let premiumType, premiumType2, c28234_3;
let c30958_0, c30958_1, c30958_2;
L25: {
L24: {
c28234_3 = void 0;
c30958_0 = void 0;
c30958_1 = void 0;
c30958_2 = void 0;
c30958_0 = UserStore.getCurrentUser();
c30958_1 = await fetchCurrentAppIcon();
if (c30958_1 === DEFAULT) {
break L25;
}
c30958_2 = (0, getIconById)(c30958_1);
if (c30958_1 !== c30958_2.id) {
c11554_7.info(`Icon ${c30958_1} is no longer available, resetting to default`);
const r75 = c30958_1;
premiumType = c30958_0?.premiumType;
if (premiumType == null) {
premiumType = void 0;
}
_this.resetIcon(r75, premiumType, c11554_9.ORPHANED);
break L24;
}
const canUsePremiumAppIcons = PremiumUtils.canUsePremiumAppIcons(c30958_0);
if (!(canUsePremiumAppIcons ? !canUsePremiumAppIcons : c30958_2.isPremium)) {
break L25;
}
c11554_7.info(`User is not premium, resetting icon ${c30958_1} to default`);
const r108 = c30958_1;
premiumType2 = c30958_0?.premiumType;
if (premiumType2 == null) {
premiumType2 = void 0;
}
_this.resetIcon(r108, premiumType2, c11554_9.PREMIUM_LOST);
break L25;
}
return void 0;
}
}
resetIcon(previous_icon_id, a1, reset_reason) {
setAppIcon(DEFAULT, a1).then(() => {
AnalyticsUtils.track(AnalyticEvents.APP_ICON_AUTO_RESET, {
previous_icon_id,
reset_to_icon_id: DEFAULT,
reset_reason
});
}).catch((error) => {
c11554_7.error("Failed to reset app icon:", error);
});
}
}
const appIconPremiumManager = new AppIconPremiumManager();
export default appIconPremiumManager;