T-M3-15 RoomStubProvider/PayStubProvider:createRoom/exitRoom/getVideoinfo/DragViewvideoIsshow、
paybrowser/getGameplay 全 void 空实现+日志,绝不触发出站(§6.5 安全网)
T-M3-04 VibrateProvider:vibrator/repeatvibrator/canclevibrator(@ohos.vibrator,重复用递归 setTimeout)
T-M3-05 ClipboardProvider:gameCopytext/gamepastetext(@ohos.pasteboard,读取经 responseCallback 回执)
T-M3-01 AppSystemProvider:orientation(window.setPreferredOrientation 横/竖)、browser(隐式 want)、
finsh(terminateSelf)、openApplyDownloadpath(按包名启动失败回退浏览器)、notification(空)
组装根 buildCapabilities 装配上述 + 桩;module.json5 增 VIBRATE 权限
devecocli build 通过。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
48 lines
1.9 KiB
Plaintext
48 lines
1.9 KiB
Plaintext
/**
|
||
* 剪贴板能力(契约 §8.4,T-M3-05)。@kit.BasicServicesKit pasteboard。
|
||
* - gameCopytext:data=文本,写入系统剪贴板。
|
||
* - gamepastetext:读取剪贴板内容,经 responseCallback 返回(getData 异步,回调延后触发,对 H5 仍是同步回执语义)。
|
||
* 前台应用读取自身剪贴板无需声明权限;失败回空串(H5 不卡死)。
|
||
*/
|
||
import { pasteboard } from '@kit.BasicServicesKit';
|
||
import { BusinessError } from '@kit.BasicServicesKit';
|
||
import { BridgeController } from 'feature_bridge';
|
||
import { InboundHandlers } from 'contracts';
|
||
import { Logger } from 'common';
|
||
import { CapabilityContext, CapabilityProvider } from '../core/CapabilityProvider';
|
||
|
||
export class ClipboardProvider implements CapabilityProvider {
|
||
readonly name: string = 'clipboard';
|
||
private readonly log: Logger = Logger.tag('ClipboardProvider');
|
||
|
||
register(bridge: BridgeController, _ctx: CapabilityContext): void {
|
||
bridge.registerHandler(InboundHandlers.GameCopyText, (data: string, _cb: (resp: string) => void) => {
|
||
this.copy(data);
|
||
});
|
||
bridge.registerHandler(InboundHandlers.GamePasteText, (_d: string, cb: (resp: string) => void) => {
|
||
this.paste(cb);
|
||
});
|
||
}
|
||
|
||
private copy(text: string): void {
|
||
try {
|
||
const data: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, text);
|
||
pasteboard.getSystemPasteboard().setData(data)
|
||
.catch((e: BusinessError) => this.log.w(`setData failed: ${e.code} ${e.message}`));
|
||
} catch (e) {
|
||
this.log.w(`copy failed: ${(e as Error).message}`);
|
||
}
|
||
}
|
||
|
||
private paste(cb: (resp: string) => void): void {
|
||
pasteboard.getSystemPasteboard().getData()
|
||
.then((data: pasteboard.PasteData) => {
|
||
cb(data.getPrimaryText() ?? '');
|
||
})
|
||
.catch((e: BusinessError) => {
|
||
this.log.w(`getData failed: ${e.code} ${e.message}`);
|
||
cb('');
|
||
});
|
||
}
|
||
}
|