已合并
Fix Portal Login Enter Phone Num Auto Pull CAPTCHA Keyboard #5555
huyu创建于 13 天前
Fix Portal Login Enter Phone Num Auto Pull CAPTCHA Keyboard #5555
已合并
共 2 个文件变更+30-1
| @@ -238,6 +238,20 @@ export function modifyUserAgent(originalUA: string, appendInfo: string): string | |||
| 238 | 238 | ||
| 239 | export const modifyCode = `Object.defineProperty(navigator, 'platform', { get: () => 'Linux aarch64' });`; | 239 | export const modifyCode = `Object.defineProperty(navigator, 'platform', { get: () => 'Linux aarch64' });`; |
| 240 | 240 | ||
| 241 | +export const preventEnterKeyScript = ` | ||
| 242 | +(function() { | ||
| 243 | + function handleEnter(e) { | ||
| 244 | + if (e.keyCode === 13 || e.key === 'Enter' || e.code === 'Enter') { | ||
| 245 | + e.preventDefault(); | ||
| 246 | + e.stopPropagation(); | ||
| 247 | + e.target.blur(); | ||
| 248 | + return false; | ||
| 249 | + } | ||
| 250 | + } | ||
| 251 | + document.addEventListener('keydown', handleEnter, true); | ||
| 252 | +})(); | ||
| 253 | +`; | ||
| 254 | + | ||
| 241 | export function loadUAWhiteList(context: common.Context): void { | 255 | export function loadUAWhiteList(context: common.Context): void { |
| 242 | try { | 256 | try { |
| 243 | const rawContent: Uint8Array = context.resourceManager.getRawFileContentSync('config.json'); | 257 | const rawContent: Uint8Array = context.resourceManager.getRawFileContentSync('config.json'); |
| @@ -22,10 +22,11 @@ import { SymbolGlyphModifier, window, CustomContentDialog } from '@kit.ArkUI'; | |||
| 22 | import { wifiManager } from '@kit.ConnectivityKit'; | 22 | import { wifiManager } from '@kit.ConnectivityKit'; |
| 23 | import { connection } from '@kit.NetworkKit'; | 23 | import { connection } from '@kit.NetworkKit'; |
| 24 | import { call } from '@kit.TelephonyKit'; | 24 | import { call } from '@kit.TelephonyKit'; |
| 25 | +import { inputMethodEngine } from '@kit.IMEKit'; | ||
| 25 | import { | 26 | import { |
| 26 | getUrl, bindToNetById, extractDomain, handleNetworkChange, exitApp, shouldShowBrowseItem, UserAgentSet, | 27 | getUrl, bindToNetById, extractDomain, handleNetworkChange, exitApp, shouldShowBrowseItem, UserAgentSet, |
| 27 | validateURL, getIsInOOBE, getHmosUAComplexRegex, StringNumberPair, getRetryList, getDefaultUrl, modifyCode, | 28 | validateURL, getIsInOOBE, getHmosUAComplexRegex, StringNumberPair, getRetryList, getDefaultUrl, modifyCode, |
| 28 | - convertToPermissions, reqPermissionsFromUser, modifyUserAgent, UserAgentCompatibleInfo | 29 | + convertToPermissions, reqPermissionsFromUser, modifyUserAgent, UserAgentCompatibleInfo, preventEnterKeyScript |
| 29 | } from '../common/utils'; | 30 | } from '../common/utils'; |
| 30 | import { | 31 | import { |
| 31 | updateFinalUrl, updateOnHttpErrorReceive, updateOnErrorReceive, updateOnSslErrorEvent, updateAboutToDisappear, | 32 | updateFinalUrl, updateOnHttpErrorReceive, updateOnErrorReceive, updateOnSslErrorEvent, updateAboutToDisappear, |
| @@ -40,6 +41,13 @@ const MAX_PROMPT_INPUT_LENGTH = 1000; | |||
| 40 | const MAX_SSL_HANDLERS = 50; | 41 | const MAX_SSL_HANDLERS = 50; |
| 41 | const MAX_RENDER_EXIT_RETRY = 3; | 42 | const MAX_RENDER_EXIT_RETRY = 3; |
| 42 | const RENDER_EXIT_RELOAD_DELAY = 200; | 43 | const RENDER_EXIT_RELOAD_DELAY = 200; |
| 44 | +const WEARABLE_KEYBOARD_OPTIONS: WebKeyboardOptions = { | ||
| 45 | + useSystemKeyboard: true, | ||
| 46 | + enterKeyType: inputMethodEngine.ENTER_KEY_TYPE_DONE, | ||
| 47 | +}; | ||
| 48 | +const DEFAULT_KEYBOARD_OPTIONS: WebKeyboardOptions = { | ||
| 49 | + useSystemKeyboard: true, | ||
| 50 | +}; | ||
| 43 | 51 | ||
| 44 | enum DeviceType { | 52 | enum DeviceType { |
| 45 | PHONE = 'Phone', | 53 | PHONE = 'Phone', |
| @@ -415,6 +423,12 @@ struct Index { | |||
| 415 | 423 | ||
| 416 | Web({ src: '', controller: this.webviewController }) | 424 | Web({ src: '', controller: this.webviewController }) |
| 417 | .javaScriptAccess(true) | 425 | .javaScriptAccess(true) |
| 426 | + .onInterceptKeyboardAttach((_KeyboardCallbackInfo) => { | ||
| 427 | + if (deviceInfo.deviceType === 'wearable') { | ||
| 428 | + return WEARABLE_KEYBOARD_OPTIONS; | ||
| 429 | + } | ||
| 430 | + return DEFAULT_KEYBOARD_OPTIONS; | ||
| 431 | + }) | ||
| 418 | .fileAccess(false) | 432 | .fileAccess(false) |
| 419 | .geolocationAccess(false) | 433 | .geolocationAccess(false) |
| 420 | .domStorageAccess(true) | 434 | .domStorageAccess(true) |
| @@ -519,6 +533,7 @@ struct Index { | |||
| 519 | } | 533 | } |
| 520 | }) | 534 | }) |
| 521 | .javaScriptOnDocumentStart([{ script: modifyCode, scriptRules: ["*"] }]) | 535 | .javaScriptOnDocumentStart([{ script: modifyCode, scriptRules: ["*"] }]) |
| 536 | + .javaScriptOnDocumentEnd(this.isWearable ? [{ script: preventEnterKeyScript, scriptRules: ["*"] }] : []) | ||
| 522 | .onPageBegin(() => { | 537 | .onPageBegin(() => { |
| 523 | updateFinalUrl(this.webUrl); | 538 | updateFinalUrl(this.webUrl); |
| 524 | this.loadProgress = 0; | 539 | this.loadProgress = 0; |