summaryrefslogtreecommitdiff
path: root/frontend/src/developer.tsx
blob: 5df6de076ecf296d9a04a71a9cc46ede644761fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { sleep } from '@decky/ui';
import { FaReact } from 'react-icons/fa';

import Logger from './logger';
import { getSetting } from './utils/settings';
import TranslationHelper, { TranslationClass } from './utils/TranslationHelper';

const logger = new Logger('DeveloperMode');

let removeSettingsObserver: () => void = () => {};

declare global {
  interface Window {
    settingsStore: any;
  }
}

export async function setShowValveInternal(show: boolean) {
  if (show) {
    const mobx =
      window.settingsStore[
        Object.getOwnPropertySymbols(window.settingsStore).find(
          (x) => x.toString() == 'Symbol(mobx administration)',
        ) as any
      ];

    removeSettingsObserver = (mobx.observe_ || mobx.observe).call(mobx, (e: any) => {
      e.newValue.bIsValveEmail = true;
    });

    window.settingsStore.m_Settings.bIsValveEmail = true;
    logger.log('Enabled Valve Internal menu');
  } else {
    removeSettingsObserver();
    window.settingsStore.m_Settings.bIsValveEmail = false;
    logger.log('Disabled Valve Internal menu');
  }
}

export async function setShouldConnectToReactDevTools(enable: boolean) {
  DeckyPluginLoader.toaster.toast({
    title: enable ? (
      <TranslationHelper transClass={TranslationClass.DEVELOPER} transText={'enabling'} />
    ) : (
      <TranslationHelper transClass={TranslationClass.DEVELOPER} transText={'disabling'} />
    ),
    body: <TranslationHelper transClass={TranslationClass.DEVELOPER} transText={'5secreload'} />,
    icon: <FaReact />,
  });
  await sleep(5000);
  return enable ? DeckyBackend.call('utilities/enable_rdt') : DeckyBackend.call('utilities/disable_rdt');
}

export async function startup() {
  const isValveInternalEnabled = await getSetting('developer.valve_internal', false);
  const isRDTEnabled = await getSetting('developer.rdt.enabled', false);

  if (isValveInternalEnabled) setShowValveInternal(isValveInternalEnabled);

  if ((isRDTEnabled && !window.deckyHasConnectedRDT) || (!isRDTEnabled && window.deckyHasConnectedRDT))
    setShouldConnectToReactDevTools(isRDTEnabled);
}