fix: custom logos
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Cross-module signaling for enterprise plugin registration.
|
||||
//
|
||||
// The enterprise plugin is loaded asynchronously by the block injected into
|
||||
// global.tsx during enterprise builds. getInitialState() must wait for that
|
||||
// registration before calling GPUStackPluginManager.initialize, otherwise
|
||||
// initialize runs with zero plugins.
|
||||
//
|
||||
// In open-source builds the block isn't injected, so the promise resolves
|
||||
// immediately and getInitialState proceeds without delay.
|
||||
|
||||
const isEnterpriseMode = process.env.ENABLE_ENTERPRISE === 'true';
|
||||
|
||||
let resolveReady: () => void = () => {};
|
||||
|
||||
export const enterprisePluginReady: Promise<void> = new Promise<void>(
|
||||
(resolve) => {
|
||||
if (!isEnterpriseMode) {
|
||||
resolve();
|
||||
} else {
|
||||
resolveReady = resolve;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export const markEnterprisePluginReady = (): void => {
|
||||
resolveReady();
|
||||
};
|
||||
@@ -26,7 +26,7 @@ export function mergeEnterpriseLocales(locales: Record<string, any> = {}) {
|
||||
antd: locale
|
||||
});
|
||||
mergedLocales.add(locale);
|
||||
console.log(`✓ Merged enterprise locale: ${locale}`);
|
||||
console.log(`✓ Merged enterprise locale: ${locale}`, messages);
|
||||
} catch (error) {
|
||||
console.error(`Failed to merge enterprise locale ${locale}:`, error);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { AppPlugin, IPluginManager } from './types';
|
||||
import { AppPlugin, AppPluginContext, IPluginManager } from './types';
|
||||
|
||||
class PluginManager implements IPluginManager {
|
||||
private plugins = new Map<string, AppPlugin>();
|
||||
@@ -38,7 +38,7 @@ class PluginManager implements IPluginManager {
|
||||
/**
|
||||
* initialize all plugins
|
||||
*/
|
||||
async initialize(): Promise<Record<string, any>> {
|
||||
async initialize(context: AppPluginContext): Promise<Record<string, any>> {
|
||||
if (this.initialized) {
|
||||
return {};
|
||||
}
|
||||
@@ -46,9 +46,10 @@ class PluginManager implements IPluginManager {
|
||||
const initData: Record<string, any> = {};
|
||||
|
||||
for (const [name, plugin] of this.plugins.entries()) {
|
||||
console.log(`Initializing plugin "${name}"...`);
|
||||
if (plugin.onAppInit) {
|
||||
try {
|
||||
const data = await plugin.onAppInit();
|
||||
const data = await plugin.onAppInit(context);
|
||||
if (data) {
|
||||
initData[name] = data;
|
||||
}
|
||||
@@ -63,7 +64,7 @@ class PluginManager implements IPluginManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通知所有插件应用已就绪
|
||||
* notify all plugins that the app is ready
|
||||
*/
|
||||
async notifyReady(): Promise<void> {
|
||||
for (const [name, plugin] of this.plugins.entries()) {
|
||||
|
||||
+56
-3
@@ -10,12 +10,52 @@ export interface RouteConfig {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* dependency kit passed from host to plugin's custom login component
|
||||
*/
|
||||
export interface LoginKit {
|
||||
useLocalAuth: (opts: any) => {
|
||||
handleLogin: (values: any) => void;
|
||||
submitLoading: boolean;
|
||||
};
|
||||
useSSOAuth: (opts: any) => {
|
||||
options: {
|
||||
saml: boolean;
|
||||
oidc: boolean;
|
||||
first_time_setup: boolean;
|
||||
get_initial_password_command: string;
|
||||
};
|
||||
loginWithOIDC: () => void;
|
||||
loginWithSAML: () => void;
|
||||
};
|
||||
userInfo: any;
|
||||
setUserInfo: (info: any) => void;
|
||||
fetchUserInfo: () => Promise<any>;
|
||||
checkDefaultPage: (userInfo: any, replace: boolean) => Promise<void>;
|
||||
initialPassword: string;
|
||||
setInitialPassword: (val: string) => void;
|
||||
decryptInitialPassword: (encrypted: string) => string;
|
||||
updatePassword: (data: any) => Promise<any>;
|
||||
passwordReg: RegExp;
|
||||
onPasswordChanged: () => void;
|
||||
resetPasswordUrl: string;
|
||||
formLogoUrl: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* login module configuration
|
||||
*/
|
||||
export interface LoginPlugin {
|
||||
shouldUseCustomLogin?: () => boolean;
|
||||
CustomLoginComponent?: ComponentType;
|
||||
shouldUseCustomLogin?: (enterpriseSettings: any) => boolean;
|
||||
CustomLoginComponent?: ComponentType<{ kit: LoginKit }>;
|
||||
}
|
||||
|
||||
/**
|
||||
* resolved logo URLs for sidebar and collapsed-state mini icon
|
||||
*/
|
||||
export interface LogoSet {
|
||||
sidebarLogo?: string;
|
||||
miniLogo?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,6 +63,7 @@ export interface LoginPlugin {
|
||||
*/
|
||||
export interface BrandingPlugin {
|
||||
ConfigPage?: ComponentType;
|
||||
resolveLogos?: (userSettings: any, isDarkTheme: boolean) => LogoSet;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,6 +73,16 @@ export interface LocalesConfig {
|
||||
[locale: string]: Record<string, any>;
|
||||
}
|
||||
|
||||
/**
|
||||
* runtime context passed to plugin lifecycle hooks
|
||||
*/
|
||||
export interface AppPluginContext {
|
||||
request: <T = any>(url: string, options?: Record<string, any>) => Promise<T>;
|
||||
setUserSettings?: (value: Record<string, any>) => void;
|
||||
setStorageUserSettings?: (value: Record<string, any>) => void;
|
||||
defaultColorPrimary?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* application plugin interface
|
||||
*/
|
||||
@@ -40,7 +91,9 @@ export interface AppPlugin {
|
||||
* application initialization hook
|
||||
* called when the application starts, can return initialization data
|
||||
*/
|
||||
onAppInit?: () => Promise<Record<string, any>> | Record<string, any>;
|
||||
onAppInit?: (
|
||||
context: AppPluginContext
|
||||
) => Promise<Record<string, any>> | Record<string, any>;
|
||||
|
||||
/**
|
||||
* application ready hook
|
||||
|
||||
Reference in New Issue
Block a user