Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: wxwork #149

Open
wants to merge 2 commits into
base: 4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "callapp-lib",
"version": "3.5.3",
"version": "3.5.4",
"description": "call native webview from webpage",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
Expand Down
15 changes: 13 additions & 2 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,20 @@ export const getWeChatVersion = (): string => {

export const isAndroid = /android/i.test(ua);

export const isIos = /iphone|ipad|ipod/i.test(ua);
let platform: string | undefined;
if ('userAgentData' in navigator) {
platform = navigator.userAgentData?.platform;
} else {
platform = navigator.platform;
}
const maxTouchPoints = navigator.maxTouchPoints || 0;

export const isWechat = /micromessenger\/([\d.]+)/i.test(ua);
export const isIOS =
/iphone|ipad|ipod/i.test(ua) || (platform === 'MacIntel' && maxTouchPoints > 1);

export const isWxwork = /wxwork\/([\d.]+)/i.test(ua);

export const isWechat = !isWxwork && /micromessenger\/([\d.]+)/i.test(ua);

export const isWeibo = /(weibo).*weibo__([\d.]+)/i.test(ua);

Expand Down
2 changes: 1 addition & 1 deletion src/evoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export function evokeByIFrame(uri: string): void {
if (!iframe) {
iframe = document.createElement('iframe');
iframe.style.cssText = 'display:none;border:0;width:0;height:0;';
document.body.appendChild(iframe);
document.body.append(iframe);
}

iframe.src = uri;
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CallApp {
logFunc('pending');
}
const isSupportWeibo = !!this.options.isSupportWeibo;
if (Browser.isIos) {
if (Browser.isIOS) {
// ios qq 禁止了 universalLink 唤起app,安卓不受影响 - 18年12月23日
// ios qq 浏览器禁止了 universalLink - 19年5月1日
// ios 微信自 7.0.5 版本放开了 Universal Link 的限制
Expand Down Expand Up @@ -111,7 +111,12 @@ class CallApp {
evokeByLocation(schemeURL);
checkOpenFall = this.fallToFbUrl;
}
} else if (Browser.isWechat || Browser.isBaidu || (Browser.isWeibo && !isSupportWeibo) || Browser.isQzone) {
} else if (
Browser.isWechat ||
Browser.isBaidu ||
(Browser.isWeibo && !isSupportWeibo) ||
Browser.isQzone
) {
evokeByLocation(this.options.fallback);
} else {
evokeByIFrame(schemeURL);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface CallappOptions {
};
appstore: string;
yingyongbao?: string;
isSupportWeibo?:boolean;
isSupportWeibo?: boolean;
fallback: string;
timeout?: number;
logFunc?: (status: 'pending' | 'failure') => void;
Expand Down
9 changes: 9 additions & 0 deletions types/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ interface Document {
webkitHidden?: boolean;
msHidden?: boolean;
}
interface NavigatorUAData {
brands: Array<{ brand: string; version: string }>;
mobile: boolean;
platform: string;
}

interface Navigator {
userAgentData?: NavigatorUAData;
}