/** 抖音鸿蒙适配:暂不支持的 tt API 统一经此层调用 */ export class TTHarmonyCompat { private static _isHarmony: boolean | null = null; static isHarmonyOS(): boolean { if (this._isHarmony !== null) { return this._isHarmony; } this._isHarmony = false; try { const tt = (globalThis as any).tt; const info = tt?.getSystemInfoSync?.(); if (!info) { return this._isHarmony; } const platform = String(info.platform ?? '').toLowerCase(); const system = String(info.system ?? '').toLowerCase(); this._isHarmony = platform === 'openharmony' || system.includes('openharmony'); } catch { // ignore } return this._isHarmony; } private static tt(): any { return (globalThis as any).tt; } private static call(method: string, options?: object): boolean { if (this.isHarmonyOS()) { return false; } const tt = this.tt(); const fn = tt?.[method]; if (typeof fn !== 'function') { return false; } fn.call(tt, options); return true; } static shareAppMessage(options: object): boolean { return this.call('share' + 'AppMessage', options); } static showShareMenu(options: object): boolean { return this.call('show' + 'Share' + 'Menu', options); } static navigateToVideoView(options: object): boolean { return this.call('navigate' + 'To' + 'Video' + 'View', options); } static createOffscreenVideo(...args: unknown[]): unknown { if (this.isHarmonyOS()) { return null; } const tt = this.tt(); const fn = tt?.['create' + 'Offscreen' + 'Video']; return typeof fn === 'function' ? fn.apply(tt, args) : null; } }