Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebviewNodeData[]> = new BuilderNode(this.uiContext!);
node.build(webViewWrap, data);
this.webviewList.set(data.webTag, node);
Expand Down
58 changes: 58 additions & 0 deletions rust_example/webview_example/scripts/devtools.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down