diff --git a/package/CHANGELOG.md b/package/CHANGELOG.md index 37efda6..b5d33af 100644 --- a/package/CHANGELOG.md +++ b/package/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.2.2 +- Fix: allow enable devtools + +--- # 0.2.1 - Allow load page with html string. - Allow load url with custom headers. diff --git a/package/oh-package.json5 b/package/oh-package.json5 index d3225ea..3951033 100644 --- a/package/oh-package.json5 +++ b/package/oh-package.json5 @@ -4,7 +4,7 @@ "name": "@ohos-rs/ability", "description": "Adaptor for OpenHarmony/HarmonyNext Application with Rust", "main": "index.ets", - "version": "0.2.1", + "version": "0.2.2", "repository": "https://github.com/harmony-contrib/openharmony-ability.git", "dependencies": {}, "keywords": [ diff --git a/rust_ability/ability_rust/src/main/ets/webview/DefaultWebview.ets b/rust_ability/ability_rust/src/main/ets/webview/DefaultWebview.ets index f789512..1e7fe51 100644 --- a/rust_ability/ability_rust/src/main/ets/webview/DefaultWebview.ets +++ b/rust_ability/ability_rust/src/main/ets/webview/DefaultWebview.ets @@ -185,6 +185,9 @@ export class RustWebviewNodeController extends NodeController { this.rootNode = new FrameNode(this.uiContext!) } + // Enabled devtools + data?.devtools && web_webview.WebviewController.setWebDebuggingAccess(true); + const node: BuilderNode = new BuilderNode(this.uiContext!); node.build(webViewWrap, data); this.webviewList.set(data.webTag, node); diff --git a/rust_example/webview_example/scripts/devtools.sh b/rust_example/webview_example/scripts/devtools.sh new file mode 100644 index 0000000..d85d510 --- /dev/null +++ b/rust_example/webview_example/scripts/devtools.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Get current fport rule list +CURRENT_FPORT_LIST=$(hdc fport ls) + +# Delete the existing fport rule one by one +while IFS= read -r line; do + # Extract the taskline + IFS=' ' read -ra parts <<< "$line" + taskline="${parts[1]} ${parts[2]}" + + # Delete the corresponding fport rule + echo "Removing forward rule for $taskline" + hdc fport rm $taskline + result=$? + + if [ $result -eq 0 ]; then + echo "Remove forward rule success, taskline:$taskline" + else + echo "Failed to remove forward rule, taskline:$taskline" + fi + +done <<< "$CURRENT_FPORT_LIST" + +# Initial port number +INITIAL_PORT=9222 + +# Get the current port number, use initial port number if not set previously +CURRENT_PORT=${PORT:-$INITIAL_PORT} + +# Get the list of all PIDs that match the condition +PID_LIST=$(hdc shell cat /proc/net/unix | grep webview_devtools_remote_ | awk -F '_' '{print $NF}') + +if [ -z "$PID_LIST" ]; then + echo "Failed to retrieve PID from the device" + exit 1 +fi + +# Increment the port number +PORT=$CURRENT_PORT + +# Forward ports for each application one by one +for PID in $PID_LIST; do + # Increment the port number + PORT=$((PORT + 1)) + + # Execute the hdc fport command + hdc fport tcp:$PORT localabstract:webview_devtools_remote_$PID + + # Check if the command executed successfully + if [ $? -ne 0 ]; then + echo "Failed to execute hdc fport command" + exit 1 + fi +done + +# List all forwarded ports +hdc fport ls \ No newline at end of file diff --git a/webview_example/entry/src/main/ets/entryability/EntryAbility.ets b/webview_example/entry/src/main/ets/entryability/EntryAbility.ets index b07022e..6b5ac5c 100644 --- a/webview_example/entry/src/main/ets/entryability/EntryAbility.ets +++ b/webview_example/entry/src/main/ets/entryability/EntryAbility.ets @@ -4,7 +4,7 @@ import { AbilityConstant } from '@kit.AbilityKit'; import window from '@ohos.window'; export default class EntryAbility extends RustAbility { - public moduleName: string = "custom_protocol" + public moduleName: string = "webview_example" public defaultPage: boolean = false; public mode: 'xcomponent' | 'webview' = 'webview'