review: M3+M4 成果审查后的质量加固
八角度审查 15 Provider+微信/七牛+双容器+导航。桥核心/契约骨架基本无误;修确凿问题:
正确性/健壮性
- ShakeProvider:stop()/onDestroy 取消未决 shakeEnd 计时并复位 pending(修停止后仍触发出站、重启后首摇被吞、计时器泄漏)
- VibrateProvider:startRepeat 先 stopRepeat(修重复 repeatvibrator('1') 叠加出无法取消的孤儿计时链)
- PhotoProvider:JSON.parse 后 Array.isArray 守卫(修 H5 传非数组致 .map 抛错、出站永不下发使 H5 挂死);去不可达 .catch
- GenericWebContainer:getWebdata 直调改用 JSON.stringify 生成 JS 字符串实参(修 data 含换行/行分隔符断行致注入语法错误)
- LocationProvider:单次请求前先停连续监听(修连续后切单次仍持续推送);去 push() 中 !continuousOn→stopContinuous 死代码
加固/清理
- BridgeGameContainer:抽 firstReadyPush() 幂等助手(appservice/setPostUrl/pendingWebdata);保持 100% 触发时序
(注明为何用 100% 而非更早 onPageEnd:确保 H5 已注册 handler);aboutToDisappear 置空 hostCtx/config/resource
研判驳回(与原 Android 一致/契约默认/自愈):getphonestate CallState 值映射、通用容器 orientation 默认横屏、setMuted prepared 自愈、exitDialog backgameData() 无参通知。
延期(随微信集成):WeChatApi 单例陈旧回调/instanceof(容器重建后回调打旧 bridge;微信运行期本就待开放平台注册)。
记录待重构:AbstractProvider 基类 + parseJson 助手(去 15 Provider 重复 bridge/ctx/解析样板)、AVPlayer 复用、openBrowser/orientation 抽公共。
devecocli build 通过;单测通过;模拟器复测桥往返/appservice/setPostUrl 无回归。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,8 @@ export class LocationProvider implements CapabilityProvider {
|
||||
if (continuous) {
|
||||
this.startContinuous();
|
||||
} else {
|
||||
// 单次请求前,若已有连续监听在跑则先停,避免单次后仍持续推送(H5 预期一次)
|
||||
this.stopContinuous();
|
||||
this.requestSingle();
|
||||
}
|
||||
}
|
||||
@@ -163,9 +165,7 @@ export class LocationProvider implements CapabilityProvider {
|
||||
}
|
||||
|
||||
private push(info: MaplocationInfo): void {
|
||||
// 单次定位用 getCurrentLocation(一次性,无监听可停);连续定位由 stopshake 等价的 stopContinuous 管理。
|
||||
this.bridge?.callHandler(OutboundHandlers.GetLocationInfo, JSON.stringify(info));
|
||||
if (!this.continuousOn) {
|
||||
this.stopContinuous();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,19 +31,25 @@ export class PhotoProvider implements CapabilityProvider {
|
||||
if (ctx === undefined) {
|
||||
return;
|
||||
}
|
||||
let list: SavephotoURLBean[];
|
||||
let parsed: Object;
|
||||
try {
|
||||
list = JSON.parse(data) as SavephotoURLBean[];
|
||||
parsed = JSON.parse(data) as Object;
|
||||
} catch (e) {
|
||||
this.log.w(`getphoto bad json: ${(e as Error).message}`);
|
||||
return;
|
||||
}
|
||||
// H5 可能传非数组 → 守卫,避免 .map 抛错致出站永不下发(H5 等待挂死)
|
||||
if (!Array.isArray(parsed)) {
|
||||
this.log.w('getphoto data is not an array');
|
||||
this.bridge?.callHandler(OutboundHandlers.GetPhoto, '[]');
|
||||
return;
|
||||
}
|
||||
const list: SavephotoURLBean[] = parsed as SavephotoURLBean[];
|
||||
const dir: string = `${ResourceManager.resourceRoot(ctx)}/photos`;
|
||||
// downloadOne 自身吞错并回空 photourl(不 reject),故 Promise.all 必定 resolve
|
||||
const tasks: Promise<SavephotoURLBean>[] = list.map((item: SavephotoURLBean) => this.downloadOne(item, dir));
|
||||
Promise.all(tasks).then((results: SavephotoURLBean[]) => {
|
||||
this.bridge?.callHandler(OutboundHandlers.GetPhoto, JSON.stringify(results));
|
||||
}).catch((e: Error) => {
|
||||
this.log.w(`getphoto failed: ${e.message}`);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ export class ShakeProvider implements CapabilityProvider {
|
||||
private listening: boolean = false;
|
||||
private feedbackOn: boolean = false;
|
||||
private pending: boolean = false;
|
||||
private endTimer: number = -1;
|
||||
private readonly onAccel: (data: sensor.AccelerometerResponse) => void;
|
||||
|
||||
constructor() {
|
||||
@@ -72,6 +73,12 @@ export class ShakeProvider implements CapabilityProvider {
|
||||
this.log.w(`sensor.off failed: ${(e as BusinessError).message}`);
|
||||
}
|
||||
this.listening = false;
|
||||
// 取消未决的 shakeEnd 计时并复位节流,避免停止后仍触发出站 / 重启后首次摇动被吞
|
||||
if (this.endTimer !== -1) {
|
||||
clearTimeout(this.endTimer);
|
||||
this.endTimer = -1;
|
||||
}
|
||||
this.pending = false;
|
||||
}
|
||||
|
||||
private handleAccel(data: sensor.AccelerometerResponse): void {
|
||||
@@ -88,7 +95,8 @@ export class ShakeProvider implements CapabilityProvider {
|
||||
vibrator.startVibration({ type: 'time', duration: 200 }, { usage: 'notification' })
|
||||
.catch((e: BusinessError) => this.log.w(`shake vibrate failed: ${e.message}`));
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.endTimer = setTimeout(() => {
|
||||
this.endTimer = -1;
|
||||
this.bridge?.callHandler(OutboundHandlers.ShakeEnd, '');
|
||||
this.pending = false;
|
||||
}, SHAKE_END_DELAY);
|
||||
|
||||
@@ -53,6 +53,8 @@ export class VibrateProvider implements CapabilityProvider {
|
||||
}
|
||||
|
||||
private startRepeat(): void {
|
||||
// 先清旧链:避免重复 repeatvibrator('1') 叠加出无法取消的孤儿计时链
|
||||
this.stopRepeat();
|
||||
this.repeating = true;
|
||||
this.loop();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user