You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.9 KiB
63 lines
1.9 KiB
|
3 weeks ago
|
/** 抖音鸿蒙适配:暂不支持的 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;
|
||
|
|
}
|
||
|
|
}
|