dirk-cfx-react 1.1.76 → 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,21 +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 current = useSettings.getState();
6578
- if (current.themeOverride) {
6579
- const { primaryColor: _pc, primaryShade: _ps, customTheme: _ct, ...rest } = data;
6580
- useSettings.setState(rest);
6581
- return;
6582
- }
6583
6578
  useSettings.setState(data);
6584
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;
6585
6618
  const mergedTheme = useMemo(
6586
6619
  () => mergeMantineThemeSafe(
6587
- { ...theme_default, primaryColor, primaryShade },
6588
- customTheme,
6620
+ { ...theme_default, primaryColor: effectivePrimaryColor, primaryShade: effectivePrimaryShade },
6621
+ effectiveCustomTheme,
6589
6622
  themeOverride
6590
6623
  ),
6591
- [primaryColor, primaryShade, customTheme, themeOverride]
6624
+ [effectivePrimaryColor, effectivePrimaryShade, effectiveCustomTheme, themeOverride]
6592
6625
  );
6593
6626
  useEffect(() => {
6594
6627
  document.body.style.fontFamily = game === "rdr3" ? '"Red Dead", sans-serif' : '"Akrobat Regular", sans-serif';