dirk-cfx-react 1.1.77 → 1.1.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -6552,6 +6552,7 @@ function DirkProvider({ children, overideResourceName, themeOverride }) {
6552
6552
  game
6553
6553
  } = useSettings();
6554
6554
  localeStore((s) => s.locales);
6555
+ const [scTheme, setScTheme] = useState(null);
6555
6556
  useLayoutEffect(() => {
6556
6557
  useSettings.setState({
6557
6558
  overideResourceName
@@ -6574,26 +6575,53 @@ function DirkProvider({ children, overideResourceName, themeOverride }) {
6574
6575
  }, []);
6575
6576
  useNuiEvent("UPDATE_DIRK_LIB_SETTINGS", (data) => {
6576
6577
  if (!data || typeof data !== "object") return;
6577
- const carriesOverrideFlag = Object.prototype.hasOwnProperty.call(data, "themeOverride");
6578
- if (carriesOverrideFlag) {
6579
- useSettings.setState(data);
6580
- return;
6581
- }
6582
- const current = useSettings.getState();
6583
- if (current.themeOverride) {
6584
- const { primaryColor: _pc, primaryShade: _ps, customTheme: _ct, ...rest } = data;
6585
- useSettings.setState(rest);
6586
- return;
6587
- }
6588
6578
  useSettings.setState(data);
6589
6579
  });
6580
+ useNuiEvent(
6581
+ "UPDATE_SCRIPT_CONFIG",
6582
+ (data) => {
6583
+ if (!data || !data.config || typeof data.config !== "object") return;
6584
+ try {
6585
+ const inst = getScriptConfigInstance();
6586
+ inst.store.setState((prev) => ({ ...prev, ...data.config }));
6587
+ } catch {
6588
+ }
6589
+ }
6590
+ );
6591
+ useEffect(() => {
6592
+ let unsubscribe;
6593
+ try {
6594
+ const inst = getScriptConfigInstance();
6595
+ setScTheme(inst.store.getState()?.theme ?? null);
6596
+ const subscribable = inst.store;
6597
+ if (typeof subscribable.subscribe === "function") {
6598
+ unsubscribe = subscribable.subscribe((s) => {
6599
+ setScTheme(s?.theme ?? null);
6600
+ });
6601
+ }
6602
+ inst.fetchConfig?.().then((full) => {
6603
+ if (full && typeof full === "object") {
6604
+ setScTheme(full.theme ?? null);
6605
+ }
6606
+ }).catch(() => {
6607
+ });
6608
+ } catch {
6609
+ }
6610
+ return () => {
6611
+ unsubscribe?.();
6612
+ };
6613
+ }, []);
6614
+ const overrideActive = scTheme?.useOverride === true;
6615
+ const effectivePrimaryColor = overrideActive ? scTheme.primaryColor ?? primaryColor : primaryColor;
6616
+ const effectivePrimaryShade = overrideActive ? scTheme.primaryShade ?? primaryShade : primaryShade;
6617
+ const effectiveCustomTheme = overrideActive ? scTheme.customTheme ?? customTheme : customTheme;
6590
6618
  const mergedTheme = useMemo(
6591
6619
  () => mergeMantineThemeSafe(
6592
- { ...theme_default, primaryColor, primaryShade },
6593
- customTheme,
6620
+ { ...theme_default, primaryColor: effectivePrimaryColor, primaryShade: effectivePrimaryShade },
6621
+ effectiveCustomTheme,
6594
6622
  themeOverride
6595
6623
  ),
6596
- [primaryColor, primaryShade, customTheme, themeOverride]
6624
+ [effectivePrimaryColor, effectivePrimaryShade, effectiveCustomTheme, themeOverride]
6597
6625
  );
6598
6626
  useEffect(() => {
6599
6627
  document.body.style.fontFamily = game === "rdr3" ? '"Red Dead", sans-serif' : '"Akrobat Regular", sans-serif';