58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
/* eslint-disable no-console */
|
|
/**
|
|
* 全局 Proto 初始化
|
|
*/
|
|
|
|
// import ProtoDefinitionsModule from "../protos/ProtoDefinitions.js";
|
|
|
|
import ProtoDefinitionsModule from "../protos/ProtoDefinitions.js";
|
|
|
|
// @ts-ignore
|
|
|
|
/**
|
|
* 初始化全局 ProtoDefinitions
|
|
*/
|
|
export class GlobalProtoInit {
|
|
// ProtoDefinitionsModule.
|
|
private static _initialized = false;
|
|
|
|
/**
|
|
* 初始化全局 Proto 定义
|
|
*/
|
|
public static init(): void {
|
|
if (this._initialized) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// 将 ProtoDefinitions 挂载到全局对象
|
|
|
|
(globalThis as any).ProtoDefinitions = ProtoDefinitionsModule;
|
|
|
|
// 同时挂载到 window 对象(浏览器环境)
|
|
if (typeof window !== "undefined") {
|
|
(window as any).ProtoDefinitions = ProtoDefinitionsModule;
|
|
}
|
|
|
|
this._initialized = true;
|
|
console.log(
|
|
"GlobalProtoInit",
|
|
"ProtoDefinitions 已成功挂载到全局对象",
|
|
);
|
|
} catch (err) {
|
|
console.error(
|
|
"GlobalProtoInit",
|
|
"初始化 ProtoDefinitions 失败:",
|
|
err,
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 检查是否已初始化
|
|
*/
|
|
public static isInitialized(): boolean {
|
|
return this._initialized;
|
|
}
|
|
}
|