mirror of
https://github.com/smallmain/cocos-enhance-kit.git
synced 2025-09-24 09:21:54 +00:00
[engine] [cocos2d-x] [jsb-adapter] 适配引擎 v2.4.12 版本
This commit is contained in:
7
cocos2d-x/templates/js-template-default/frameworks/runtime-src/proj.openharmony/.gitignore
vendored
Normal file
7
cocos2d-x/templates/js-template-default/frameworks/runtime-src/proj.openharmony/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/node_modules
|
||||
/local.properties
|
||||
/oh_modules
|
||||
/.idea
|
||||
**/build
|
||||
/.hvigor
|
||||
log.txt
|
@@ -0,0 +1 @@
|
||||
{"app":{"bundleName":"org.cocos2d.demo","vendor":"example","versionCode":1000000,"versionName":"1.0.0","icon":"$media:app_icon","label":"$string:app_name","distributedNotificationEnabled":true}}
|
@@ -0,0 +1 @@
|
||||
{"string":[{"name":"app_name","value":"HarmonyDemo"}]}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,71 @@
|
||||
# the minimum version of CMake.
|
||||
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
set(CC_LIB_NAME cocos)
|
||||
set(CC_PROJ_SOURCES)
|
||||
set(CC_COCOS_SOURCES)
|
||||
set(CC_COMMON_SOURCES)
|
||||
set(CC_ALL_SOURCES)
|
||||
|
||||
option(APP_NAME "Project Name" "test-cases")
|
||||
project(${APP_NAME} CXX)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Werror=return-type -ferror-limit=0")
|
||||
|
||||
enable_language(C ASM)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
|
||||
include(${COCOS_X_PATH}/CMakeLists.txt)
|
||||
|
||||
list(APPEND CC_ALL_SOURCES ${CC_COCOS_SOURCES} ${CC_COMMON_SOURCES} ${CC_PROJ_SOURCES})
|
||||
add_library(${CC_LIB_NAME} SHARED ${CC_ALL_SOURCES})
|
||||
|
||||
# setup default flags
|
||||
cc_apply_definations(${CC_LIB_NAME})
|
||||
|
||||
find_library( # Sets the name of the path variable.
|
||||
EGL-lib
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
EGL )
|
||||
find_library( # Sets the name of the path variable.
|
||||
GLESv3-lib
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
GLESv3)
|
||||
|
||||
find_library( hilog-lib
|
||||
hilog_ndk.z )
|
||||
|
||||
find_library( # Sets the name of the path variable.
|
||||
libace-lib
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
ace_ndk.z )
|
||||
find_library( # Sets the name of the path variable.
|
||||
libnapi-lib
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
ace_napi.z )
|
||||
find_library( # Sets the name of the path variable.
|
||||
libuv-lib
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
uv )
|
||||
|
||||
find_library( # Sets the name of the path variable.
|
||||
rawfile-lib
|
||||
# Specifies the name of the NDK library that
|
||||
# you want CMake to locate.
|
||||
rawfile.z )
|
||||
message(STATUS, "rawfile=${rawfile-lib}")
|
||||
target_link_libraries(${CC_LIB_NAME} PUBLIC
|
||||
${EGL-lib} ${GLESv3-lib} ${hilog-lib} ${libace-lib} ${libnapi-lib} ${libuv-lib} ${rawfile-lib} libnative_drawing.so libc++.a libOpenSLES.so
|
||||
${CC_EXTERNAL_LIBS}
|
||||
)
|
||||
|
||||
|
||||
|
||||
#cc_openharmony_before_target(${CC_LIB_NAME})
|
||||
|
||||
#cc_openharmony_after_target(${CC_LIB_NAME})
|
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"app": {
|
||||
"signingConfigs": [
|
||||
],
|
||||
"compileSdkVersion": 9,
|
||||
"compatibleSdkVersion": 9,
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
/node_modules
|
||||
/.preview
|
||||
/build
|
||||
/.cxx
|
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"apiType": 'stageMode',
|
||||
"buildOption": {
|
||||
"externalNativeOptions": {
|
||||
"path": "../CMakeLists.txt",
|
||||
"arguments": "-v arm-linux-ohos -DOHOS_STL=c++_shared -std=c++17 -DCOCOS_X_PATH=../../cocos2d-x -DOPENHARMONY=1",
|
||||
"abiFilters": [
|
||||
"armeabi-v7a",
|
||||
"arm64-v8a"
|
||||
],
|
||||
"cppFlags": "",
|
||||
}
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"runtimeOS": "HarmonyOS"
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||
import { getHvigorNode } from '@ohos/hvigor'
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin'
|
||||
import * as path from 'path'
|
||||
// import { executeOnlineSign } from '../hw_sign/sign.js'
|
||||
|
||||
const mModule = getHvigorNode(__filename)
|
||||
const ohosPlugin = hapTasks(mModule)
|
||||
|
||||
const onlineSignHapTaskName = "onlineSignHap"
|
||||
const curTargetName = "default"
|
||||
const mModuleName = mModule.getName()
|
||||
const projectRootPath = process.cwd()
|
||||
|
||||
// 若是feature模块签名,此处填写依赖的entry模块名称
|
||||
const entryName = '';
|
||||
|
||||
// 注册在线签名任务和创建任务依赖
|
||||
const onlineSignTask = mModule.task(() => {
|
||||
// 构建的未签名的hap的输出根目录
|
||||
const moduleBuildOutputDir = path.resolve(projectRootPath, mModuleName, 'build/default/outputs/default/')
|
||||
|
||||
// 未签名的hap包路径
|
||||
const inputFile = path.resolve(moduleBuildOutputDir, `${mModuleName}${entryName? '-' + entryName: ''}-default-unsigned.hap`)
|
||||
// 签名后的hap包路径
|
||||
const outputFile = path.resolve(moduleBuildOutputDir, `${mModuleName}${entryName? '-' + entryName: ''}-default-signed.hap`)
|
||||
|
||||
// executeOnlineSign(inputFile, outputFile)
|
||||
}, onlineSignHapTaskName).dependsOn(`${curTargetName}@PackageHap`)
|
||||
|
||||
// 使用在线签名,可以把离线签名任务disable掉
|
||||
// if (onlineSignTask.getEnabled()) {
|
||||
// mModule.getTaskByName(`${curTargetName}@SignHap`).setEnabled(false)
|
||||
// }
|
||||
// 将在线签名任务挂接在assembleHap任务上,如果需要在IDE上使用,assembleHap任务是固定的
|
||||
mModule.getTaskByName("assembleHap").dependsOn(onlineSignHapTaskName)
|
||||
|
||||
module.exports = {
|
||||
ohos: ohosPlugin
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"license": "",
|
||||
"devDependencies": {},
|
||||
"author": "",
|
||||
"name": "entry",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
Need a cpp folder to fix the IDE can't compile native code for verion 3.0.0.992
|
@@ -0,0 +1,54 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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 {Constants} from '../common/Constants'
|
||||
|
||||
export class WorkerManager {
|
||||
private static instance: WorkerManager;
|
||||
private cocosWorker: any;
|
||||
|
||||
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}`);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,96 @@
|
||||
globalThis.oh = {};
|
||||
function boot() {
|
||||
const cc = globalThis.cc;
|
||||
var settings = globalThis._CCSettings;
|
||||
globalThis._CCSettings = undefined;
|
||||
var onProgress = null;
|
||||
|
||||
var RESOURCES = cc.AssetManager.BuiltinBundleName.RESOURCES;
|
||||
var INTERNAL = cc.AssetManager.BuiltinBundleName.INTERNAL;
|
||||
var MAIN = cc.AssetManager.BuiltinBundleName.MAIN;
|
||||
cc.macro.CLEANUP_IMAGE_CACHE = true
|
||||
var onStart = function () {
|
||||
cc.view.enableRetina(true);
|
||||
cc.view.resizeWithBrowserSize(true);
|
||||
|
||||
if (settings.orientation === 'landscape') {
|
||||
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
|
||||
}
|
||||
else if (settings.orientation === 'portrait') {
|
||||
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
|
||||
}
|
||||
cc.view.enableAutoFullScreen([
|
||||
cc.sys.BROWSER_TYPE_BAIDU,
|
||||
cc.sys.BROWSER_TYPE_BAIDU_APP,
|
||||
cc.sys.BROWSER_TYPE_WECHAT,
|
||||
cc.sys.BROWSER_TYPE_MOBILE_QQ,
|
||||
cc.sys.BROWSER_TYPE_MIUI,
|
||||
cc.sys.BROWSER_TYPE_HUAWEI,
|
||||
cc.sys.BROWSER_TYPE_UC,
|
||||
].indexOf(cc.sys.browserType) < 0);
|
||||
|
||||
var launchScene = settings.launchScene;
|
||||
var bundle = cc.assetManager.bundles.find(function (b) {
|
||||
return b.getSceneInfo(launchScene);
|
||||
});
|
||||
|
||||
bundle.loadScene(launchScene, null, onProgress,
|
||||
function (err, scene) {
|
||||
if (!err) {
|
||||
cc.director.runSceneImmediate(scene);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var option = {
|
||||
id: 'GameCanvas',
|
||||
debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
|
||||
showFPS: settings.debug,
|
||||
frameRate: 60,
|
||||
groupList: settings.groupList,
|
||||
collisionMatrix: settings.collisionMatrix,
|
||||
};
|
||||
|
||||
cc.assetManager.init({
|
||||
bundleVers: settings.bundleVers,
|
||||
remoteBundles: settings.remoteBundles,
|
||||
server: settings.server
|
||||
});
|
||||
|
||||
var bundleRoot = [INTERNAL];
|
||||
settings.hasResourcesBundle && bundleRoot.push(RESOURCES);
|
||||
|
||||
var count = 0;
|
||||
function cb(err) {
|
||||
if (err) {
|
||||
return console.error(err.message, err.stack);
|
||||
}
|
||||
count++;
|
||||
if (count === bundleRoot.length + 1) {
|
||||
cc.assetManager.loadBundle(MAIN, function (err) {
|
||||
if (!err) cc.game.run(option, onStart);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.oh.loadJsList(settings.jsList,cb);
|
||||
|
||||
for (var i = 0; i < bundleRoot.length; i++) {
|
||||
cc.assetManager.loadBundle(bundleRoot[i], cb);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
async function loadSysTemReady() {
|
||||
await import('./sys-ability-polyfill');
|
||||
await import('./index');
|
||||
}
|
||||
|
||||
export async function launchEngine() {
|
||||
return loadSysTemReady().then(() => {
|
||||
boot();
|
||||
}).catch(e => {
|
||||
console.log("load cocos-lib error,", e);
|
||||
});
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
require('./src/settings.js');
|
||||
require('./jsb-adapter/jsb-builtin.js');
|
||||
require('./src/cocos2d-jsb.js');
|
||||
require('./src/physics.js');
|
||||
require('./jsb-adapter/jsb-engine.js');
|
||||
|
||||
<%commonJSModuleMap%>
|
||||
|
||||
globalThis.oh.loadModule = (name) => {
|
||||
commonJSModuleMap[name]?.();
|
||||
};
|
||||
globalThis.oh.loadJsList = (jsList, cb) => {
|
||||
globalThis.cc.assetManager.loadScript(jsList.map(function (x) { return x; }), cb);
|
||||
};
|
@@ -0,0 +1,171 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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 display from '@ohos.display';
|
||||
import I18n from '@ohos.i18n';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
import batteryInfo from '@ohos.batteryInfo';
|
||||
import sensor from '@ohos.sensor';
|
||||
import connection from '@ohos.net.connection'
|
||||
import vibrator from '@ohos.vibrator';
|
||||
import process from '@ohos.process';
|
||||
import { ContextType } from "../common/Constants"
|
||||
import cocos from "libcocos.so";
|
||||
|
||||
const systemUtils = cocos.getContext(ContextType.SYSTEM_UTILS);
|
||||
|
||||
let pro = new process.ProcessManager();
|
||||
globalThis.getSystemLanguage = function () {
|
||||
return I18n.System.getSystemLanguage();
|
||||
}
|
||||
|
||||
globalThis.getOSFullName = function () {
|
||||
return deviceInfo.osFullName;
|
||||
}
|
||||
|
||||
globalThis.getDeviceModel = function () {
|
||||
return deviceInfo.productModel;
|
||||
}
|
||||
|
||||
globalThis.getBatteryLevel = function () {
|
||||
return batteryInfo.batterySOC;
|
||||
}
|
||||
|
||||
globalThis.getDPI = function () {
|
||||
var displayClass = display.getDefaultDisplaySync();
|
||||
return displayClass.densityDPI;
|
||||
}
|
||||
|
||||
globalThis.getPixelRation = function () {
|
||||
var displayClass = display.getDefaultDisplaySync();
|
||||
return displayClass.densityPixels;
|
||||
}
|
||||
|
||||
let onDisplayChange = (data) => {
|
||||
// Monitor changes in screen orientation.
|
||||
systemUtils.onDisplayChange(globalThis.getDeviceOrientation());
|
||||
}
|
||||
|
||||
try {
|
||||
display.on("change", onDisplayChange);
|
||||
} catch (exception) {
|
||||
console.log('Failed to register callback. Code: ' + JSON.stringify(exception));
|
||||
}
|
||||
|
||||
globalThis.getDeviceOrientation = function () {
|
||||
var displayClass = display.getDefaultDisplaySync();
|
||||
return displayClass.rotation;
|
||||
}
|
||||
|
||||
function radiansToDegrees(radians) {
|
||||
var pi = Math.PI;
|
||||
return radians * (180/pi);
|
||||
}
|
||||
|
||||
let sDeviceMotionValues = [];
|
||||
try {
|
||||
sensor.on(sensor.SensorId.ACCELEROMETER, function (data) {
|
||||
sDeviceMotionValues[0] = data.x;
|
||||
sDeviceMotionValues[1] = data.y;
|
||||
sDeviceMotionValues[2] = -data.z;
|
||||
},
|
||||
{ interval: 200000000 }
|
||||
);
|
||||
} catch (err) {
|
||||
sDeviceMotionValues[0] = 0;
|
||||
sDeviceMotionValues[1] = 0;
|
||||
sDeviceMotionValues[2] = 0;
|
||||
}
|
||||
|
||||
try {
|
||||
sensor.on(sensor.SensorId.LINEAR_ACCELEROMETER, function(data){
|
||||
sDeviceMotionValues[3] = data.x;
|
||||
sDeviceMotionValues[4] = data.y;
|
||||
sDeviceMotionValues[5] = data.z;
|
||||
},
|
||||
{interval: 200000000}
|
||||
);
|
||||
} catch (err) {
|
||||
sDeviceMotionValues[3] = 0;
|
||||
sDeviceMotionValues[4] = 0;
|
||||
sDeviceMotionValues[5] = 0;
|
||||
}
|
||||
try {
|
||||
sensor.on(sensor.SensorId.GYROSCOPE, function(data){
|
||||
sDeviceMotionValues[6] = radiansToDegrees(data.x);
|
||||
sDeviceMotionValues[7] = radiansToDegrees(data.y);
|
||||
sDeviceMotionValues[8] = radiansToDegrees(data.z);
|
||||
},
|
||||
{interval: 200000000}
|
||||
);
|
||||
} catch (err) {
|
||||
sDeviceMotionValues[6] = 0;
|
||||
sDeviceMotionValues[7] = 0;
|
||||
sDeviceMotionValues[8] = 0;
|
||||
}
|
||||
|
||||
globalThis.getDeviceMotionValue = function () {
|
||||
return sDeviceMotionValues;
|
||||
}
|
||||
|
||||
|
||||
globalThis.getNetworkType = function () {
|
||||
connection.getDefaultNet().then((netHandle)=>
|
||||
connection.getNetCapabilities(netHandle).then((data)=>{
|
||||
return data.bearerTypes;
|
||||
}).catch(err => {
|
||||
console.log('getDefaultNet error.' + JSON.stringify(err));
|
||||
return -1; // 未获取到网络连接类型
|
||||
})
|
||||
).catch(err => {
|
||||
console.log('getDefaultNet error.' + JSON.stringify(err));
|
||||
return -1; // 网络未连接
|
||||
});
|
||||
}
|
||||
|
||||
globalThis.vibrate = function (duration) {
|
||||
console.log('begin to vibrate, duration is.' + duration);
|
||||
try {
|
||||
vibrator.startVibration({
|
||||
type: 'time',
|
||||
duration: duration * 1000
|
||||
}, {
|
||||
id: 0,
|
||||
usage: 'alarm'
|
||||
}, (error) => {
|
||||
if (error) {
|
||||
console.error('vibrate fail, error.code: ' + error.code + 'error.message: ', + error.message);
|
||||
return error.code;
|
||||
}
|
||||
console.log('Vibration start sucessful.');
|
||||
return 0;
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('errCode: ' + err.code + ' ,msg: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.terminateProcess = function () {
|
||||
this.pro.exit(0);
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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.
|
||||
****************************************************************************/
|
||||
export enum ContextType {
|
||||
APP_LIFECYCLE = 0,
|
||||
JSPAGE_LIFECYCLE,
|
||||
XCOMPONENT_CONTEXT,
|
||||
XCOMPONENT_REGISTER_LIFECYCLE_CALLBACK,
|
||||
NATIVE_RENDER_API,
|
||||
WORKER_INIT,
|
||||
ENGINE_UTILS,
|
||||
EDITBOX_UTILS,
|
||||
WEBVIEW_UTILS,
|
||||
SYSTEM_UTILS,
|
||||
UV_ASYNC_SEND,
|
||||
}
|
||||
|
||||
export class Constants {
|
||||
static readonly APP_KEY_WORKER_MANAGER = "app_key_worker_manager";
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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 { MessageEvent } from '@ohos.worker';
|
||||
|
||||
export class PortProxy {
|
||||
private autoId: number = 0;
|
||||
public actionHandleMap = {}
|
||||
private port :DedicatedWorkerGlobalScope = null;
|
||||
|
||||
public _messageHandle?:(e: MessageEvent<any>) => void;
|
||||
|
||||
constructor (port) {
|
||||
this.port = port;
|
||||
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 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -0,0 +1,119 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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'
|
||||
|
||||
enum EventType {
|
||||
PLAYING = 0,
|
||||
PAUSED,
|
||||
STOPPED,
|
||||
COMPLETED,
|
||||
META_LOADED,
|
||||
CLICKED,
|
||||
READY_TO_PLAY,
|
||||
UPDATE,
|
||||
QUIT_FULLSCREEN = 1000
|
||||
};
|
||||
|
||||
@Observed
|
||||
export class VideoInfo {
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
public w: number = 0;
|
||||
public h: number = 0;
|
||||
// url
|
||||
public url: string | Resource = ""
|
||||
public viewTag: string = ''
|
||||
public visible: boolean = true
|
||||
|
||||
public duration: number = 0;
|
||||
public currentTime: number = 0;
|
||||
public isFullScreen: boolean = false;
|
||||
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) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.viewTag = viewTag
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
export struct CocosVideoPlayer {
|
||||
@ObjectLink videoInfo: VideoInfo;
|
||||
public workPort: PortProxy;
|
||||
build() {
|
||||
Video({ src: this.videoInfo.url, controller: this.videoInfo.controller, currentProgressRate:this.videoInfo.currentProgressRate })
|
||||
.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});
|
||||
})
|
||||
.onPause(() => {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.PAUSED});
|
||||
})
|
||||
.onFinish(() => {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.COMPLETED});
|
||||
})
|
||||
.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});
|
||||
})
|
||||
.onClick((event: ClickEvent) => {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.CLICKED});
|
||||
})
|
||||
.onUpdate((event?: {
|
||||
time: number;
|
||||
}) => {
|
||||
this.videoInfo.currentTime = event.time
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.UPDATE, args:event.time});
|
||||
})
|
||||
.onFullscreenChange((event?: {
|
||||
fullscreen: boolean;
|
||||
}) => {
|
||||
if (!event.fullscreen) {
|
||||
this.workPort.postMessage("onVideoEvent",{videoTag:this.videoInfo.viewTag, videoEvent:EventType.QUIT_FULLSCREEN});
|
||||
}
|
||||
this.videoInfo.isFullScreen = event.fullscreen
|
||||
})
|
||||
.visibility(this.videoInfo.visible ? Visibility.Visible : Visibility.None)
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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 web from '@ohos.web.webview'
|
||||
@Observed
|
||||
export class WebViewInfo {
|
||||
// position
|
||||
public x: number = 0;
|
||||
public y: number = 0;
|
||||
// size
|
||||
public w: number = 0;
|
||||
public h: number = 0;
|
||||
// url
|
||||
public url: string = ''
|
||||
// tag
|
||||
public viewTag: string = ''
|
||||
// Whether to display
|
||||
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()
|
||||
|
||||
constructor(x: number, y: number, w: number, h: number, viewTag: string) {
|
||||
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});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
export struct CocosWebView {
|
||||
@ObjectLink viewInfo: WebViewInfo;
|
||||
public workPort: PortProxy;
|
||||
build() {
|
||||
Web({ src: "", 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});
|
||||
})
|
||||
.onPageEnd((event) => {
|
||||
this.workPort.postMessage("onPageEnd", {viewTag:this.viewInfo.viewTag, url:event.url})
|
||||
})
|
||||
.onErrorReceive((event) => {
|
||||
this.workPort.postMessage("onErrorReceive", {viewTag:this.viewInfo.viewTag, url:this.viewInfo.url})
|
||||
})
|
||||
.onHttpErrorReceive((event) => {
|
||||
this.workPort.postMessage("onErrorReceive", {viewTag:this.viewInfo.viewTag, url:this.viewInfo.url})
|
||||
})
|
||||
// 开启DOM存储权限
|
||||
.domStorageAccess(true)
|
||||
// 开启数据库存储权限
|
||||
.databaseAccess(true)
|
||||
// 图片加载相关权限
|
||||
.imageAccess(true)
|
||||
// 支持JS代码运行
|
||||
.javaScriptAccess(true)
|
||||
.visibility(this.viewInfo.visible ? Visibility.Visible : Visibility.None)
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Row() {
|
||||
TextInput({ text: this.showMessage })
|
||||
.backgroundColor('#ffffff')
|
||||
.layoutWeight(1)
|
||||
.onChange((value) => {
|
||||
if (this.onTextChange) {
|
||||
this.onTextChange(value);
|
||||
}
|
||||
this.inputMessage = value;
|
||||
})
|
||||
.onSubmit((value) => {
|
||||
if (this.accept) {
|
||||
this.accept(this.inputMessage);
|
||||
}
|
||||
this.controller.close();
|
||||
})
|
||||
Blank(8).width(16)
|
||||
Button('完成').onClick(() => {
|
||||
if (this.accept) {
|
||||
this.accept(this.inputMessage);
|
||||
}
|
||||
this.controller.close();
|
||||
})
|
||||
}.padding({ left: 8, right: 8, top: 8, bottom: 8 })
|
||||
.backgroundColor(Color.Gray)
|
||||
|
||||
}
|
||||
.width('100%')
|
||||
|
||||
.justifyContent(FlexAlign.End)
|
||||
}
|
||||
}
|
@@ -0,0 +1,78 @@
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import cocos from "libcocos.so";
|
||||
import { ContextType } from "../common/Constants"
|
||||
import window from '@ohos.window';
|
||||
|
||||
const nativeContext = cocos.getContext(ContextType.ENGINE_UTILS);
|
||||
const nativeAppLifecycle = cocos.getContext(ContextType.APP_LIFECYCLE);
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want, launchParam) {
|
||||
globalThis.abilityWant = want;
|
||||
nativeAppLifecycle.onCreate();
|
||||
nativeContext.resourceManagerInit(this.context.resourceManager);
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
nativeAppLifecycle.onDestroy();
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
nativeContext.writablePathInit(this.context.cacheDir);
|
||||
|
||||
// Get the Main window instance
|
||||
let windowClass = null;
|
||||
windowStage.getMainWindow((err, data) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to obtain the main window. Cause: ' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
windowClass = data;
|
||||
console.info('Succeeded in obtaining the main window. Data: ' + JSON.stringify(data));
|
||||
|
||||
// 设置窗口为全屏布局,配合设置导航栏、状态栏是否显示,与主窗口显示保持协调一致。
|
||||
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));
|
||||
return;
|
||||
}
|
||||
console.info('Succeeded in setting the window layout to full-screen mode.');
|
||||
});
|
||||
|
||||
// 设置状态栏和导航栏是否显示。例如,需全部显示,该参数设置为['status', 'navigation'];不设置,则默认不显示。
|
||||
let visibleBar = [];
|
||||
windowClass.setWindowSystemBarEnable(visibleBar, (err) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to set the system bar to be invisible. Cause: ' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
console.info('Succeeded in setting the system bar to be invisible.');
|
||||
});
|
||||
});
|
||||
|
||||
// Main window is created, set main page for this ability
|
||||
windowStage.loadContent("pages/index", (err, data) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
nativeAppLifecycle.onShow();
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
nativeAppLifecycle.onHide();
|
||||
}
|
||||
}
|
@@ -0,0 +1,303 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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 { 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 {PortProxy} from '../common/PortProxy'
|
||||
const nativePageLifecycle = nativerender.getContext(ContextType.JSPAGE_LIFECYCLE);
|
||||
const engineUtils = nativerender.getContext(ContextType.ENGINE_UTILS);
|
||||
|
||||
@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());
|
||||
dialogController: CustomDialogController = new CustomDialogController({
|
||||
builder: EditBoxDialog({
|
||||
showMessage: this.showMessage,
|
||||
onTextChange: (msg: string) => {
|
||||
this.showMessage = msg;
|
||||
this.workPort.postMessage('onTextInput', msg)
|
||||
},
|
||||
accept: (msg: string) => {
|
||||
this.showMessage = msg;
|
||||
this.workPort.postMessage('onComplete', msg)
|
||||
},
|
||||
}),
|
||||
cancel: () => {
|
||||
this.workPort.postMessage('onComplete', this.showMessage)
|
||||
},
|
||||
autoCancel: true,
|
||||
alignment: DialogAlignment.Bottom,
|
||||
customStyle: true,
|
||||
})
|
||||
|
||||
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;
|
||||
switch (msg.name) {
|
||||
// EditBox
|
||||
case "showEditBox": {
|
||||
this.showMessage = msg.param
|
||||
this.dialogController.open()
|
||||
break;
|
||||
}
|
||||
case "hideEditBox": {
|
||||
this.showMessage = ''
|
||||
this.dialogController.close()
|
||||
break;
|
||||
}
|
||||
// WebView
|
||||
case "createWebView": {
|
||||
this.webViewArray.push(new WebViewInfo(0, 0, 0, 0, msg.param))
|
||||
this.webViewIndexMap.set(msg.param, this.webViewArray.length - 1);
|
||||
break;
|
||||
}
|
||||
case "removeWebView": {
|
||||
if (this.webViewArray.length > 0) {
|
||||
this.webViewArray.splice(this.webViewIndexMap.get(msg.param), 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});
|
||||
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});
|
||||
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});
|
||||
break;
|
||||
}
|
||||
case "evaluateJS": {
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag)
|
||||
this.webViewArray[index].controller.runJavaScript({
|
||||
script: web.jsContents
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "reload": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
this.webViewArray[index].controller.refresh();
|
||||
break;
|
||||
}
|
||||
case "stopLoading": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
this.webViewArray[index].controller.stop();
|
||||
break;
|
||||
}
|
||||
case "canGoForward": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
result = this.webViewArray[index].controller.accessForward();
|
||||
break;
|
||||
}
|
||||
case "canGoBack": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
result = this.webViewArray[index].controller.accessBackward();
|
||||
break;
|
||||
}
|
||||
case "goForward": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
this.webViewArray[index].controller.forward();
|
||||
break;
|
||||
}
|
||||
case "goBack": {
|
||||
var index = this.webViewIndexMap.get(msg.param);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
case "setVisible":
|
||||
var web = msg.param;
|
||||
var index = this.webViewIndexMap.get(web.tag);
|
||||
this.webViewArray[index].visible = web.visible;
|
||||
break;
|
||||
// video
|
||||
case "createVideo":
|
||||
this.videoArray.push(new VideoInfo(0, 0, 0, 0, msg.param))
|
||||
this.videoIndexMap.set(msg.param, this.videoArray.length - 1);
|
||||
break;
|
||||
case "removeVideo":
|
||||
if (this.videoArray.length > 0) {
|
||||
this.videoArray.splice(this.videoIndexMap.get(msg.param), 1)
|
||||
}
|
||||
break;
|
||||
case "setVideoUrl":
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
var resourceType = video.resourceType;
|
||||
if (resourceType == 1) {
|
||||
this.videoArray[index].url = $rawfile(video.url);
|
||||
} else {
|
||||
this.videoArray[index].url = video.url;
|
||||
}
|
||||
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);
|
||||
break;
|
||||
}
|
||||
case "startVideo": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
this.videoArray[index].controller.start();
|
||||
break;
|
||||
}
|
||||
case "pauseVideo" : {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
this.videoArray[index].controller.pause();
|
||||
break;
|
||||
}
|
||||
case "stopVideo" : {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
this.videoArray[index].controller.stop();
|
||||
break;
|
||||
}
|
||||
case "resumeVideo": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
this.videoArray[index].controller.start();
|
||||
break;
|
||||
}
|
||||
case "getVideoDuration": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
case "setVideoVisible" : {
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
this.videoArray[index].visible = video.visible;
|
||||
break;
|
||||
}
|
||||
case "setFullScreenEnabled": {
|
||||
var video = msg.param;
|
||||
var index = this.videoIndexMap.get(video.tag);
|
||||
this.videoArray[index].isFullScreen = video.fullScreen;
|
||||
break;
|
||||
}
|
||||
case "currentTime": {
|
||||
var index = this.videoIndexMap.get(msg.param);
|
||||
result = this.videoArray[index].currentTime;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
}
|
||||
}
|
||||
if (result != null || result != undefined) {
|
||||
this.workPort.postReturnMessage(data, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aboutToDisappear(): void {
|
||||
console.log('[LIFECYCLE-Index] cocos aboutToDisappear');
|
||||
// this.cocosWorker.postMessage({type: "JSPageLifecycle", data: "aboutToAppear"});
|
||||
// nativePageLifecycle.aboutToDisappear();
|
||||
}
|
||||
|
||||
onPageShow(): void {
|
||||
console.log('[LIFECYCLE-Page] cocos onPageShow');
|
||||
nativePageLifecycle.onPageShow();
|
||||
}
|
||||
|
||||
onPageHide(): void {
|
||||
console.log('[LIFECYCLE-Page] cocos onPageHide');
|
||||
nativePageLifecycle.onPageHide();
|
||||
}
|
||||
|
||||
onBackPress() {
|
||||
console.log("[LIFECYCLE-Page] cocos onBackPress");
|
||||
this.workPort.postMessage("backPress", "");
|
||||
// If disable system exit needed, remove comment "return true"
|
||||
// return true;
|
||||
}
|
||||
|
||||
build() {
|
||||
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
|
||||
XComponent({ id: 'xcomponentId', type: 'surface', libraryname: 'cocos'})
|
||||
.onLoad((context) => {
|
||||
// Set the cache directory in the ts layer.
|
||||
this.workPort.postMessage("onXCLoad", "XComponent");
|
||||
})
|
||||
.onDestroy(() => {
|
||||
console.log('cocos onDestroy')
|
||||
})
|
||||
|
||||
ForEach(this.webViewArray, (item: WebViewInfo, index: number) => {
|
||||
CocosWebView({ viewInfo: item, workPort: this.workPort})
|
||||
}, item => item.viewTag)
|
||||
|
||||
ForEach(this.videoArray, (item: VideoInfo, index: number) => {
|
||||
CocosVideoPlayer({ videoInfo: item, workPort: this.workPort})
|
||||
}, item => item.viewTag)
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
}
|
||||
}
|
@@ -0,0 +1,111 @@
|
||||
import hilog from '@ohos.hilog';
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
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 { PortProxy } from '../common/PortProxy';
|
||||
|
||||
const nativeContext = cocos.getContext(ContextType.WORKER_INIT);
|
||||
nativeContext.workerInit()
|
||||
|
||||
const nativeEditBox = cocos.getContext(ContextType.EDITBOX_UTILS);
|
||||
const nativeWebView = cocos.getContext(ContextType.WEBVIEW_UTILS);
|
||||
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.postSyncMessage = async function(msgType: string, msgData:string) {
|
||||
const result = await uiPort.postSyncMessage(msgType, msgData);
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"description": "$string:entry_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"default"
|
||||
],
|
||||
"requestPermissions":[
|
||||
{"name" : "ohos.permission.INTERNET"},
|
||||
{"name" : "ohos.permission.VIBRATE"},
|
||||
{"name" : "ohos.permission.GET_NETWORK_INFO"},
|
||||
{"name" : "ohos.permission.ACCELEROMETER"},
|
||||
{"name" : "ohos.permission.GYROSCOPE"}
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "MainAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ts",
|
||||
"description": "$string:MainAbility_desc",
|
||||
"orientation": "portrait",
|
||||
"icon": "$media:icon",
|
||||
"label": "$string:MainAbility_label",
|
||||
"startWindowIcon": "$media:icon",
|
||||
"startWindowBackground": "$color:white",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "white",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "MainAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "MainAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "permissions_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/index"
|
||||
]
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"hvigorVersion":"2.4.2",
|
||||
"dependencies":{
|
||||
"@ohos/hvigor-ohos-plugin":"2.4.2"
|
||||
}
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||
export { appTasks } from '@ohos/hvigor-ohos-plugin';
|
@@ -0,0 +1,48 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Hvigor startup script, version 1.0.0
|
||||
#
|
||||
# Required ENV vars:
|
||||
# ------------------
|
||||
# NODE_HOME - location of a Node home dir
|
||||
# or
|
||||
# Add /usr/local/nodejs/bin to the PATH environment variable
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
HVIGOR_APP_HOME=$(dirname $(readlink -f $0))
|
||||
HVIGOR_WRAPPER_SCRIPT=${HVIGOR_APP_HOME}/hvigor/hvigor-wrapper.js
|
||||
warn() {
|
||||
echo ""
|
||||
echo -e "\033[1;33m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo ""
|
||||
echo -e "\033[1;31m`date '+[%Y-%m-%d %H:%M:%S]'`$@\033[0m"
|
||||
}
|
||||
|
||||
fail() {
|
||||
error "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Determine node to start hvigor wrapper script
|
||||
if [ -n "${NODE_HOME}" ];then
|
||||
EXECUTABLE_NODE="${NODE_HOME}/bin/node"
|
||||
if [ ! -x "$EXECUTABLE_NODE" ];then
|
||||
fail "ERROR: NODE_HOME is set to an invalid directory,check $NODE_HOME\n\nPlease set NODE_HOME in your environment to the location where your nodejs installed"
|
||||
fi
|
||||
else
|
||||
EXECUTABLE_NODE="node"
|
||||
which ${EXECUTABLE_NODE} > /dev/null 2>&1 || fail "ERROR: NODE_HOME is not set and not 'node' command found in your path"
|
||||
fi
|
||||
|
||||
# Check hvigor wrapper script
|
||||
if [ ! -r "$HVIGOR_WRAPPER_SCRIPT" ];then
|
||||
fail "ERROR: Couldn't find hvigor/hvigor-wrapper.js in ${HVIGOR_APP_HOME}"
|
||||
fi
|
||||
|
||||
# start hvigor-wrapper script
|
||||
exec "${EXECUTABLE_NODE}" \
|
||||
"${HVIGOR_WRAPPER_SCRIPT}" "$@"
|
@@ -0,0 +1,64 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Hvigor startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
set WRAPPER_MODULE_PATH=%APP_HOME%\hvigor\hvigor-wrapper.js
|
||||
set NODE_EXE=node.exe
|
||||
|
||||
goto start
|
||||
|
||||
:start
|
||||
@rem Find node.exe
|
||||
if defined NODE_HOME goto findNodeFromNodeHome
|
||||
|
||||
%NODE_EXE% --version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the NODE_HOME variable in your environment to match the
|
||||
echo location of your NodeJs installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findNodeFromNodeHome
|
||||
set NODE_HOME=%NODE_HOME:"=%
|
||||
set NODE_EXE_PATH=%NODE_HOME%/%NODE_EXE%
|
||||
|
||||
if exist "%NODE_EXE_PATH%" goto execute
|
||||
echo.
|
||||
echo ERROR: NODE_HOME is not set and no 'node' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the NODE_HOME variable in your environment to match the
|
||||
echo location of your NodeJs installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Execute hvigor
|
||||
"%NODE_EXE%" %WRAPPER_MODULE_PATH% %*
|
||||
|
||||
if "%ERRORLEVEL%" == "0" goto hvigorwEnd
|
||||
|
||||
:fail
|
||||
exit /b 1
|
||||
|
||||
:hvigorwEnd
|
||||
if "%OS%" == "Windows_NT" endlocal
|
||||
|
||||
:end
|
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.6"
|
||||
},
|
||||
"author": "",
|
||||
"name": "myapplication",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {}
|
||||
}
|
Reference in New Issue
Block a user