-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdweb-keyboard-overlay.ts
More file actions
48 lines (40 loc) · 1.32 KB
/
dweb-keyboard-overlay.ts
File metadata and controls
48 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { isDwebEnvironment } from './crypto/secure-storage'
export interface DwebVirtualKeyboardPlugin {
setOverlay(overlay: boolean): Promise<unknown>
}
export interface DwebPluginsModule {
virtualKeyboardPlugin?: DwebVirtualKeyboardPlugin
}
export interface ApplyDwebKeyboardOverlayOptions {
isDweb?: () => boolean
loadPlugins?: () => Promise<DwebPluginsModule>
}
async function defaultLoadPlugins(): Promise<DwebPluginsModule> {
const module = await import('@plaoc/plugins')
return module as DwebPluginsModule
}
/**
* 在 DWEB 环境配置键盘 overlay 行为。
* 当前策略:显式关闭 overlay,避免部分环境下的输入异常。
*/
export async function applyDwebKeyboardOverlay(
options: ApplyDwebKeyboardOverlayOptions = {},
): Promise<boolean> {
const isDweb = options.isDweb ?? isDwebEnvironment
const loadPlugins = options.loadPlugins ?? defaultLoadPlugins
if (!isDweb()) {
return false
}
try {
const plugins = await loadPlugins()
const virtualKeyboardPlugin = plugins.virtualKeyboardPlugin
if (!virtualKeyboardPlugin || typeof virtualKeyboardPlugin.setOverlay !== 'function') {
return false
}
await virtualKeyboardPlugin.setOverlay(false)
return true
} catch (error) {
console.warn('[dweb-keyboard-overlay] apply failed', error)
return false
}
}