2024-03-06 18:14:32 +00:00
|
|
|
import { once } from 'lodash-es';
|
2023-10-20 16:18:30 +00:00
|
|
|
import { AppRouterOutput, trpc } from '../api/trpc';
|
2024-03-06 18:14:32 +00:00
|
|
|
import { anonymousTelemetryUrl } from '../utils/env';
|
2023-10-20 16:18:30 +00:00
|
|
|
|
|
|
|
const defaultGlobalConfig: AppRouterOutput['global']['config'] = {
|
|
|
|
allowRegister: false,
|
2024-02-17 03:45:11 +00:00
|
|
|
alphaMode: false,
|
2024-03-06 18:14:32 +00:00
|
|
|
disableAnonymousTelemetry: false,
|
2024-08-02 19:44:43 +00:00
|
|
|
authProvider: [],
|
2023-10-20 16:18:30 +00:00
|
|
|
};
|
|
|
|
|
2024-03-06 18:14:32 +00:00
|
|
|
const callAnonymousTelemetry = once(() => {
|
|
|
|
fetch(anonymousTelemetryUrl);
|
|
|
|
});
|
|
|
|
|
2023-10-20 16:18:30 +00:00
|
|
|
/**
|
|
|
|
* Fetch settings from server
|
|
|
|
*/
|
|
|
|
export function useGlobalConfig(): AppRouterOutput['global']['config'] {
|
|
|
|
const { data = defaultGlobalConfig } = trpc.global.config.useQuery(
|
|
|
|
undefined,
|
|
|
|
{
|
|
|
|
staleTime: 1000 * 60 * 60 * 1, // 1 hour
|
2024-03-06 18:14:32 +00:00
|
|
|
onSuccess(data) {
|
|
|
|
if (data.disableAnonymousTelemetry !== true) {
|
|
|
|
callAnonymousTelemetry();
|
|
|
|
}
|
|
|
|
},
|
2023-10-20 16:18:30 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|