@@ -144,27 +144,28 @@ echo "==> Patching web_engine NativeMessagingAdapter for API compatibility ..."
144144
145145NATIVE_MSG_ADAPTER=" ${WEB_ENGINE_DIR} /src/main/ets/adapter/NativeMessagingAdapter.ets"
146146if [ -f " ${NATIVE_MSG_ADAPTER} " ]; then
147- # The Electron runtime may import APIs that don't exist in the target SDK.
148- # Strategy: comment out unsupported imports AND all lines that reference
149- # those symbols, to prevent both "no exported member" and "cannot find name" errors.
150- PATCHED=false
151- if grep -q ' dataShare' " ${NATIVE_MSG_ADAPTER} " 2> /dev/null; then
152- echo " Patching: commenting out 'dataShare' references (import + usages)"
153- # Comment out any line containing dataShare that isn't already commented
154- perl -i -pe ' s/^([^\/].*\bdataShare\b)/\/\/ PATCHED: $1/' " ${NATIVE_MSG_ADAPTER} "
155- PATCHED=true
156- fi
157- if grep -q ' webNativeMessagingExtensionManager' " ${NATIVE_MSG_ADAPTER} " 2> /dev/null; then
158- echo " Patching: commenting out 'webNativeMessagingExtensionManager' references (import + usages)"
159- # Comment out any line containing webNativeMessagingExtensionManager that isn't already commented
160- perl -i -pe ' s/^([^\/].*\bwebNativeMessagingExtensionManager\b)/\/\/ PATCHED: $1/' " ${NATIVE_MSG_ADAPTER} "
161- PATCHED=true
162- fi
163- if [ " ${PATCHED} " = true ]; then
164- echo " NativeMessagingAdapter patched (unsupported API references commented out)"
165- else
166- echo " NativeMessagingAdapter: no patches needed"
167- fi
147+ # The Electron runtime imports APIs (dataShare from @kit.ArkData,
148+ # webNativeMessagingExtensionManager from @kit.ArkWeb) that don't exist
149+ # in the target SDK. Replacing the entire file with a minimal stub is
150+ # the safest approach — line-by-line patching breaks code structure.
151+ echo " Replacing NativeMessagingAdapter.ets with minimal stub"
152+ cat > " ${NATIVE_MSG_ADAPTER} " << 'NMASTUB '
153+ // NativeMessagingAdapter.ets — Stubbed for API compatibility
154+ // Original file uses dataShare (@kit.ArkData) and webNativeMessagingExtensionManager
155+ // (@kit.ArkWeb) which are not available in the target SDK.
156+ export class NativeMessagingAdapter {
157+ static connectNative(name: string, callback: (err: string, data: string) => void): void {
158+ callback('', '')
159+ }
160+ static disconnectNative(connectionId: number, callback: (err: string) => void): void {
161+ callback('')
162+ }
163+ static getManifestConfig(name: string, callback: (err: string, config: string) => void): void {
164+ callback('', '')
165+ }
166+ }
167+ NMASTUB
168+ echo " NativeMessagingAdapter replaced with stub"
168169else
169170 echo " (NativeMessagingAdapter.ets not found, skipping)"
170171fi
@@ -175,10 +176,12 @@ echo "==> Patching web_engine AppWindowAdapter for API compatibility ..."
175176
176177APP_WINDOW_ADAPTER=" ${WEB_ENGINE_DIR} /src/main/ets/adapter/AppWindowAdapter.ets"
177178if [ -f " ${APP_WINDOW_ADAPTER} " ]; then
178- # shiftAppWindowTouchEvent may not exist in the target SDK
179+ # shiftAppWindowTouchEvent may not exist on window in the target SDK.
180+ # Use a cast to ESObject to bypass the type check.
179181 if grep -q ' shiftAppWindowTouchEvent' " ${APP_WINDOW_ADAPTER} " 2> /dev/null; then
180- echo " Patching: commenting out 'shiftAppWindowTouchEvent' references"
181- perl -i -pe ' s/^([^\/].*\bshiftAppWindowTouchEvent\b)/\/\/ PATCHED: $1/' " ${APP_WINDOW_ADAPTER} "
182+ echo " Patching: neutralizing 'shiftAppWindowTouchEvent' calls"
183+ # Replace window.shiftAppWindowTouchEvent with (window as ESObject).shiftAppWindowTouchEvent
184+ perl -i -pe ' s/window\.shiftAppWindowTouchEvent/(window as ESObject).shiftAppWindowTouchEvent/g' " ${APP_WINDOW_ADAPTER} "
182185 echo " AppWindowAdapter patched"
183186 else
184187 echo " AppWindowAdapter: no patches needed"
0 commit comments