mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-10-09 15:25:24 +00:00
[engine] [cocos2d-x] [jsb-adapter] 适配引擎 v2.4.13 版本
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { ContextType } from '../../../ets/common/Constants';
|
||||
|
||||
interface context {
|
||||
onPageShow: () => void;
|
||||
onPageHide: () => void;
|
||||
workerInit: () => void;
|
||||
postMessage: (msgType: string, msgData: string) => void;
|
||||
postSyncMessage: (msgType: string, msgData: string) => Promise<boolean | string | number>;
|
||||
setPostMessageFunction: (postMessage: (msgType: string, msgData: string) => void) => void;
|
||||
setPostSyncMessageFunction: (postSyncMessage: (msgType: string, msgData: string) => void) => void;
|
||||
nativeEngineInit: () => void;
|
||||
nativeEngineStart: () => void;
|
||||
onTextChange: (param: string) => void;
|
||||
onComplete: (param: string) => void;
|
||||
shouldStartLoading: (viewTag: number, url: string) => void;
|
||||
finishLoading: (viewTag: number, url: string) => void;
|
||||
failLoading: (viewTag: number, url: string) => void;
|
||||
onBackPress: () => void;
|
||||
onCreate: () => void;
|
||||
onDestroy: () => void;
|
||||
onShow: () => void;
|
||||
onHide: () => void;
|
||||
resourceManagerInit: (resourceManager: any) => void;
|
||||
writablePathInit: (cacheDir: string) => void;
|
||||
}
|
||||
|
||||
export const getContext: (type: ContextType) => context;
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "libcocos.so",
|
||||
"types": "./index.d.ts",
|
||||
"version": "",
|
||||
"description": "Please describe the basic information."
|
||||
}
|
@@ -24,31 +24,34 @@
|
||||
****************************************************************************/
|
||||
|
||||
import worker from '@ohos.worker';
|
||||
import {Constants} from '../common/Constants'
|
||||
import { Constants } from '../common/Constants'
|
||||
|
||||
export class WorkerManager {
|
||||
private static instance: WorkerManager;
|
||||
private cocosWorker: any;
|
||||
private cocosWorker: worker.Worker;
|
||||
|
||||
private constructor() {
|
||||
this.cocosWorker = new worker.Worker("entry/ets/workers/cocos_worker.ts", {type:"classic", name: "CocosWorker"});
|
||||
this.cocosWorker.onerror = function (e) {
|
||||
var msg = e.message;
|
||||
var filename = e.filename;
|
||||
var lineno = e.lineno;
|
||||
var colno = e.colno;
|
||||
console.error(`on Error ${msg} ${filename} ${lineno} ${colno}`);
|
||||
}
|
||||
private constructor() {
|
||||
this.cocosWorker = new worker.Worker("entry/ets/workers/cocos_worker.ts", {
|
||||
type: "classic",
|
||||
name: "CocosWorker"
|
||||
});
|
||||
this.cocosWorker.onerror = (e) => {
|
||||
let msg = e.message;
|
||||
let filename = e.filename;
|
||||
let lineno = e.lineno;
|
||||
let colno = e.colno;
|
||||
console.error(`on Error ${msg} ${filename} ${lineno} ${colno}`);
|
||||
}
|
||||
}
|
||||
|
||||
public static getInstance(): WorkerManager {
|
||||
if (AppStorage.Get(Constants.APP_KEY_WORKER_MANAGER) == null) {
|
||||
AppStorage.SetOrCreate(Constants.APP_KEY_WORKER_MANAGER, new WorkerManager);
|
||||
}
|
||||
return AppStorage.Get(Constants.APP_KEY_WORKER_MANAGER);
|
||||
}
|
||||
public getWorker(): any {
|
||||
return this.cocosWorker;
|
||||
public static getInstance(): WorkerManager {
|
||||
if (AppStorage.Get(Constants.APP_KEY_WORKER_MANAGER) as WorkerManager == undefined) {
|
||||
AppStorage.SetOrCreate(Constants.APP_KEY_WORKER_MANAGER, new WorkerManager);
|
||||
}
|
||||
return AppStorage.Get(Constants.APP_KEY_WORKER_MANAGER) as WorkerManager;
|
||||
}
|
||||
|
||||
public getWorker(): worker.Worker {
|
||||
return this.cocosWorker;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
globalThis.oh = {};
|
||||
globalThis.oh = {} as any;
|
||||
|
||||
function boot() {
|
||||
const cc = globalThis.cc;
|
||||
var settings = globalThis._CCSettings;
|
||||
@@ -74,8 +75,8 @@ function boot() {
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.oh.loadJsList(settings.jsList,cb);
|
||||
|
||||
globalThis.oh.loadJsList(settings.jsList, cb);
|
||||
|
||||
for (var i = 0; i < bundleRoot.length; i++) {
|
||||
cc.assetManager.loadBundle(bundleRoot[i], cb);
|
||||
}
|
||||
|
@@ -11,4 +11,4 @@ globalThis.oh.loadModule = (name) => {
|
||||
};
|
||||
globalThis.oh.loadJsList = (jsList, cb) => {
|
||||
globalThis.cc.assetManager.loadScript(jsList.map(function (x) { return x; }), cb);
|
||||
};
|
||||
};
|
@@ -21,57 +21,56 @@
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import worker from '@ohos.worker';
|
||||
import {DedicatedWorkerGlobalScope} from '@ohos.worker';
|
||||
// NOTE: don't use this import all statement, because this has compile issue.
|
||||
// import * as wk from '@ohos.worker';
|
||||
****************************************************************************/
|
||||
import { DedicatedWorkerGlobalScope } from '@ohos.worker';
|
||||
import { MessageEvent } from '@ohos.worker';
|
||||
|
||||
export class PortProxy {
|
||||
private autoId: number = 0;
|
||||
public actionHandleMap = {}
|
||||
private port :DedicatedWorkerGlobalScope = null;
|
||||
private autoId: number = 0;
|
||||
public actionHandleMap = {}
|
||||
private port: DedicatedWorkerGlobalScope = null;
|
||||
|
||||
public _messageHandle?:(e: MessageEvent<any>) => void;
|
||||
public _messageHandle?: (e: MessageEvent<any>) => void;
|
||||
|
||||
constructor (port) {
|
||||
this.port = port;
|
||||
this.port.onmessage = this.onMessage.bind(this);
|
||||
}
|
||||
constructor(worker) {
|
||||
this.port = worker;
|
||||
this.port.onmessage = this.onMessage.bind(this);
|
||||
}
|
||||
|
||||
public onMessage(e) {
|
||||
let data = e['data'];
|
||||
if(data.type != "syncResult" && this._messageHandle) {
|
||||
this._messageHandle(e);
|
||||
} else if(data.type == "syncResult") {
|
||||
const {id, response} = data.data;
|
||||
if (!this.actionHandleMap[id]) {
|
||||
return;
|
||||
}
|
||||
this.actionHandleMap[id].call(this, response)
|
||||
delete this.actionHandleMap[id];
|
||||
}
|
||||
}
|
||||
public postReturnMessage(e:any, res: any) {
|
||||
if(e.type == "sync" && res != null && res != undefined) {
|
||||
this.port.postMessage({type:"syncResult", data:{id:e.data.cbId, response:res}});
|
||||
}
|
||||
}
|
||||
public postMessage(msgName: string, msgData:any) {
|
||||
this.port.postMessage({type:"async", data:{name:msgName, param:msgData}});
|
||||
public onMessage(e) {
|
||||
let data = e['data'];
|
||||
if (data.type != "syncResult" && this._messageHandle) {
|
||||
this._messageHandle(e);
|
||||
} else if (data.type == "syncResult") {
|
||||
const { id, response } = data.data;
|
||||
if (!this.actionHandleMap[id]) {
|
||||
return;
|
||||
}
|
||||
this.actionHandleMap[id].call(this, response);
|
||||
delete this.actionHandleMap[id];
|
||||
}
|
||||
}
|
||||
|
||||
public postSyncMessage(msgName: string, msgData:any) {
|
||||
const id = this.autoId++;
|
||||
return new Promise((resolve, reject) => {
|
||||
const message = {
|
||||
type:"sync", data:{cbId:id, name:msgName, param:msgData}
|
||||
}
|
||||
this.port.postMessage(message);
|
||||
this.actionHandleMap[id] = (response) => {
|
||||
resolve(response)
|
||||
}
|
||||
})
|
||||
public postReturnMessage(e: any, res: any) {
|
||||
if (e.type == "sync" && res != null && res != undefined) {
|
||||
this.port.postMessage({ type: "syncResult", data: { id: e.data.cbId, response: res } });
|
||||
}
|
||||
}
|
||||
|
||||
public postMessage(msgName: string, msgData: any) {
|
||||
this.port.postMessage({ type: "async", data: { name: msgName, param: msgData } });
|
||||
}
|
||||
|
||||
public postSyncMessage(msgName: string, msgData: any) {
|
||||
const id = this.autoId++;
|
||||
return new Promise((resolve, reject) => {
|
||||
const message = {
|
||||
type: "sync", data: { cbId: id, name: msgName, param: msgData }
|
||||
}
|
||||
this.port.postMessage(message);
|
||||
this.actionHandleMap[id] = (response) => {
|
||||
resolve(response)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -21,9 +21,8 @@
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import { WorkerManager } from '../cocos/WorkerManager'
|
||||
import { PortProxy } from '../common/PortProxy'
|
||||
****************************************************************************/
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
|
||||
enum EventType {
|
||||
PLAYING = 0,
|
||||
@@ -35,7 +34,13 @@ enum EventType {
|
||||
READY_TO_PLAY,
|
||||
UPDATE,
|
||||
QUIT_FULLSCREEN = 1000
|
||||
};
|
||||
}
|
||||
|
||||
interface param {
|
||||
videoTag?: number,
|
||||
videoEvent?: EventType,
|
||||
args?: number
|
||||
}
|
||||
|
||||
@Observed
|
||||
export class VideoInfo {
|
||||
@@ -44,24 +49,21 @@ export class VideoInfo {
|
||||
public w: number = 0;
|
||||
public h: number = 0;
|
||||
// url
|
||||
public url: string | Resource = ""
|
||||
public viewTag: string = ''
|
||||
public visible: boolean = true
|
||||
|
||||
public url: string | Resource = "";
|
||||
public viewTag: number = 0;
|
||||
public visible: boolean = true;
|
||||
public duration: number = 0;
|
||||
public currentTime: number = 0;
|
||||
public isFullScreen: boolean = false;
|
||||
public currentProgressRate:number | string | PlaybackSpeed;
|
||||
|
||||
public currentProgressRate?: number | string | PlaybackSpeed;
|
||||
public resourceType: number = 0;
|
||||
|
||||
/**
|
||||
* https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/arkui-ts/ts-media-components-video.md#videocontroller
|
||||
*
|
||||
*/
|
||||
public controller: VideoController = new VideoController()
|
||||
|
||||
constructor(x: number, y: number, w: number, h: number, viewTag: string) {
|
||||
constructor(x: number, y: number, w: number, h: number, viewTag: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
@@ -70,49 +72,70 @@ export class VideoInfo {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
export struct CocosVideoPlayer {
|
||||
@ObjectLink videoInfo: VideoInfo;
|
||||
public workPort: PortProxy;
|
||||
public workPort: PortProxy | null = null;
|
||||
|
||||
build() {
|
||||
Video({ src: this.videoInfo.url, controller: this.videoInfo.controller, currentProgressRate:this.videoInfo.currentProgressRate })
|
||||
Video({
|
||||
src: this.videoInfo.url,
|
||||
controller: this.videoInfo.controller,
|
||||
currentProgressRate: this.videoInfo.currentProgressRate as number | string | PlaybackSpeed
|
||||
})
|
||||
.position({ x: this.videoInfo.x, y: this.videoInfo.y })
|
||||
.width(this.videoInfo.w)
|
||||
.height(this.videoInfo.h)
|
||||
.controls(false)
|
||||
.autoPlay(false)
|
||||
.onStart(() => {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.PLAYING});
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag as number,
|
||||
videoEvent: EventType.PLAYING as EventType
|
||||
} as param);
|
||||
})
|
||||
.onPause(() => {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.PAUSED});
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag as number,
|
||||
videoEvent: EventType.PAUSED as EventType
|
||||
} as param);
|
||||
})
|
||||
.onFinish(() => {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.COMPLETED});
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.COMPLETED
|
||||
} as param);
|
||||
})
|
||||
.onPrepared((event: {
|
||||
duration: number;
|
||||
}) => {
|
||||
this.videoInfo.duration = event.duration;
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.READY_TO_PLAY, args:event.duration});
|
||||
.onPrepared((event): void => {
|
||||
this.videoInfo.duration = event?.duration as number;
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.READY_TO_PLAY,
|
||||
args: event?.duration
|
||||
} as param);
|
||||
})
|
||||
.onClick((event: ClickEvent) => {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.CLICKED});
|
||||
.onClick((event): void => {
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.CLICKED
|
||||
} as param);
|
||||
})
|
||||
.onUpdate((event?: {
|
||||
time: number;
|
||||
}) => {
|
||||
this.videoInfo.currentTime = event.time
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.UPDATE, args:event.time});
|
||||
.onUpdate((event) => {
|
||||
this.videoInfo.currentTime = event?.time as number;
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.UPDATE,
|
||||
args: event?.time
|
||||
} as param);
|
||||
})
|
||||
.onFullscreenChange((event?: {
|
||||
fullscreen: boolean;
|
||||
}) => {
|
||||
if (!event.fullscreen) {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.QUIT_FULLSCREEN});
|
||||
.onFullscreenChange((event) => {
|
||||
if (!event?.fullscreen) {
|
||||
this.workPort?.postMessage("onVideoEvent", {
|
||||
videoTag: this.videoInfo.viewTag,
|
||||
videoEvent: EventType.QUIT_FULLSCREEN
|
||||
} as param);
|
||||
}
|
||||
this.videoInfo.isFullScreen = event.fullscreen
|
||||
this.videoInfo.isFullScreen = event?.fullscreen as boolean;
|
||||
})
|
||||
.visibility(this.videoInfo.visible ? Visibility.Visible : Visibility.None)
|
||||
}
|
||||
|
@@ -22,9 +22,14 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import { WorkerManager } from '../cocos/WorkerManager'
|
||||
import { PortProxy } from '../common/PortProxy'
|
||||
import web from '@ohos.web.webview'
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
import web from '@ohos.web.webview';
|
||||
|
||||
interface param {
|
||||
viewTag: number,
|
||||
url: string,
|
||||
}
|
||||
|
||||
@Observed
|
||||
export class WebViewInfo {
|
||||
// position
|
||||
@@ -34,27 +39,26 @@ export class WebViewInfo {
|
||||
public w: number = 0;
|
||||
public h: number = 0;
|
||||
// url
|
||||
public url: string = ''
|
||||
public url: string = '';
|
||||
// tag
|
||||
public viewTag: string = ''
|
||||
public viewTag: number = 0;
|
||||
// Whether to display
|
||||
public visible: boolean = true
|
||||
|
||||
public visible: boolean = true;
|
||||
/*
|
||||
* doc : https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/arkui-ts/ts-basic-components-web.md#webcontroller
|
||||
*/
|
||||
public controller: WebController = new WebController()
|
||||
public controller: web.WebviewController = new web.WebviewController();
|
||||
|
||||
constructor(x: number, y: number, w: number, h: number, viewTag: string) {
|
||||
constructor(x: number, y: number, w: number, h: number, viewTag: number) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.viewTag = viewTag;
|
||||
|
||||
web.once("webInited", ()=>{
|
||||
if (this.url!= '') {
|
||||
this.controller.loadUrl({url: this.url});
|
||||
web.once("webInited", () => {
|
||||
if (this.url != '') {
|
||||
this.controller.loadUrl(this.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -63,33 +67,33 @@ export class WebViewInfo {
|
||||
@Component
|
||||
export struct CocosWebView {
|
||||
@ObjectLink viewInfo: WebViewInfo;
|
||||
public workPort: PortProxy;
|
||||
public workPort: PortProxy | null = null;
|
||||
|
||||
build() {
|
||||
Web({ src: "", controller: this.viewInfo.controller })
|
||||
Web({ src: this.viewInfo.url, controller: this.viewInfo.controller })
|
||||
.position({ x: this.viewInfo.x, y: this.viewInfo.y })
|
||||
.width(this.viewInfo.w)
|
||||
.height(this.viewInfo.h)
|
||||
.border({ width: 1 })
|
||||
.onPageBegin((event) => {
|
||||
this.workPort.postMessage("onPageBegin", {viewTag:this.viewInfo.viewTag, url:event.url});
|
||||
this.workPort?.postMessage("onPageBegin", {
|
||||
viewTag: this.viewInfo.viewTag as number,
|
||||
url: event?.url as string
|
||||
} as param);
|
||||
})
|
||||
.onPageEnd((event) => {
|
||||
this.workPort.postMessage("onPageEnd", {viewTag:this.viewInfo.viewTag, url:event.url})
|
||||
this.workPort?.postMessage("onPageEnd", { viewTag: this.viewInfo.viewTag as number, url: event?.url as string } as param)
|
||||
})
|
||||
.onErrorReceive((event) => {
|
||||
this.workPort.postMessage("onErrorReceive", {viewTag:this.viewInfo.viewTag, url:this.viewInfo.url})
|
||||
this.workPort?.postMessage("onErrorReceive", { viewTag: this.viewInfo.viewTag as number, url: this.viewInfo.url as string } as param)
|
||||
})
|
||||
.onHttpErrorReceive((event) => {
|
||||
this.workPort.postMessage("onErrorReceive", {viewTag:this.viewInfo.viewTag, url:this.viewInfo.url})
|
||||
this.workPort?.postMessage("onErrorReceive", { viewTag: this.viewInfo.viewTag as number, url: this.viewInfo.url as string } as param)
|
||||
})
|
||||
// 开启DOM存储权限
|
||||
.domStorageAccess(true)
|
||||
// 开启数据库存储权限
|
||||
.databaseAccess(true)
|
||||
// 图片加载相关权限
|
||||
.imageAccess(true)
|
||||
// 支持JS代码运行
|
||||
.javaScriptAccess(true)
|
||||
.domStorageAccess(true)// enable DOM storage permissions
|
||||
.databaseAccess(true)// enable database storage permissions
|
||||
.imageAccess(true)// enable image loading permissions
|
||||
.javaScriptAccess(true)// support JS code running
|
||||
.visibility(this.viewInfo.visible ? Visibility.Visible : Visibility.None)
|
||||
}
|
||||
}
|
@@ -21,16 +21,16 @@
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
****************************************************************************/
|
||||
@CustomDialog
|
||||
export struct EditBoxDialog {
|
||||
private showMessage: string = ''
|
||||
private inputMessage: string = ''
|
||||
onTextChange: (msg: string) => void
|
||||
accept: (msg: string) => void
|
||||
controller: CustomDialogController
|
||||
cancel: () => void
|
||||
confirm: () => void
|
||||
onTextChange?: (msg: string) => void;
|
||||
accept?: (msg: string) => void;
|
||||
controller?: CustomDialogController;
|
||||
cancel?: () => void;
|
||||
confirm?: () => void;
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
@@ -48,14 +48,14 @@ export struct EditBoxDialog {
|
||||
if (this.accept) {
|
||||
this.accept(this.inputMessage);
|
||||
}
|
||||
this.controller.close();
|
||||
this.controller?.close();
|
||||
})
|
||||
Blank(8).width(16)
|
||||
Button('完成').onClick(() => {
|
||||
if (this.accept) {
|
||||
this.accept(this.inputMessage);
|
||||
}
|
||||
this.controller.close();
|
||||
this.controller?.close();
|
||||
})
|
||||
}.padding({ left: 8, right: 8, top: 8, bottom: 8 })
|
||||
.backgroundColor(Color.Gray)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import cocos from "libcocos.so";
|
||||
import { ContextType } from "../common/Constants"
|
||||
import cocos from 'libcocos.so';
|
||||
import { ContextType } from '../common/Constants';
|
||||
import window from '@ohos.window';
|
||||
|
||||
const nativeContext = cocos.getContext(ContextType.ENGINE_UTILS);
|
||||
@@ -29,9 +29,9 @@ export default class EntryAbility extends UIAbility {
|
||||
}
|
||||
windowClass = data;
|
||||
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
|
||||
|
||||
|
||||
// 设置窗口为全屏布局,配合设置导航栏、状态栏是否显示,与主窗口显示保持协调一致。
|
||||
let isLayoutFullScreen= true;
|
||||
let isLayoutFullScreen = true;
|
||||
windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to set the window layout to full-screen mode. Cause: ' + JSON.stringify(err));
|
||||
@@ -39,7 +39,7 @@ export default class EntryAbility extends UIAbility {
|
||||
}
|
||||
console.info('Succeeded in setting the window layout to full-screen mode.');
|
||||
});
|
||||
|
||||
|
||||
// 设置状态栏和导航栏是否显示。例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。
|
||||
let visibleBar = [];
|
||||
windowClass.setWindowSystemBarEnable(visibleBar, (err) => {
|
||||
|
@@ -21,227 +21,264 @@
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
import nativerender from "libcocos.so";
|
||||
****************************************************************************/
|
||||
import nativerender from 'libcocos.so';
|
||||
|
||||
import { WorkerManager } from '../cocos/WorkerManager'
|
||||
import { ContextType } from "../common/Constants"
|
||||
import featureAbility from '@ohos.ability.featureAbility'
|
||||
import { EditBoxDialog } from '../components/EditBoxDialog'
|
||||
import { WebViewInfo, CocosWebView } from '../components/CocosWebView'
|
||||
import { VideoInfo, CocosVideoPlayer } from '../components/CocosVideoPlayer'
|
||||
import { WorkerManager } from '../cocos/WorkerManager';
|
||||
import { ContextType } from '../common/Constants';
|
||||
import { EditBoxDialog } from '../components/EditBoxDialog';
|
||||
import { CocosWebView, WebViewInfo } from '../components/CocosWebView';
|
||||
import { CocosVideoPlayer, VideoInfo } from '../components/CocosVideoPlayer';
|
||||
import { MessageEvent } from '@ohos.worker';
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
|
||||
import {PortProxy} from '../common/PortProxy'
|
||||
const nativePageLifecycle = nativerender.getContext(ContextType.JSPAGE_LIFECYCLE);
|
||||
const engineUtils = nativerender.getContext(ContextType.ENGINE_UTILS);
|
||||
|
||||
interface WorkerMessage {
|
||||
type: string;
|
||||
data: data;
|
||||
}
|
||||
|
||||
interface data {
|
||||
id: string,
|
||||
name: string,
|
||||
param: number | string | param
|
||||
}
|
||||
|
||||
interface param {
|
||||
tag?: number,
|
||||
url?: string,
|
||||
contents?: string,
|
||||
mimeType?: string,
|
||||
encoding?: string,
|
||||
baseUrl?: string,
|
||||
jsContents?: string,
|
||||
x?: number,
|
||||
y?: number,
|
||||
w?: number,
|
||||
h?: number,
|
||||
visible?: boolean,
|
||||
resourceType?: number,
|
||||
time?: number,
|
||||
fullScreen?: boolean
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@State showMessage: string = ''
|
||||
@State webViewArray: WebViewInfo[] = [];
|
||||
@State videoArray:VideoInfo[] = [];
|
||||
//private index: number = 0;
|
||||
private webViewIndexMap: Map<number, number> = new Map;
|
||||
private videoIndexMap: Map<number, number> = new Map;
|
||||
|
||||
private workPort : PortProxy = new PortProxy(WorkerManager.getInstance().getWorker());
|
||||
@State videoArray: VideoInfo[] = [];
|
||||
private webViewIndexMap: Map<number, number> = new Map<number, number>();
|
||||
private videoIndexMap: Map<number, number> = new Map<number, number>();
|
||||
private workPort: PortProxy = new PortProxy(WorkerManager.getInstance().getWorker());
|
||||
dialogController: CustomDialogController = new CustomDialogController({
|
||||
builder: EditBoxDialog({
|
||||
showMessage: this.showMessage,
|
||||
onTextChange: (msg: string) => {
|
||||
onTextChange: (msg: string): void => {
|
||||
this.showMessage = msg;
|
||||
this.workPort.postMessage('onTextInput', msg)
|
||||
this.workPort.postMessage('onTextInput', msg);
|
||||
},
|
||||
accept: (msg: string) => {
|
||||
accept: (msg: string): void => {
|
||||
this.showMessage = msg;
|
||||
this.workPort.postMessage('onComplete', msg)
|
||||
},
|
||||
this.workPort.postMessage('onComplete', msg);
|
||||
}
|
||||
}),
|
||||
cancel: () => {
|
||||
this.workPort.postMessage('onComplete', this.showMessage)
|
||||
cancel: (): void => {
|
||||
this.workPort.postMessage('onComplete', this.showMessage);
|
||||
},
|
||||
autoCancel: true,
|
||||
alignment: DialogAlignment.Bottom,
|
||||
customStyle: true,
|
||||
})
|
||||
|
||||
aboutToAppear(): void {
|
||||
aboutToAppear(): void {
|
||||
console.log('[LIFECYCLE-Index] cocos aboutToAppear');
|
||||
this.workPort._messageHandle = (e) => {
|
||||
//let data = e['data'];
|
||||
var data = e.data;
|
||||
var msg = data.data;
|
||||
var result;
|
||||
this.workPort._messageHandle = async (e: MessageEvent<WorkerMessage>): Promise<void> => {
|
||||
let data: WorkerMessage = e.data;
|
||||
let msg = data.data;
|
||||
let result: boolean | string | number | null = null;
|
||||
switch (msg.name) {
|
||||
// EditBox
|
||||
// EditBox
|
||||
case "showEditBox": {
|
||||
this.showMessage = msg.param
|
||||
this.dialogController.open()
|
||||
this.showMessage = msg.param as string;
|
||||
this.dialogController.open();
|
||||
break;
|
||||
}
|
||||
case "hideEditBox": {
|
||||
this.showMessage = ''
|
||||
this.dialogController.close()
|
||||
this.showMessage = '';
|
||||
this.dialogController.close();
|
||||
break;
|
||||
}
|
||||
// WebView
|
||||
// WebView
|
||||
case "createWebView": {
|
||||
this.webViewArray.push(new WebViewInfo(0, 0, 0, 0, msg.param))
|
||||
this.webViewIndexMap.set(msg.param, this.webViewArray.length - 1);
|
||||
this.webViewArray.push(new WebViewInfo(0, 0, 0, 0, msg.param as number));
|
||||
this.webViewIndexMap.set(msg.param as number, this.webViewArray.length - 1);
|
||||
break;
|
||||
}
|
||||
case "removeWebView": {
|
||||
if (this.webViewArray.length > 0) {
|
||||
this.webViewArray.splice(this.webViewIndexMap.get(msg.param), 1)
|
||||
this.webViewArray.splice(this.webViewIndexMap.get(msg?.param as number) as number, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "loadUrl": {
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag);
|
||||
this.webViewArray[index].url = web.url;
|
||||
this.webViewArray[index].controller.loadUrl({url: web.url});
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].url = web?.url as string;
|
||||
this.webViewArray[index].controller.loadUrl(web?.url as string);
|
||||
break;
|
||||
}
|
||||
case "loadHTMLString": {
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag);
|
||||
this.webViewArray[index].controller.loadData({data: web.contents, mimeType:"text/html",encoding:"UTF-8", baseUrl:web.baseUrl});
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].controller.loadData(
|
||||
web?.contents as string,
|
||||
"text/html",
|
||||
"UTF-8",
|
||||
web?.baseUrl
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "loadData": {
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag);
|
||||
this.webViewArray[index].controller.loadData({data: web.contents, mimeType:web.mimeType,encoding:web.encoding, baseUrl:web.baseUrl});
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].controller.loadData(
|
||||
web?.contents as string,
|
||||
web?.mimeType as string,
|
||||
web?.encoding as string,
|
||||
web?.baseUrl as string
|
||||
);
|
||||
break;
|
||||
}
|
||||
case "evaluateJS": {
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag)
|
||||
this.webViewArray[index].controller.runJavaScript({
|
||||
script: web.jsContents
|
||||
});
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].controller.runJavaScript(web?.jsContents as string);
|
||||
break;
|
||||
}
|
||||
case "reload": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.refresh();
|
||||
break;
|
||||
}
|
||||
case "stopLoading": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.stop();
|
||||
break;
|
||||
}
|
||||
case "canGoForward": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
result = this.webViewArray[index].controller.accessForward();
|
||||
break;
|
||||
}
|
||||
case "canGoBack": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
result = this.webViewArray[index].controller.accessBackward();
|
||||
break;
|
||||
}
|
||||
case "goForward": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.forward();
|
||||
break;
|
||||
}
|
||||
case "goBack": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
let index = this.webViewIndexMap.get(msg.param as number) as number;
|
||||
this.webViewArray[index].controller.backward();
|
||||
break;
|
||||
}
|
||||
case "setWebViewRect": {
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag);
|
||||
this.webViewArray[index].x = px2vp(web.x);
|
||||
this.webViewArray[index].y = px2vp(web.y);
|
||||
this.webViewArray[index].w = px2vp(web.w);
|
||||
this.webViewArray[index].h = px2vp(web.h);
|
||||
let web = msg.param as param
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].x = px2vp(web?.x as number) as number;
|
||||
this.webViewArray[index].y = px2vp(web?.y as number) as number;
|
||||
this.webViewArray[index].w = px2vp(web?.w as number) as number;
|
||||
this.webViewArray[index].h = px2vp(web?.h as number) as number;
|
||||
break;
|
||||
}
|
||||
case "setVisible":
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag);
|
||||
this.webViewArray[index].visible = web.visible;
|
||||
case "setVisible": {
|
||||
let web = msg.param as param;
|
||||
let index = this.webViewIndexMap.get(web?.tag as number) as number;
|
||||
this.webViewArray[index].visible = web?.visible as boolean;
|
||||
break;
|
||||
// video
|
||||
case "createVideo":
|
||||
this.videoArray.push(new VideoInfo(0, 0, 0, 0, msg.param))
|
||||
this.videoIndexMap.set(msg.param, this.videoArray.length - 1);
|
||||
}
|
||||
// video
|
||||
case "createVideo": {
|
||||
this.videoArray.push(new VideoInfo(0, 0, 0, 0, msg.param as number));
|
||||
this.videoIndexMap.set(msg.param as number, this.videoArray.length - 1);
|
||||
break;
|
||||
case "removeVideo":
|
||||
}
|
||||
case "removeVideo": {
|
||||
if (this.videoArray.length > 0) {
|
||||
this.videoArray.splice(this.videoIndexMap.get(msg.param), 1)
|
||||
this.videoArray.splice(this.videoIndexMap.get(msg.param as number) as number, 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "setVideoUrl":
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
var resourceType = video.resourceType;
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
let resourceType = video.resourceType;
|
||||
if (resourceType == 1) {
|
||||
this.videoArray[index].url = $rawfile(video.url);
|
||||
this.videoArray[index].url = $rawfile(video.url as string);
|
||||
} else {
|
||||
this.videoArray[index].url = video.url;
|
||||
this.videoArray[index].url = video.url as string;
|
||||
}
|
||||
break;
|
||||
case "setVideoRect": {
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
this.videoArray[index].x = px2vp(video.x);
|
||||
this.videoArray[index].y = px2vp(video.y);
|
||||
this.videoArray[index].w = px2vp(video.w);
|
||||
this.videoArray[index].h = px2vp(video.h);
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].x = px2vp(video?.x as number) as number;
|
||||
this.videoArray[index].y = px2vp(video?.y as number) as number;
|
||||
this.videoArray[index].w = px2vp(video?.w as number) as number;
|
||||
this.videoArray[index].h = px2vp(video?.h as number) as number;
|
||||
break;
|
||||
}
|
||||
case "startVideo": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
this.videoArray[index].controller.start();
|
||||
break;
|
||||
}
|
||||
case "pauseVideo" : {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
case "pauseVideo": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
this.videoArray[index].controller.pause();
|
||||
break;
|
||||
}
|
||||
case "stopVideo" : {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
case "stopVideo": {
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
this.videoArray[index].controller.stop();
|
||||
break;
|
||||
}
|
||||
case "resumeVideo": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
this.videoArray[index].controller.start();
|
||||
break;
|
||||
}
|
||||
case "getVideoDuration": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
result = this.videoArray[index].duration;
|
||||
break;
|
||||
}
|
||||
case "seekVideoTo" : {
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
this.videoArray[index].controller.setCurrentTime(video.time, SeekMode.Accurate);
|
||||
case "seekVideoTo": {
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].controller.setCurrentTime(video?.time as number, SeekMode.Accurate);
|
||||
break;
|
||||
}
|
||||
case "setVideoVisible" : {
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
this.videoArray[index].visible = video.visible;
|
||||
case "setVideoVisible": {
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].visible = video.visible as boolean;
|
||||
break;
|
||||
}
|
||||
case "setFullScreenEnabled": {
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
this.videoArray[index].isFullScreen = video.fullScreen;
|
||||
let video = msg.param as param;
|
||||
let index = this.videoIndexMap.get(video?.tag as number) as number;
|
||||
this.videoArray[index].isFullScreen = video.fullScreen as boolean;
|
||||
break;
|
||||
}
|
||||
case "currentTime": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
let index = this.videoIndexMap.get(msg.param as number) as number;
|
||||
result = this.videoArray[index].currentTime;
|
||||
break;
|
||||
}
|
||||
@@ -257,16 +294,16 @@ struct Index {
|
||||
|
||||
aboutToDisappear(): void {
|
||||
console.log('[LIFECYCLE-Index] cocos aboutToDisappear');
|
||||
// this.cocosWorker.postMessage({type: "JSPageLifecycle", data: "aboutToAppear"});
|
||||
// nativePageLifecycle.aboutToDisappear();
|
||||
// this.cocosWorker.postMessage({type: "JSPageLifecycle", data: "aboutToAppear"});
|
||||
// nativePageLifecycle.aboutToDisappear();
|
||||
}
|
||||
|
||||
onPageShow(): void {
|
||||
onPageShow(): void {
|
||||
console.log('[LIFECYCLE-Page] cocos onPageShow');
|
||||
nativePageLifecycle.onPageShow();
|
||||
}
|
||||
|
||||
onPageHide(): void {
|
||||
onPageHide(): void {
|
||||
console.log('[LIFECYCLE-Page] cocos onPageHide');
|
||||
nativePageLifecycle.onPageHide();
|
||||
}
|
||||
@@ -279,8 +316,12 @@ struct Index {
|
||||
}
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'cocos'})
|
||||
Flex({
|
||||
direction: FlexDirection.Column,
|
||||
alignItems: ItemAlign.Center,
|
||||
justifyContent: FlexAlign.Center
|
||||
} as FlexOptions) {
|
||||
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'cocos' })
|
||||
.onLoad((context) => {
|
||||
// Set the cache directory in the ts layer.
|
||||
this.workPort.postMessage("onXCLoad", "XComponent");
|
||||
@@ -289,13 +330,13 @@ struct Index {
|
||||
console.log('cocos onDestroy')
|
||||
})
|
||||
|
||||
ForEach(this.webViewArray, (item: WebViewInfo, index: number) => {
|
||||
CocosWebView({ viewInfo: item, workPort: this.workPort})
|
||||
}, item => item.viewTag)
|
||||
ForEach(this.webViewArray, (item: WebViewInfo) => {
|
||||
CocosWebView({ viewInfo: item, workPort: this.workPort })
|
||||
}, (item: WebViewInfo): string => item.viewTag.toString())
|
||||
|
||||
ForEach(this.videoArray, (item: VideoInfo, index: number) => {
|
||||
CocosVideoPlayer({ videoInfo: item, workPort: this.workPort})
|
||||
}, item => item.viewTag)
|
||||
ForEach(this.videoArray, (item: VideoInfo) => {
|
||||
CocosVideoPlayer({ videoInfo: item, workPort: this.workPort })
|
||||
}, (item: VideoInfo): string => item.viewTag.toString())
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
|
@@ -22,16 +22,15 @@ import hilog from '@ohos.hilog';
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
****************************************************************************/
|
||||
import worker from '@ohos.worker';
|
||||
import cocos from "libcocos.so";
|
||||
import { ContextType } from "../common/Constants"
|
||||
import { launchEngine } from '../cocos/game'
|
||||
import cocos from 'libcocos.so';
|
||||
import { ContextType } from '../common/Constants';
|
||||
import { launchEngine } from '../cocos/game';
|
||||
import { PortProxy } from '../common/PortProxy';
|
||||
|
||||
const nativeContext = cocos.getContext(ContextType.WORKER_INIT);
|
||||
nativeContext.workerInit()
|
||||
nativeContext.workerInit();
|
||||
|
||||
const nativeEditBox = cocos.getContext(ContextType.EDITBOX_UTILS);
|
||||
const nativeWebView = cocos.getContext(ContextType.WEBVIEW_UTILS);
|
||||
@@ -39,73 +38,66 @@ const appLifecycle = cocos.getContext(ContextType.APP_LIFECYCLE);
|
||||
|
||||
let uiPort = new PortProxy(worker.parentPort);
|
||||
|
||||
nativeContext.postMessage = function(msgType: string, msgData:string) {
|
||||
uiPort.postMessage(msgType, msgData);
|
||||
nativeContext.postMessage = function (msgType: string, msgData: string): void {
|
||||
uiPort.postMessage(msgType, msgData);
|
||||
}
|
||||
|
||||
nativeContext.postSyncMessage = async function(msgType: string, msgData:string) {
|
||||
const result = await uiPort.postSyncMessage(msgType, msgData);
|
||||
return result;
|
||||
nativeContext.postSyncMessage = async function (msgType: string, msgData: string): Promise<boolean | string | number> {
|
||||
const result = await uiPort.postSyncMessage(msgType, msgData) as boolean | string | number;
|
||||
return result;
|
||||
}
|
||||
|
||||
// The purpose of this is to avoid being GC
|
||||
nativeContext.setPostMessageFunction.call(nativeContext, nativeContext.postMessage)
|
||||
nativeContext.setPostSyncMessageFunction.call(nativeContext, nativeContext.postSyncMessage)
|
||||
|
||||
uiPort._messageHandle = function(e) {
|
||||
var data = e.data;
|
||||
var msg = data.data;
|
||||
hilog.info(0x0000, 'testTag',msg.name,msg.param);
|
||||
uiPort._messageHandle = function (e) {
|
||||
var data = e.data;
|
||||
var msg = data.data;
|
||||
|
||||
switch(msg.name) {
|
||||
case "onXCLoad":
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', '_messageHandle onXCLoad');
|
||||
console.info("cocos worker:_messageHandle onXCLoad");
|
||||
const renderContext = cocos.getContext(ContextType.NATIVE_RENDER_API);
|
||||
renderContext.nativeEngineInit();
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'begin invoke launchEngine');
|
||||
launchEngine().then(() => {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launch CC engine finished');
|
||||
console.info('launch CC engine finished');
|
||||
}).catch(e => {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'launch CC engine failed');
|
||||
console.error('launch CC engine failed');
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
globalThis.oh.postMessage = nativeContext.postMessage;
|
||||
// @ts-ignore
|
||||
globalThis.oh.postSyncMessage = nativeContext.postSyncMessage;
|
||||
renderContext.nativeEngineStart();
|
||||
break;
|
||||
case "onTextInput":
|
||||
nativeEditBox.onTextChange(msg.param);
|
||||
break;
|
||||
case "onComplete":
|
||||
nativeEditBox.onComplete(msg.param);
|
||||
break;
|
||||
case "onPageBegin":
|
||||
nativeWebView.shouldStartLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onPageEnd":
|
||||
nativeWebView.finishLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onErrorReceive":
|
||||
nativeWebView.failLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onVideoEvent":
|
||||
// @ts-ignore
|
||||
if(globalThis.oh && typeof globalThis.oh.onVideoEvent === "function") {
|
||||
// @ts-ignore
|
||||
globalThis.oh.onVideoEvent(msg.param.videoTag, msg.param.videoEvent, msg.param.args);
|
||||
}
|
||||
break;
|
||||
case "backPress":
|
||||
appLifecycle.onBackPress();
|
||||
break;
|
||||
default:
|
||||
hilog.info(0x0000, 'testTag', 'cocos worker: message type unknown:%{public}s', msg.name);
|
||||
console.error("cocos worker: message type unknown");
|
||||
break;
|
||||
}
|
||||
switch (msg.name) {
|
||||
case "onXCLoad":
|
||||
const renderContext = cocos.getContext(ContextType.NATIVE_RENDER_API);
|
||||
renderContext.nativeEngineInit();
|
||||
launchEngine().then(() => {
|
||||
console.info('launch CC engine finished');
|
||||
}).catch(e => {
|
||||
console.error('launch CC engine failed');
|
||||
});
|
||||
// @ts-ignore
|
||||
globalThis.oh.postMessage = nativeContext.postMessage;
|
||||
// @ts-ignore
|
||||
globalThis.oh.postSyncMessage = nativeContext.postSyncMessage;
|
||||
renderContext.nativeEngineStart();
|
||||
break;
|
||||
case "onTextInput":
|
||||
nativeEditBox.onTextChange(msg.param);
|
||||
break;
|
||||
case "onComplete":
|
||||
nativeEditBox.onComplete(msg.param);
|
||||
break;
|
||||
case "onPageBegin":
|
||||
nativeWebView.shouldStartLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onPageEnd":
|
||||
nativeWebView.finishLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onErrorReceive":
|
||||
nativeWebView.failLoading(msg.param.viewTag, msg.param.url);
|
||||
break;
|
||||
case "onVideoEvent":
|
||||
// @ts-ignore
|
||||
if (globalThis.oh && typeof globalThis.oh.onVideoEvent === "function") {
|
||||
// @ts-ignore
|
||||
globalThis.oh.onVideoEvent(msg.param.videoTag, msg.param.videoEvent, msg.param.args);
|
||||
}
|
||||
break;
|
||||
case "backPress":
|
||||
appLifecycle.onBackPress();
|
||||
break;
|
||||
default:
|
||||
hilog.info(0x0000, 'testTag', 'cocos worker: message type unknown:%{public}s', msg.name);
|
||||
console.error("cocos worker: message type unknown");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user