Files
cocos4/pal/env/runtime/env.ts
T
Santy-Wang 7bc135e1c7 adjust initialization process (#11143)
* adjust init process

* fix bugs

* restructure

* tweak

* delete useless code

* fix ci

* support more platform and fix some bugs

* mark internal

* tweak

* add docs

* add docs and little adjustment

* fix bugs

* adjust decorator execute order

fix mesh error

* fix bugs

* revert some change

* revert auto-generated code

* revert auto-generated code
2022-07-03 21:16:09 +08:00

31 lines
968 B
TypeScript

import { COCOSPLAY, HUAWEI, OPPO, VIVO } from 'internal:constants';
declare const require: (path: string) => Promise<void>;
declare const ral: any;
export function findCanvas (): { frame: HTMLDivElement, container: HTMLDivElement, canvas: HTMLCanvasElement } {
const container = document.createElement('div');
let frame;
if (COCOSPLAY) {
frame = {
clientWidth: window.innerWidth,
clientHeight: window.innerHeight,
} as any;
} else {
frame = container.parentNode === document.body ? document.documentElement : container.parentNode as any;
}
let canvas;
if (VIVO) {
canvas = window.mainCanvas;
window.mainCanvas = undefined;
} else {
canvas = ral.createCanvas();
}
return { frame, canvas, container };
}
export function loadJsFile (path: string): Promise<void> {
// eslint-disable-next-line import/no-dynamic-require
return require(`${path}`);
}