提交 0397ac47 编写于 作者: fxy060608's avatar fxy060608

feat: uni-push

上级 23053d7f
......@@ -90,7 +90,7 @@ type ApiCallbacks = {
[key in CALLBACK_TYPES]?: Function
}
function getApiCallbacks(args: Record<string, any>) {
export function getApiCallbacks(args: Record<string, any>) {
const apiCallbacks: ApiCallbacks = {}
for (const name in args) {
const fn = args[name]
......@@ -133,11 +133,11 @@ export function createAsyncApiCallback(
isFunction(beforeAll) && beforeAll(res)
if (res.errMsg === name + ':ok') {
isFunction(beforeSuccess) && beforeSuccess(res, args)
hasSuccess && success!(res)
hasSuccess && success(res)
} else {
hasFail && fail!(res)
hasFail && fail(res)
}
hasComplete && complete!(res)
hasComplete && complete(res)
})
return callbackId
}
......@@ -21,6 +21,8 @@ export * from './service/keyboard/getSelectedTextRange'
export * from './service/lifecycle/app'
export * from './service/plugin/push'
// protocols
export * from './protocols/base/canIUse'
......
import { isFunction, isPlainObject } from '@vue/shared'
import { getApiCallbacks } from '../../helpers/api/callback'
interface OnPushCidCallback {
type: 'clientId'
cid: string
}
interface OnPushLineStateCallback {
type: 'lineState'
online: boolean
}
interface OnPushMsgCallback {
type: 'pushMsg'
message: unknown
}
let cid: string = ''
/**
* @private
* @param args
*/
export function invokePushCallback(
args: OnPushCidCallback | OnPushLineStateCallback | OnPushMsgCallback
) {
if (args.type === 'clientId') {
cid = args.cid
invokeGetPushCidCallbacks(cid)
} else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message })
})
}
}
interface GetPushCidOptions {
success?: OnPushMessageSuccess
}
const getPushCidCallbacks: ((cid?: string) => void)[] = []
function invokeGetPushCidCallbacks(cid?: string) {
getPushCidCallbacks.forEach((callback) => {
callback(cid)
})
getPushCidCallbacks.length = 0
}
export function getPushCid(args: GetPushCidOptions) {
if (!isPlainObject(args)) {
args = {}
}
const { success, fail, complete } = getApiCallbacks(args)
const hasSuccess = isFunction(success)
const hasFail = isFunction(fail)
const hasComplete = isFunction(complete)
getPushCidCallbacks.push((cid?: string) => {
let res: Record<string, unknown>
if (cid) {
res = { errMsg: 'getPushCid:ok', cid }
hasSuccess && success(res)
} else {
res = { errMsg: 'getPushCid:fail' }
hasFail && fail(res)
}
hasComplete && complete(res)
})
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid))
}
}
interface OnPushMessageSuccess {
data: unknown
}
type OnPushMessageCallback = (result: OnPushMessageSuccess) => void
const onPushMessageCallbacks: OnPushMessageCallback[] = []
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
export const onPushMessage: (fn: OnPushMessageCallback) => void = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn)
}
}
export const offPushMessage: (fn?: OnPushMessageCallback) => void = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0
} else {
const index = onPushMessageCallbacks.indexOf(fn)
if (index > -1) {
onPushMessageCallbacks.splice(index, 1)
}
}
}
......@@ -11521,6 +11521,72 @@ var serviceContext = (function (vue) {
return getLaunchOptions();
});
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const API_GET_BACKGROUND_AUDIO_MANAGER = 'getBackgroundAudioManager';
const API_MAKE_PHONE_CALL = 'makePhoneCall';
......@@ -19889,6 +19955,10 @@ var serviceContext = (function (vue) {
setPageMeta: setPageMeta,
getEnterOptionsSync: getEnterOptionsSync,
getLaunchOptionsSync: getLaunchOptionsSync,
getPushCid: getPushCid,
onPushMessage: onPushMessage,
offPushMessage: offPushMessage,
invokePushCallback: invokePushCallback,
setStorageSync: setStorageSync,
setStorage: setStorage,
getStorageSync: getStorageSync,
......
......@@ -115,4 +115,9 @@ export {
setPageMeta,
getEnterOptionsSync,
getLaunchOptionsSync,
getPushCid,
onPushMessage,
offPushMessage,
// 内部使用
invokePushCallback,
} from '@dcloudio/uni-api'
......@@ -4,6 +4,8 @@ var index = [
/* eslint-disable no-restricted-globals */
...require('@dcloudio/uni-cloud/lib/uni.plugin.js').default,
/* eslint-disable no-restricted-globals */
...require('@dcloudio/uni-push/lib/uni.plugin.js'),
/* eslint-disable no-restricted-globals */
...require('@dcloudio/uni-stat/lib/uni.plugin.js'),
];
......
......@@ -27,6 +27,7 @@
"@dcloudio/uni-cloud": "3.0.0-alpha-3030820220114006",
"@dcloudio/uni-components": "3.0.0-alpha-3030820220114006",
"@dcloudio/uni-i18n": "3.0.0-alpha-3030820220114006",
"@dcloudio/uni-push": "3.0.0-alpha-3030820220114006",
"@dcloudio/uni-shared": "3.0.0-alpha-3030820220114006",
"@dcloudio/uni-stat": "3.0.0-alpha-3030820220114006",
"@vue/shared": "3.2.30"
......
......@@ -2,5 +2,7 @@ export default [
/* eslint-disable no-restricted-globals */
...require('@dcloudio/uni-cloud/lib/uni.plugin.js').default,
/* eslint-disable no-restricted-globals */
...require('@dcloudio/uni-push/lib/uni.plugin.js'),
/* eslint-disable no-restricted-globals */
...require('@dcloudio/uni-stat/lib/uni.plugin.js'),
]
......@@ -66,6 +66,23 @@ export function getUniStatistics(inputDir: string, platform: UniApp.PLATFORM) {
)
}
export function getUniPush(inputDir: string, platform: UniApp.PLATFORM) {
const manifest = parseManifestJsonOnce(inputDir)
return extend(
{},
manifest.unipush,
manifest[platform] && manifest[platform].unipush
)
}
export function isUniPushOffline(inputDir: string) {
const manifest = parseManifestJsonOnce(inputDir)
return (
manifest?.['app-plus']?.distribute?.sdkConfigs?.push?.unipush?.enable ===
true
)
}
export function getRouterOptions(manifestJson: Record<string, any>): {
mode?: 'history' | 'hash'
base?: string
......
import type { ResolvedConfig } from 'vite'
import type { ConfigEnv, ResolvedConfig, UserConfig } from 'vite'
export function withSourcemap(config: ResolvedConfig) {
if (config.command === 'serve') {
......@@ -6,3 +6,16 @@ export function withSourcemap(config: ResolvedConfig) {
}
return !!config.build.sourcemap
}
export function isSsr(
command: ConfigEnv['command'],
config: UserConfig | ResolvedConfig
) {
if (command === 'serve') {
return !!(config.server && config.server.middlewareMode)
}
if (command === 'build') {
return !!(config.build && config.build.ssr)
}
return false
}
......@@ -41,6 +41,7 @@
"getLocation",
"getNetworkType",
"getProvider",
"getPushCid",
"getRealPath",
"getRecorderManager",
"getRightWindowStyle",
......@@ -66,6 +67,7 @@
"hideToast",
"hideTopWindow",
"interceptors",
"invokePushCallback",
"loadFontFace",
"login",
"makePhoneCall",
......@@ -74,6 +76,7 @@
"offAccelerometerChange",
"offCompassChange",
"offNetworkStatusChange",
"offPushMessage",
"offWindowResize",
"onAccelerometerChange",
"onAppLaunch",
......@@ -82,6 +85,7 @@
"onLocaleChange",
"onMemoryWarning",
"onNetworkStatusChange",
"onPushMessage",
"onSocketClose",
"onSocketError",
"onSocketMessage",
......
......@@ -9,8 +9,9 @@ import {
parseManifestJsonOnce,
initPostcssPlugin,
parseRpx2UnitOnce,
isSsr,
} from '@dcloudio/uni-cli-shared'
import { createDefine, isSsr } from '../utils'
import { createDefine } from '../utils'
import { esbuildPrePlugin } from './esbuild/esbuildPrePlugin'
import { external } from './configureServer/ssr'
import { extend, hasOwn } from '@vue/shared'
......
import path from 'path'
import { defineUniMainJsPlugin, normalizePath } from '@dcloudio/uni-cli-shared'
import { isSSR, isSsr, isSsrManifest } from '../utils'
import {
defineUniMainJsPlugin,
isSsr,
normalizePath,
} from '@dcloudio/uni-cli-shared'
import { isSSR, isSsrManifest } from '../utils'
export function uniMainJsPlugin() {
return defineUniMainJsPlugin((opts) => {
......
......@@ -3,10 +3,9 @@ import type { Plugin, ResolvedConfig } from 'vite'
import { OutputChunk } from 'rollup'
import { parseRpx2UnitOnce } from '@dcloudio/uni-cli-shared'
import { isSsr, parseRpx2UnitOnce } from '@dcloudio/uni-cli-shared'
import {
isSsr,
initSsrDefine,
rewriteSsrVue,
rewriteSsrResolve,
......
......@@ -3,8 +3,9 @@ import {
parsePagesJsonOnce,
parseManifestJsonOnce,
initFeatures,
isSsr,
} from '@dcloudio/uni-cli-shared'
import { isSsr, isSsrManifest } from './ssr'
import { isSsrManifest } from './ssr'
export function createDefine(
command: ConfigEnv['command'],
......
......@@ -23,19 +23,6 @@ import { transformPageHead } from '../plugin/transforms/transformPageHead'
export const isSSR = (opt: { ssr?: boolean } | boolean | undefined) =>
opt === undefined ? false : typeof opt === 'boolean' ? opt : opt?.ssr === true
export function isSsr(
command: ConfigEnv['command'],
config: UserConfig | ResolvedConfig
) {
if (command === 'serve') {
return !!(config.server && config.server.middlewareMode)
}
if (command === 'build') {
return !!(config.build && config.build.ssr)
}
return false
}
export function isSsrManifest(
command: ConfigEnv['command'],
config: UserConfig | ResolvedConfig
......
......@@ -1634,10 +1634,10 @@ function useResizeSensorReset(rootRef) {
};
}
const pixelRatio = 1;
function wrapper(canvas) {
canvas.width = canvas.offsetWidth * pixelRatio;
canvas.height = canvas.offsetHeight * pixelRatio;
canvas.getContext("2d").__hidpi__ = true;
function wrapper(canvas, hidpi = true) {
canvas.width = canvas.offsetWidth * (hidpi ? pixelRatio : 1);
canvas.height = canvas.offsetHeight * (hidpi ? pixelRatio : 1);
canvas.getContext("2d").__hidpi__ = hidpi;
}
const initHidpiOnce = /* @__PURE__ */ uniShared.once(() => {
return void 0;
......@@ -1678,6 +1678,10 @@ const props$t = {
disableScroll: {
type: [Boolean, String],
default: false
},
hidpi: {
type: Boolean,
default: true
}
};
var index$B = /* @__PURE__ */ defineBuiltInComponent({
......@@ -1714,7 +1718,7 @@ var index$B = /* @__PURE__ */ defineBuiltInComponent({
const {
_handleSubscribe,
_resize
} = useMethods(canvas, actionsWaiting);
} = useMethods(props2, canvas, actionsWaiting);
useSubscribe(_handleSubscribe, useContextInfo(props2.canvasId));
return () => {
const {
......@@ -1780,21 +1784,22 @@ function useListeners(props2, Listeners, trigger) {
_listeners
};
}
function useMethods(canvasRef, actionsWaiting) {
function useMethods(props2, canvasRef, actionsWaiting) {
let _actionsDefer = [];
let _images = {};
const _pixelRatio = vue.computed(() => props2.hidpi ? pixelRatio : 1);
function _resize(size) {
let canvas = canvasRef.value;
var hasChanged = !size || canvas.width !== Math.floor(size.width * pixelRatio) || canvas.height !== Math.floor(size.height * pixelRatio);
var hasChanged = !size || canvas.width !== Math.floor(size.width * _pixelRatio.value) || canvas.height !== Math.floor(size.height * _pixelRatio.value);
if (!hasChanged)
return;
if (canvas.width > 0 && canvas.height > 0) {
let context = canvas.getContext("2d");
let imageData = context.getImageData(0, 0, canvas.width, canvas.height);
wrapper(canvas);
wrapper(canvas, props2.hidpi);
context.putImageData(imageData, 0, 0);
} else {
wrapper(canvas);
wrapper(canvas, props2.hidpi);
}
}
function actionsChanged({
......@@ -2004,8 +2009,8 @@ function useMethods(canvasRef, actionsWaiting) {
height = height ? Math.min(height, maxHeight) : maxHeight;
if (!hidpi) {
if (!destWidth && !destHeight) {
destWidth = Math.round(width * pixelRatio);
destHeight = Math.round(height * pixelRatio);
destWidth = Math.round(width * _pixelRatio.value);
destHeight = Math.round(height * _pixelRatio.value);
} else if (!destWidth) {
destWidth = Math.round(width / height * destHeight);
} else if (!destHeight) {
......
......@@ -4537,6 +4537,63 @@ const API_GET_LAUNCH_OPTIONS_SYNC = "getLaunchOptionsSync";
const getLaunchOptionsSync = /* @__PURE__ */ defineSyncApi(API_GET_LAUNCH_OPTIONS_SYNC, () => {
return getLaunchOptions();
});
let cid = "";
function invokePushCallback(args) {
if (args.type === "clientId") {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
} else if (args.type === "pushMsg") {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid2) {
getPushCidCallbacks.forEach((callback) => {
callback(cid2);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid2) => {
let res;
if (cid2) {
res = { errMsg: "getPushCid:ok", cid: cid2 };
hasSuccess && success(res);
} else {
res = { errMsg: "getPushCid:fail" };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
} else {
const index2 = onPushMessageCallbacks.indexOf(fn);
if (index2 > -1) {
onPushMessageCallbacks.splice(index2, 1);
}
}
};
const API_CAN_I_USE = "canIUse";
const CanIUseProtocol = [
{
......@@ -6245,10 +6302,10 @@ const pixelRatio = /* @__PURE__ */ function() {
const backingStore = context.backingStorePixelRatio || context.webkitBackingStorePixelRatio || context.mozBackingStorePixelRatio || context.msBackingStorePixelRatio || context.oBackingStorePixelRatio || context.backingStorePixelRatio || 1;
return (window.devicePixelRatio || 1) / backingStore;
}();
function wrapper(canvas) {
canvas.width = canvas.offsetWidth * pixelRatio;
canvas.height = canvas.offsetHeight * pixelRatio;
canvas.getContext("2d").__hidpi__ = true;
function wrapper(canvas, hidpi = true) {
canvas.width = canvas.offsetWidth * (hidpi ? pixelRatio : 1);
canvas.height = canvas.offsetHeight * (hidpi ? pixelRatio : 1);
canvas.getContext("2d").__hidpi__ = hidpi;
}
let isHidpi = false;
function initHidpi() {
......@@ -6337,6 +6394,7 @@ function initHidpi() {
const args = Array.prototype.slice.call(arguments);
args[1] *= pixelRatio;
args[2] *= pixelRatio;
args[3] *= pixelRatio;
var font2 = this.font;
this.font = font2.replace(/(\d+\.?\d*)(px|em|rem|pt)/g, function(w, m, u) {
return m * pixelRatio + u;
......@@ -6353,6 +6411,7 @@ function initHidpi() {
var args = Array.prototype.slice.call(arguments);
args[1] *= pixelRatio;
args[2] *= pixelRatio;
args[3] *= pixelRatio;
var font2 = this.font;
this.font = font2.replace(/(\d+\.?\d*)(px|em|rem|pt)/g, function(w, m, u) {
return m * pixelRatio + u;
......@@ -6412,6 +6471,10 @@ const props$A = {
disableScroll: {
type: [Boolean, String],
default: false
},
hidpi: {
type: Boolean,
default: true
}
};
var index$w = /* @__PURE__ */ defineBuiltInComponent({
......@@ -6448,7 +6511,7 @@ var index$w = /* @__PURE__ */ defineBuiltInComponent({
const {
_handleSubscribe,
_resize
} = useMethods(canvas, actionsWaiting);
} = useMethods(props2, canvas, actionsWaiting);
useSubscribe(_handleSubscribe, useContextInfo(props2.canvasId), true);
onMounted(() => {
_resize();
......@@ -6517,21 +6580,22 @@ function useListeners(props2, Listeners, trigger) {
_listeners
};
}
function useMethods(canvasRef, actionsWaiting) {
function useMethods(props2, canvasRef, actionsWaiting) {
let _actionsDefer = [];
let _images = {};
const _pixelRatio = computed(() => props2.hidpi ? pixelRatio : 1);
function _resize(size) {
let canvas = canvasRef.value;
var hasChanged = !size || canvas.width !== Math.floor(size.width * pixelRatio) || canvas.height !== Math.floor(size.height * pixelRatio);
var hasChanged = !size || canvas.width !== Math.floor(size.width * _pixelRatio.value) || canvas.height !== Math.floor(size.height * _pixelRatio.value);
if (!hasChanged)
return;
if (canvas.width > 0 && canvas.height > 0) {
let context = canvas.getContext("2d");
let imageData = context.getImageData(0, 0, canvas.width, canvas.height);
wrapper(canvas);
wrapper(canvas, props2.hidpi);
context.putImageData(imageData, 0, 0);
} else {
wrapper(canvas);
wrapper(canvas, props2.hidpi);
}
}
function actionsChanged({
......@@ -6741,8 +6805,8 @@ function useMethods(canvasRef, actionsWaiting) {
height = height ? Math.min(height, maxHeight) : maxHeight;
if (!hidpi) {
if (!destWidth && !destHeight) {
destWidth = Math.round(width * pixelRatio);
destHeight = Math.round(height * pixelRatio);
destWidth = Math.round(width * _pixelRatio.value);
destHeight = Math.round(height * _pixelRatio.value);
} else if (!destWidth) {
destWidth = Math.round(width / height * destHeight);
} else if (!destHeight) {
......@@ -19829,6 +19893,10 @@ var api = {
setPageMeta,
getEnterOptionsSync,
getLaunchOptionsSync,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
cssVar,
cssEnv,
cssConstant,
......@@ -21990,4 +22058,4 @@ var index = /* @__PURE__ */ defineSystemComponent({
return openBlock(), createBlock("div", clazz, [loadingVNode]);
}
});
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
export { $emit, $off, $on, $once, index$8 as Ad, index$7 as AdContentPage, index$6 as AdDraw, index$1 as AsyncErrorComponent, index as AsyncLoadingComponent, index$y as Button, index$5 as Camera, index$w as Canvas, index$u as Checkbox, index$v as CheckboxGroup, index$a as CoverImage, index$b as CoverView, index$t as Editor, index$A as Form, index$s as Icon, index$r as Image, Input, index$z as Label, LayoutComponent, index$4 as LivePlayer, index$3 as LivePusher, Map$1 as Map, MovableArea, MovableView, index$q as Navigator, index$2 as PageComponent, index$9 as Picker, PickerView, PickerViewColumn, index$p as Progress, index$n as Radio, index$o as RadioGroup, ResizeSensor, index$m as RichText, ScrollView, index$l as Slider, Swiper, SwiperItem, index$k as Switch, index$j as Text, index$i as Textarea, UniServiceJSBridge$1 as UniServiceJSBridge, UniViewJSBridge$1 as UniViewJSBridge, index$e as Video, index$h as View, index$d as WebView, addInterceptor, addPhoneContact, arrayBufferToBase64, base64ToArrayBuffer, canIUse, canvasGetImageData, canvasPutImageData, canvasToTempFilePath, chooseFile, chooseImage, chooseLocation, chooseVideo, clearStorage, clearStorageSync, closePreviewImage, closeSocket, connectSocket, createAnimation$1 as createAnimation, createCameraContext, createCanvasContext, createInnerAudioContext, createIntersectionObserver, createLivePlayerContext, createMapContext, createMediaQueryObserver, createSelectorQuery, createVideoContext, cssBackdropFilter, cssConstant, cssEnv, cssVar, downloadFile, getApp$1 as getApp, getClipboardData, getCurrentPages$1 as getCurrentPages, getEnterOptionsSync, getFileInfo, getImageInfo, getLaunchOptionsSync, getLeftWindowStyle, getLocale, getLocation, getNetworkType, getProvider, getPushCid, getRealPath, getRecorderManager, getRightWindowStyle, getSavedFileInfo, getSavedFileList, getScreenBrightness, getSelectedTextRange$1 as getSelectedTextRange, getStorage, getStorageInfo, getStorageInfoSync, getStorageSync, getSystemInfo, getSystemInfoSync, getTopWindowStyle, getVideoInfo, hideKeyboard, hideLeftWindow, hideLoading, hideNavigationBarLoading, hideRightWindow, hideTabBar, hideTabBarRedDot, hideToast, hideTopWindow, interceptors, invokePushCallback, loadFontFace, login, makePhoneCall, navigateBack, navigateTo, offAccelerometerChange, offCompassChange, offNetworkStatusChange, offPushMessage, offWindowResize, onAccelerometerChange, onAppLaunch, onCompassChange, onGyroscopeChange, onLocaleChange, onMemoryWarning, onNetworkStatusChange, onPushMessage, onSocketClose, onSocketError, onSocketMessage, onSocketOpen, onTabBarMidButtonTap, onUserCaptureScreen, onWindowResize, openDocument, openLocation, pageScrollTo, index$f as plugin, preloadPage, previewImage, reLaunch, redirectTo, removeInterceptor, removeSavedFileInfo, removeStorage, removeStorageSync, removeTabBarBadge, request, saveFile, saveImageToPhotosAlbum, saveVideoToPhotosAlbum, scanCode, sendSocketMessage, setClipboardData, setKeepScreenOn, setLeftWindowStyle, setLocale, setNavigationBarColor, setNavigationBarTitle, setPageMeta, setRightWindowStyle, setScreenBrightness, setStorage, setStorageSync, setTabBarBadge, setTabBarItem, setTabBarStyle, setTopWindowStyle, setupApp, setupPage, setupWindow, showActionSheet, showLeftWindow, showLoading, showModal, showNavigationBarLoading, showRightWindow, showTabBar, showTabBarRedDot, showToast, showTopWindow, startAccelerometer, startCompass, startGyroscope, startPullDownRefresh, stopAccelerometer, stopCompass, stopGyroscope, stopPullDownRefresh, switchTab, uni$1 as uni, uploadFile, upx2px, useI18n, useTabBar, vibrateLong, vibrateShort };
......@@ -97,5 +97,10 @@ export {
setPageMeta,
getEnterOptionsSync,
getLaunchOptionsSync,
getPushCid,
onPushMessage,
offPushMessage,
// 内部使用
invokePushCallback,
} from '@dcloudio/uni-api'
//#endif
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -189,6 +189,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -772,6 +862,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -189,6 +189,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -772,6 +862,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
......@@ -12,6 +12,12 @@ import {
$once,
$emit,
} from '@dcloudio/uni-api/src/service/base/eventBus'
import {
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
} from '@dcloudio/uni-api/src/service/plugin/push'
import { promisify } from './promise'
import { initWrapper } from './wrapper'
......@@ -32,6 +38,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
}
export function initUni(api: Record<string, any>, protocols: MPProtocols) {
......
......@@ -21,8 +21,8 @@ export const setLocale: typeof uni.setLocale = (locale) => {
return false
}
type OnLocaleCHangeCallback = Parameters<typeof uni.onLocaleChange>[0]
const onLocaleChangeCallbacks: OnLocaleCHangeCallback[] = []
type OnLocaleChangeCallback = Parameters<typeof uni.onLocaleChange>[0]
const onLocaleChangeCallbacks: OnLocaleChangeCallback[] = []
export const onLocaleChange: typeof uni.onLocaleChange = (fn) => {
if (onLocaleChangeCallbacks.indexOf(fn) === -1) {
onLocaleChangeCallbacks.push(fn)
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -189,6 +189,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -772,6 +862,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -189,6 +189,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -772,6 +862,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -189,6 +189,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -772,6 +862,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -189,6 +189,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -772,6 +862,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -153,6 +153,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -548,6 +572,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -736,6 +826,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
[
{
"input": {
"src/plugin/index.ts": "lib/uni.plugin.js"
},
"output": {
"format": "cjs"
},
"external": ["debug", "@dcloudio/uni-cli-shared"]
},
{
"input": {
"src/index.ts": ["dist/uni-push.es.js"]
}
},
{
"input": {
"src/plus.ts": ["dist/uni-push.plus.es.js"]
}
}
]
此差异已折叠。
Promise.resolve().then(() => {
const info = plus.push.getClientInfo();
if (info.clientid) {
// @ts-expect-error
uni.invokePushCallback({
type: 'clientId',
cid: info.clientid,
});
}
plus.push.addEventListener('receive', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'pushMsg',
message: result,
});
});
});
declare namespace GtPush {
/**
* 设置调试模式
* @param debugMode 打开或关闭调试模式
*/
function setDebugMode(debugMode: boolean): void
/**
* 初始化GtPush
*/
function init(obj: {
/**
* 个推官网生成的appid
*/
appid: string
/**
* 个推终端ID回调,标识当前终端和应用
*/
onClientId?: (res: { cid: string }) => void
/**
* 个推终端ID在线状态回调
*/
onlineState?: (res: { online: boolean }) => void
/**
* 推送消息回调
*/
onPushMsg?: (res: { message: string }) => void
}): void
}
export default GtPush
此差异已折叠。
/*!
Copyright (c) 2011, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 2.9.0
*/
/**
* @fileOverview
* @name asn1-1.0.js
* @author Kenji Urushima kenji.urushima@gmail.com
* @version asn1 1.0.13 (2017-Jun-02)
* @since jsrsasign 2.1
* @license <a href="https://kjur.github.io/jsrsasign/license/">MIT License</a>
*/
/** @preserve
* Counter block mode compatible with Dr Brian Gladman fileenc.c
* derived from CryptoJS.mode.CTR
* Jan Hruby jhruby.web@gmail.com
*/
/** @preserve
(c) 2012 by Cédric Mesnil. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
此差异已折叠。
'use strict'
var path = require('path')
var debug = require('debug')
var uniCliShared = require('@dcloudio/uni-cli-shared')
function _interopDefaultLegacy(e) {
return e && typeof e === 'object' && 'default' in e ? e : { default: e }
}
var path__default = /*#__PURE__*/ _interopDefaultLegacy(path)
var debug__default = /*#__PURE__*/ _interopDefaultLegacy(debug)
const debugPush = debug__default['default']('uni:push')
var index = [
uniCliShared.defineUniMainJsPlugin((opts) => {
let isEnable = false
let isOffline = false
return {
name: 'uni:push',
enforce: 'pre',
config(config, env) {
if (uniCliShared.isSsr(env.command, config)) {
return
}
const inputDir = process.env.UNI_INPUT_DIR
const platform = process.env.UNI_PLATFORM
isOffline =
platform === 'app' && uniCliShared.isUniPushOffline(inputDir)
if (isOffline) {
isEnable = true
return
}
const { appid, enable, debug } = uniCliShared.getUniPush(
inputDir,
platform
)
isEnable = appid && enable === true
if (!isEnable) {
return
}
debugPush('appid', appid, 'deubg', debug)
return {
define: {
'process.env.UNI_PUSH_APP_ID': JSON.stringify(appid),
'process.env.UNI_PUSH_DEBUG': !!debug,
},
}
},
resolveId(id) {
if (id === '@dcloudio/uni-push') {
return uniCliShared.resolveBuiltIn(
path__default['default'].join(
'@dcloudio/uni-push',
isOffline ? 'dist/uni-push.plus.es.js' : 'dist/uni-push.es.js'
)
)
}
},
transform(code, id) {
if (!opts.filter(id)) {
return
}
if (isEnable) {
return {
code: code + `;import '@dcloudio/uni-push';`,
map: null,
}
}
},
}
}),
]
module.exports = index
{
"name": "@dcloudio/uni-push",
"version": "3.0.0-alpha-3030820220114006",
"description": "@dcloudio/uni-push",
"main": "lib/uni-push.js",
"module": "lib/uni-push.js",
"files": [
"lib"
],
"sideEffects": false,
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-push"
},
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/dcloudio/uni-app/issues"
},
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
"dependencies": {
"@dcloudio/uni-cli-shared": "3.0.0-alpha-3030820220114006",
"debug": "^4.3.2"
},
"devDependencies": {
"@types/debug": "^4.1.7"
}
}
import GtPush from '../lib/gtpush-min'
if (process.env.UNI_PUSH_DEBUG) {
GtPush.setDebugMode(true)
}
GtPush.init({
appid: process.env.UNI_PUSH_APP_ID!,
onClientId: (res) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'clientId',
cid: res.cid,
})
},
onlineState: (res) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'lineState',
online: res.online,
})
},
onPushMsg: (res) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'pushMsg',
message: res.message,
})
},
})
import path from 'path'
import debug from 'debug'
import {
defineUniMainJsPlugin,
isSsr,
getUniPush,
isUniPushOffline,
resolveBuiltIn,
} from '@dcloudio/uni-cli-shared'
const debugPush = debug('uni:push')
export default [
defineUniMainJsPlugin((opts) => {
let isEnable = false
let isOffline = false
return {
name: 'uni:push',
enforce: 'pre',
config(config, env) {
if (isSsr(env.command, config)) {
return
}
const inputDir = process.env.UNI_INPUT_DIR!
const platform = process.env.UNI_PLATFORM!
isOffline = platform === 'app' && isUniPushOffline(inputDir)
if (isOffline) {
isEnable = true
return
}
const { appid, enable, debug } = getUniPush(inputDir, platform)
isEnable = appid && enable === true
if (!isEnable) {
return
}
debugPush('appid', appid, 'deubg', debug)
return {
define: {
'process.env.UNI_PUSH_APP_ID': JSON.stringify(appid),
'process.env.UNI_PUSH_DEBUG': !!debug,
},
}
},
resolveId(id) {
if (id === '@dcloudio/uni-push') {
return resolveBuiltIn(
path.join(
'@dcloudio/uni-push',
isOffline ? 'dist/uni-push.plus.es.js' : 'dist/uni-push.es.js'
)
)
}
},
transform(code, id) {
if (!opts.filter(id)) {
return
}
if (isEnable) {
return {
code: code + `;import '@dcloudio/uni-push';`,
map: null,
}
}
},
}
}),
]
Promise.resolve().then(() => {
const info = plus.push.getClientInfo()
if (info.clientid) {
// @ts-expect-error
uni.invokePushCallback({
type: 'clientId',
cid: info.clientid,
})
}
plus.push.addEventListener('receive', (result) => {
// @ts-expect-error
uni.invokePushCallback({
type: 'pushMsg',
message: result,
})
})
})
{
"compilerOptions": {
"outDir": "dist",
"sourceMap": false,
"target": "es2015",
"module": "esnext",
"moduleResolution": "node",
"allowJs": false,
"strict": true,
"noUnusedLocals": true,
"experimentalDecorators": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"removeComments": false,
"lib": ["ESNext", "DOM"],
"types": ["@dcloudio/types"]
},
"include": ["src"]
}
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isPromise, isFunction, extend } from '@vue/shared';
import { isArray, hasOwn, isString, isPlainObject, isObject, capitalize, toRawType, makeMap, isFunction, isPromise, extend } from '@vue/shared';
import { injectHook } from 'vue';
//App
......@@ -189,6 +189,30 @@ function isBoolean(...args) {
return args.some((elem) => elem.toLowerCase() === 'boolean');
}
function tryCatch(fn) {
return function () {
try {
return fn.apply(fn, arguments);
}
catch (e) {
// TODO
console.error(e);
}
};
}
function getApiCallbacks(args) {
const apiCallbacks = {};
for (const name in args) {
const fn = args[name];
if (isFunction(fn)) {
apiCallbacks[name] = tryCatch(fn);
delete args[name];
}
}
return apiCallbacks;
}
const HOOK_SUCCESS = 'success';
const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
......@@ -584,6 +608,72 @@ const $emit = defineSyncApi(API_EMIT, (name, ...args) => {
emitter.emit(name, ...args);
}, EmitProtocol);
let cid = '';
/**
* @private
* @param args
*/
function invokePushCallback(args) {
if (args.type === 'clientId') {
cid = args.cid;
invokeGetPushCidCallbacks(cid);
}
else if (args.type === 'pushMsg') {
onPushMessageCallbacks.forEach((callback) => {
callback({ data: args.message });
});
}
}
const getPushCidCallbacks = [];
function invokeGetPushCidCallbacks(cid) {
getPushCidCallbacks.forEach((callback) => {
callback(cid);
});
getPushCidCallbacks.length = 0;
}
function getPushCid(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
getPushCidCallbacks.push((cid) => {
let res;
if (cid) {
res = { errMsg: 'getPushCid:ok', cid };
hasSuccess && success(res);
}
else {
res = { errMsg: 'getPushCid:fail' };
hasFail && fail(res);
}
hasComplete && complete(res);
});
if (cid) {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid));
}
}
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
onPushMessageCallbacks.push(fn);
}
};
const offPushMessage = (fn) => {
if (!fn) {
onPushMessageCallbacks.length = 0;
}
else {
const index = onPushMessageCallbacks.indexOf(fn);
if (index > -1) {
onPushMessageCallbacks.splice(index, 1);
}
}
};
const SYNC_API_RE = /^\$|getLocale|setLocale|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
// Context例外情况
......@@ -772,6 +862,10 @@ const baseApis = {
getLocale,
setLocale,
onLocaleChange,
getPushCid,
onPushMessage,
offPushMessage,
invokePushCallback,
};
function initUni(api, protocols) {
const wrapper = initWrapper(protocols);
......
......@@ -14,7 +14,7 @@ var index = [
name: 'uni:stat',
enforce: 'pre',
config(config, env) {
if (isSsr(env.command, config)) {
if (uniCliShared.isSsr(env.command, config)) {
return;
}
const inputDir = process.env.UNI_INPUT_DIR;
......@@ -65,14 +65,5 @@ var index = [
};
}),
];
function isSsr(command, config) {
if (command === 'serve') {
return !!(config.server && config.server.middlewareMode);
}
if (command === 'build') {
return !!(config.build && config.build.ssr);
}
return false;
}
module.exports = index;
import type { ConfigEnv, UserConfig } from 'vite'
import debug from 'debug'
import {
M,
......@@ -6,6 +5,7 @@ import {
getUniStatistics,
parseManifestJsonOnce,
parsePagesJson,
isSsr,
} from '@dcloudio/uni-cli-shared'
export default [
......@@ -64,13 +64,3 @@ export default [
}
}),
]
function isSsr(command: ConfigEnv['command'], config: UserConfig) {
if (command === 'serve') {
return !!(config.server && config.server.middlewareMode)
}
if (command === 'build') {
return !!(config.build && config.build.ssr)
}
return false
}
......@@ -154,6 +154,7 @@ importers:
'@dcloudio/uni-cloud': 3.0.0-alpha-3030820220114006
'@dcloudio/uni-components': 3.0.0-alpha-3030820220114006
'@dcloudio/uni-i18n': 3.0.0-alpha-3030820220114006
'@dcloudio/uni-push': 3.0.0-alpha-3030820220114006
'@dcloudio/uni-shared': 3.0.0-alpha-3030820220114006
'@dcloudio/uni-stat': 3.0.0-alpha-3030820220114006
'@vue/shared': 3.2.30
......@@ -161,6 +162,7 @@ importers:
'@dcloudio/uni-cloud': link:../uni-cloud
'@dcloudio/uni-components': link:../uni-components
'@dcloudio/uni-i18n': link:../uni-i18n
'@dcloudio/uni-push': link:../uni-push
'@dcloudio/uni-shared': link:../uni-shared
'@dcloudio/uni-stat': link:../uni-stat
'@vue/shared': 3.2.30
......@@ -742,6 +744,17 @@ importers:
devDependencies:
'@vue/compiler-core': 3.2.30
packages/uni-push:
specifiers:
'@dcloudio/uni-cli-shared': 3.0.0-alpha-3030820220114006
'@types/debug': ^4.1.7
debug: ^4.3.2
dependencies:
'@dcloudio/uni-cli-shared': link:../uni-cli-shared
debug: 4.3.3
devDependencies:
'@types/debug': 4.1.7
packages/uni-quickapp-webview:
specifiers:
'@dcloudio/uni-cli-shared': 3.0.0-alpha-3030820220114006
......
......@@ -8,6 +8,8 @@ const priority = {
'uni-app': 90,
'uni-cli-shared': 80,
'uni-stat': 75,
'uni-push': 75,
'uni-components': 75,
'uni-mp-vue': 75,
'uni-mp-alipay': 70,
'uni-mp-baidu': 70,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册