mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
openharmony: add servoshell for ohos (#33295)
* openharmony: add servoshell for ohos Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> * ohos: handle missing signing config on forks Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com> --------- Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
This commit is contained in:
parent
457d37d94e
commit
157e28c59b
31 changed files with 625 additions and 9 deletions
10
support/openharmony/AppScope/app.json5
Normal file
10
support/openharmony/AppScope/app.json5
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"app": {
|
||||
"bundleName": "org.servo.servoshell",
|
||||
"vendor": "example",
|
||||
"versionCode": 1000000,
|
||||
"versionName": "1.0.0",
|
||||
"icon": "$media:servo_64",
|
||||
"label": "$string:app_name"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "Servo Shell"
|
||||
}
|
||||
]
|
||||
}
|
1
support/openharmony/AppScope/resources/base/media/servo_64.png
Symbolic link
1
support/openharmony/AppScope/resources/base/media/servo_64.png
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../../../../resources/servo_64.png
|
44
support/openharmony/build-profile.json5
Normal file
44
support/openharmony/build-profile.json5
Normal file
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"app": {
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
"compileSdkVersion": 11,
|
||||
"compatibleSdkVersion": 11,
|
||||
"targetSdkVersion": 11,
|
||||
"runtimeOS": "OpenHarmony"
|
||||
},
|
||||
{
|
||||
"name": "harmonyos",
|
||||
"signingConfig": "default",
|
||||
"compatibleSdkVersion": "4.1.0(11)",
|
||||
"targetSdkVersion": "4.1.0(11)",
|
||||
"runtimeOS": "HarmonyOS"
|
||||
}
|
||||
],
|
||||
"buildModeSet": [
|
||||
{
|
||||
"name": "debug"
|
||||
},
|
||||
{
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "servoshell",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default",
|
||||
"harmonyos"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
36
support/openharmony/entry/build-profile.json5
Normal file
36
support/openharmony/entry/build-profile.json5
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
"arkOptions": {
|
||||
},
|
||||
"externalNativeOptions": {
|
||||
"path": "./src/main/cpp/CMakeLists.txt",
|
||||
"arguments": "",
|
||||
"cppFlags": "",
|
||||
"abiFilters": ["arm64-v8a", "x86_64"]
|
||||
}
|
||||
},
|
||||
"buildOptionSet": [
|
||||
{
|
||||
"name": "release",
|
||||
"arkOptions": {
|
||||
"obfuscation": {
|
||||
"ruleOptions": {
|
||||
"enable": true,
|
||||
"files": [
|
||||
"./obfuscation-rules.txt"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
"targets": [
|
||||
{
|
||||
"name": "default"
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
6
support/openharmony/entry/hvigorfile.ts
Normal file
6
support/openharmony/entry/hvigorfile.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
18
support/openharmony/entry/obfuscation-rules.txt
Normal file
18
support/openharmony/entry/obfuscation-rules.txt
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Define project specific obfuscation rules here.
|
||||
# You can include the obfuscation configuration files in the current module's build-profile.json5.
|
||||
#
|
||||
# For more details, see
|
||||
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
|
||||
|
||||
# Obfuscation options:
|
||||
# -disable-obfuscation: disable all obfuscations
|
||||
# -enable-property-obfuscation: obfuscate the property names
|
||||
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
|
||||
# -compact: remove unnecessary blank spaces and all line feeds
|
||||
# -remove-log: remove all console.* statements
|
||||
# -print-namecache: print the name cache that contains the mapping from the old names to new names
|
||||
# -apply-namecache: reuse the given cache file
|
||||
|
||||
# Keep options:
|
||||
# -keep-property-name: specifies property names that you want to keep
|
||||
# -keep-global-name: specifies names that you want to keep in the global scope
|
12
support/openharmony/entry/oh-package.json5
Normal file
12
support/openharmony/entry/oh-package.json5
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {},
|
||||
"author": "",
|
||||
"name": "servoshell",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"libservoshell.so": "file:./src/main/cpp/types/libentry"
|
||||
}
|
||||
}
|
3
support/openharmony/entry/src/main/cpp/CMakeLists.txt
Normal file
3
support/openharmony/entry/src/main/cpp/CMakeLists.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
# the minimum version of CMake.
|
||||
cmake_minimum_required(VERSION 3.4.1)
|
||||
project(servoshell)
|
1
support/openharmony/entry/src/main/cpp/types/libentry/index.d.ts
vendored
Normal file
1
support/openharmony/entry/src/main/cpp/types/libentry/index.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
export const loadURL: (url: string) => void;
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "libservoshell.so",
|
||||
"types": "./index.d.ts",
|
||||
"version": "",
|
||||
"description": "The native module which exposes a C API to servoshell"
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
import AbilityConstant from '@ohos.app.ability.AbilityConstant';
|
||||
import hilog from '@ohos.hilog';
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import Want from '@ohos.app.ability.Want';
|
||||
import window from '@ohos.window';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
}
|
||||
|
||||
onDestroy() {
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy() {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground() {
|
||||
// Ability has brought to foreground
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground() {
|
||||
// Ability has back to background
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
};
|
85
support/openharmony/entry/src/main/ets/pages/Index.ets
Normal file
85
support/openharmony/entry/src/main/ets/pages/Index.ets
Normal file
|
@ -0,0 +1,85 @@
|
|||
import display from '@ohos.display';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
|
||||
interface ServoXComponentInterface {
|
||||
loadURL(url: string): void;
|
||||
registerURLcallback(callback: (url: string) => void): void;
|
||||
initServo(options: InitOpts): void;
|
||||
}
|
||||
|
||||
interface InitOpts {
|
||||
url: string;
|
||||
deviceType: string,
|
||||
osFullName: string,
|
||||
displayDensity: number,
|
||||
}
|
||||
|
||||
function get_density(): number {
|
||||
try {
|
||||
let displayClass = display.getDefaultDisplaySync();
|
||||
console.info('Test densityDPI:' + JSON.stringify(displayClass.densityDPI));
|
||||
return displayClass.densityDPI / 160;
|
||||
} catch (exception) {
|
||||
console.error('Failed to obtain the default display object. Code: ' + JSON.stringify(exception));
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
function get_device_type(): string {
|
||||
let device_type: string = deviceInfo.deviceType;
|
||||
if (device_type == "") {
|
||||
console.error("deviceInfo.deviceType is empty string!")
|
||||
} else {
|
||||
console.info("Device type is " + device_type)
|
||||
}
|
||||
return device_type;
|
||||
}
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
xComponentContext: ServoXComponentInterface | undefined = undefined;
|
||||
xComponentAttrs: XComponentAttrs = {
|
||||
id: 'ServoDemo',
|
||||
type: XComponentType.SURFACE,
|
||||
libraryname: 'servoshell',
|
||||
}
|
||||
@State urlToLoad: string = 'https://servo.org'
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
TextInput({placeholder:'URL',text: $$this.urlToLoad})
|
||||
.type(InputType.Normal)
|
||||
.onChange((value) => {
|
||||
this.urlToLoad = value
|
||||
})
|
||||
.onSubmit((EnterKeyType)=>{
|
||||
this.xComponentContext?.loadURL(this.urlToLoad)
|
||||
console.info('Load URL: ', this.urlToLoad)
|
||||
})
|
||||
XComponent(this.xComponentAttrs)
|
||||
.focusable(true)
|
||||
.onLoad((xComponentContext) => {
|
||||
this.xComponentContext = xComponentContext as ServoXComponentInterface;
|
||||
let init_options: InitOpts = {
|
||||
url: this.urlToLoad,
|
||||
deviceType: get_device_type(),
|
||||
osFullName: deviceInfo.osFullName,
|
||||
displayDensity: get_density()
|
||||
}
|
||||
this.xComponentContext.initServo(init_options)
|
||||
this.xComponentContext.registerURLcallback((new_url) => {
|
||||
console.info('New URL from native: ', new_url)
|
||||
this.urlToLoad = new_url
|
||||
})
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
}
|
||||
}
|
||||
|
||||
interface XComponentAttrs {
|
||||
id: string;
|
||||
type: number;
|
||||
libraryname: string;
|
||||
}
|
52
support/openharmony/entry/src/main/module.json5
Normal file
52
support/openharmony/entry/src/main/module.json5
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"module": {
|
||||
"name": "servoshell",
|
||||
"type": "entry",
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"default"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:servo_1024",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:servo_64",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
// ohos.permission.RUN_DYN_CODE - required for JIT?
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.GET_NETWORK_INFO",
|
||||
"reason": "$string:perm_reason",
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.INTERNET",
|
||||
"reason": "$string:perm_reason",
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.KEEP_BACKGROUND_RUNNING",
|
||||
"reason": "$string:perm_reason",
|
||||
},
|
||||
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "perm_reason",
|
||||
"value": "This is a demo app, and we need permissions"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../../resources/servo_1024.png
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../../resources/servo_64.png
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "Servo"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "模块描述"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "Servo"
|
||||
}
|
||||
]
|
||||
}
|
17
support/openharmony/hvigor/hvigor-config.json5
Normal file
17
support/openharmony/hvigor/hvigor-config.json5
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"dependencies": {
|
||||
},
|
||||
"execution": {
|
||||
// "daemon": true, /* Enable daemon compilation. Default: true */
|
||||
// "incremental": true, /* Enable incremental compilation. Default: true */
|
||||
// "parallel": true, /* Enable parallel compilation. Default: true */
|
||||
// "typeCheck": false, /* Enable typeCheck. Default: false */
|
||||
},
|
||||
"logging": {
|
||||
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
|
||||
},
|
||||
"debugging": {
|
||||
// "stacktrace": false /* Disable stacktrace compilation. Default: false */
|
||||
}
|
||||
}
|
34
support/openharmony/hvigorfile.ts
Normal file
34
support/openharmony/hvigorfile.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { appTasks, OhosAppContext, OhosPluginId } from '@ohos/hvigor-ohos-plugin';
|
||||
import { getNode } from '@ohos/hvigor'
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
const rootNode = getNode(__filename);
|
||||
rootNode.afterNodeEvaluate(node => {
|
||||
const appContext = node.getContext(OhosPluginId.OHOS_APP_PLUGIN) as OhosAppContext;
|
||||
const buildProfileOpt = appContext.getBuildProfileOpt();
|
||||
const signingConfigsPath = process.env["SERVO_OHOS_SIGNING_CONFIG"];
|
||||
if (signingConfigsPath) {
|
||||
if (!fs.existsSync(signingConfigsPath)) {
|
||||
console.error("File referenced by SERVO_OHOS_SIGNING_CONFIG does not exist!");
|
||||
return;
|
||||
}
|
||||
const basePath = path.dirname(signingConfigsPath);
|
||||
const signingConfigs = JSON.parse(fs.readFileSync(signingConfigsPath));
|
||||
for (const config of signingConfigs) {
|
||||
config.material.certpath = path.resolve(basePath, config.material.certpath);
|
||||
config.material.profile = path.resolve(basePath, config.material.profile);
|
||||
config.material.storeFile = path.resolve(basePath, config.material.storeFile);
|
||||
}
|
||||
buildProfileOpt['app']['signingConfigs'] = signingConfigs;
|
||||
} else {
|
||||
console.log('Signing config not found in enviroment. hvigor will fallback to build-profile.json5.')
|
||||
}
|
||||
// Set the obj object back to the context object to enable the build process and results.
|
||||
appContext.setBuildProfileOpt(buildProfileOpt);
|
||||
})
|
||||
|
||||
export default {
|
||||
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
20
support/openharmony/oh-package-lock.json5
Normal file
20
support/openharmony/oh-package-lock.json5
Normal file
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@ohos/hypium@1.0.6": "@ohos/hypium@1.0.6"
|
||||
},
|
||||
"packages": {
|
||||
"@ohos/hypium@1.0.6": {
|
||||
"name": "@ohos/hypium",
|
||||
"version": "1.0.6",
|
||||
"integrity": "sha512-IgF26ui+ZL2/5ITpAoHqtNbpdDOyoXTjK8TEyncETNyH3gzklKD9+ZPdsxEvNVRbigiptmisfugNBNFM3OdpeQ==",
|
||||
"resolved": "https://cmc.centralrepo.rnd.huawei.com/artifactory/api/npm/product_npm/@ohos/hypium/-/@ohos/hypium-1.0.6.tgz",
|
||||
"shasum": "c2042745b131325ccf3d2b7eb7f77306758a838b",
|
||||
"registryType": "npm"
|
||||
}
|
||||
}
|
||||
}
|
13
support/openharmony/oh-package.json5
Normal file
13
support/openharmony/oh-package.json5
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.6"
|
||||
},
|
||||
"author": "",
|
||||
"name": "servoshell",
|
||||
"description": "Servo browser shell",
|
||||
"main": "",
|
||||
"version": "1.0.0",
|
||||
"dependencies": {}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue