2024-01-21 23:50:56 +11:00
|
|
|
import { createContext, useContext } from 'react';
|
|
|
|
|
|
2024-05-31 19:49:46 +05:30
|
|
|
export type HashRouterConfig = {
|
|
|
|
|
enabled?: boolean;
|
|
|
|
|
basename?: string;
|
|
|
|
|
};
|
|
|
|
|
|
2024-01-21 23:50:56 +11:00
|
|
|
export type ClientConfig = {
|
|
|
|
|
defaultHomeserver?: number;
|
|
|
|
|
homeserverList?: string[];
|
|
|
|
|
allowCustomHomeservers?: boolean;
|
|
|
|
|
|
2024-05-31 19:49:46 +05:30
|
|
|
featuredCommunities?: {
|
|
|
|
|
openAsDefault?: boolean;
|
|
|
|
|
spaces?: string[];
|
|
|
|
|
rooms?: string[];
|
|
|
|
|
servers?: string[];
|
2024-01-21 23:50:56 +11:00
|
|
|
};
|
2024-05-31 19:49:46 +05:30
|
|
|
|
|
|
|
|
hashRouter?: HashRouterConfig;
|
2026-05-15 13:37:03 -04:00
|
|
|
gifApiKey?: string;
|
2026-09-26 23:24:24 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* [Gitea #43] Absolute https URL of the Element Call page on its own origin.
|
|
|
|
|
* Unset: the bundled copy on this origin. Ignored in the desktop app.
|
|
|
|
|
*/
|
|
|
|
|
elementCallUrl?: string;
|
2026-09-27 16:54:29 -04:00
|
|
|
|
2026-09-29 00:09:27 -04:00
|
|
|
/**
|
|
|
|
|
* [Gitea #43] Desktop only: the loopback origin the desktop app's local
|
|
|
|
|
* server also answers on (e.g. "http://127.0.0.1:44548"), to load the
|
|
|
|
|
* bundled call page from a different origin than the app
|
|
|
|
|
* ("http://localhost:44548"). Set by cinny-desktop together with the server
|
|
|
|
|
* and CSP changes it needs; unset keeps the same-origin call page.
|
|
|
|
|
*/
|
|
|
|
|
desktopCallOrigin?: string;
|
|
|
|
|
|
2026-09-27 16:54:29 -04:00
|
|
|
/**
|
|
|
|
|
* Absolute https URL of the public web app (e.g. https://chat.lotusguild.org).
|
|
|
|
|
* The desktop app sets it so it can hand calls it can't make to the browser.
|
|
|
|
|
*/
|
|
|
|
|
webAppUrl?: string;
|
2024-01-21 23:50:56 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ClientConfigContext = createContext<ClientConfig | null>(null);
|
|
|
|
|
|
|
|
|
|
export const ClientConfigProvider = ClientConfigContext.Provider;
|
|
|
|
|
|
|
|
|
|
export function useClientConfig(): ClientConfig {
|
|
|
|
|
const config = useContext(ClientConfigContext);
|
|
|
|
|
if (!config) throw new Error('Client config are not provided!');
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const clientDefaultServer = (clientConfig: ClientConfig): string =>
|
|
|
|
|
clientConfig.homeserverList?.[clientConfig.defaultHomeserver ?? 0] ?? 'matrix.org';
|
|
|
|
|
|
|
|
|
|
export const clientAllowedServer = (clientConfig: ClientConfig, server: string): boolean => {
|
|
|
|
|
const { homeserverList, allowCustomHomeservers } = clientConfig;
|
|
|
|
|
|
|
|
|
|
if (allowCustomHomeservers) return true;
|
|
|
|
|
|
|
|
|
|
return homeserverList?.includes(server) === true;
|
|
|
|
|
};
|