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

feat(push): add enabled event

上级 688021bf
...@@ -103,6 +103,10 @@ var GtPush = /*@__PURE__*/getDefaultExportFromCjs(gtpushMin); ...@@ -103,6 +103,10 @@ var GtPush = /*@__PURE__*/getDefaultExportFromCjs(gtpushMin);
// if (process.env.UNI_PUSH_DEBUG) { // if (process.env.UNI_PUSH_DEBUG) {
// GtPush.setDebugMode(true) // GtPush.setDebugMode(true)
// } // }
// @ts-expect-error
uni.invokePushCallback({
type: 'enabled',
});
const appid = process.env.UNI_APP_ID; const appid = process.env.UNI_APP_ID;
if (!appid) { if (!appid) {
Promise.resolve().then(() => { Promise.resolve().then(() => {
......
// @ts-expect-error
uni.invokePushCallback({
type: 'enabled',
});
Promise.resolve().then(() => { Promise.resolve().then(() => {
plus.push.setAutoNotification && plus.push.setAutoNotification(false); plus.push.setAutoNotification && plus.push.setAutoNotification(false);
const info = plus.push.getClientInfo(); const info = plus.push.getClientInfo();
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
let cid let cid
let cidErrMsg let cidErrMsg
let enabled
function normalizePushMessage (message) { function normalizePushMessage (message) {
try { try {
...@@ -19,7 +20,9 @@ function normalizePushMessage (message) { ...@@ -19,7 +20,9 @@ function normalizePushMessage (message) {
export function invokePushCallback ( export function invokePushCallback (
args args
) { ) {
if (args.type === 'clientId') { if (args.type === 'enabled') {
enabled = true
} else if (args.type === 'clientId') {
cid = args.cid cid = args.cid
cidErrMsg = args.errMsg cidErrMsg = args.errMsg
invokeGetPushCidCallbacks(cid, args.errMsg) invokeGetPushCidCallbacks(cid, args.errMsg)
...@@ -61,25 +64,32 @@ export function getPushClientId (args) { ...@@ -61,25 +64,32 @@ export function getPushClientId (args) {
const hasSuccess = isFn(success) const hasSuccess = isFn(success)
const hasFail = isFn(fail) const hasFail = isFn(fail)
const hasComplete = isFn(complete) const hasComplete = isFn(complete)
getPushCidCallbacks.push((cid, errMsg) => { Promise.resolve().then(() => {
let res if (typeof enabled === 'undefined') {
if (cid) { enabled = false
res = { cid = ''
errMsg: 'getPushClientId:ok', cidErrMsg = 'unipush is not enabled'
cid }
} getPushCidCallbacks.push((cid, errMsg) => {
hasSuccess && success(res) let res
} else { if (cid) {
res = { res = {
errMsg: 'getPushClientId:fail' + (errMsg ? ' ' + errMsg : '') errMsg: 'getPushClientId:ok',
cid
}
hasSuccess && success(res)
} else {
res = {
errMsg: 'getPushClientId:fail' + (errMsg ? ' ' + errMsg : '')
}
hasFail && fail(res)
} }
hasFail && fail(res) hasComplete && complete(res)
})
if (typeof cid !== 'undefined') {
invokeGetPushCidCallbacks(cid, cidErrMsg)
} }
hasComplete && complete(res)
}) })
if (typeof cid !== 'undefined') {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid, cidErrMsg))
}
} }
const onPushMessageCallbacks = [] const onPushMessageCallbacks = []
...@@ -99,4 +109,4 @@ export const offPushMessage = (fn) => { ...@@ -99,4 +109,4 @@ export const offPushMessage = (fn) => {
onPushMessageCallbacks.splice(index, 1) onPushMessageCallbacks.splice(index, 1)
} }
} }
} }
...@@ -4,7 +4,7 @@ import { ...@@ -4,7 +4,7 @@ import {
import { isFn, isPlainObject } from 'uni-shared' import { isFn, isPlainObject } from 'uni-shared'
const providers = { const providers = {
oauth(callback) { oauth (callback) {
plus.oauth.getServices(services => { plus.oauth.getServices(services => {
const provider = [] const provider = []
services.forEach(({ services.forEach(({
...@@ -17,7 +17,7 @@ const providers = { ...@@ -17,7 +17,7 @@ const providers = {
callback(err) callback(err)
}) })
}, },
share(callback) { share (callback) {
plus.share.getServices(services => { plus.share.getServices(services => {
const provider = [] const provider = []
services.forEach(({ services.forEach(({
...@@ -30,7 +30,7 @@ const providers = { ...@@ -30,7 +30,7 @@ const providers = {
callback(err) callback(err)
}) })
}, },
payment(callback) { payment (callback) {
plus.payment.getChannels(services => { plus.payment.getChannels(services => {
const provider = [] const provider = []
services.forEach(({ services.forEach(({
...@@ -43,7 +43,7 @@ const providers = { ...@@ -43,7 +43,7 @@ const providers = {
callback(err) callback(err)
}) })
}, },
push(callback) { push (callback) {
if (typeof weex !== 'undefined' || typeof plus !== 'undefined') { if (typeof weex !== 'undefined' || typeof plus !== 'undefined') {
const clientInfo = plus.push.getClientInfo() const clientInfo = plus.push.getClientInfo()
callback(null, [clientInfo.id], [clientInfo]) callback(null, [clientInfo.id], [clientInfo])
...@@ -53,7 +53,7 @@ const providers = { ...@@ -53,7 +53,7 @@ const providers = {
} }
} }
export function getProvider({ export function getProvider ({
service service
}, callbackId) { }, callbackId) {
if (providers[service]) { if (providers[service]) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册