@dcloudio/uni-push 3.0.0-alpha-3070720230316001 → 3.0.0-alpha-3071220230324001

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -102,158 +102,158 @@ var gtpushMin = {
102
102
 
103
103
  var GtPush = /*@__PURE__*/getDefaultExportFromCjs(gtpushMinExports);
104
104
 
105
- function initPushNotification() {
106
- // 仅 App 端
107
- if (typeof plus !== 'undefined' && plus.push) {
108
- plus.globalEvent.addEventListener('newPath', ({ path }) => {
109
- if (!path) {
110
- return;
111
- }
112
- // 指定的页面为当前页面
113
- const pages = getCurrentPages();
114
- const currentPage = pages[pages.length - 1];
115
- if (currentPage &&
116
- currentPage.$page &&
117
- currentPage.$page.fullPath === path) {
118
- return;
119
- }
120
- // 简单起见,先尝试 navigateTo 跳转,失败后,再尝试 tabBar 跳转
121
- uni.navigateTo({
122
- url: path,
123
- fail(res) {
124
- if (res.errMsg.indexOf('tabbar') > -1) {
125
- uni.switchTab({
126
- url: path,
127
- fail(res) {
128
- console.error(res.errMsg);
129
- },
130
- });
131
- }
132
- else {
133
- console.error(res.errMsg);
134
- }
135
- },
136
- });
137
- });
138
- }
105
+ function initPushNotification() {
106
+ // 仅 App 端
107
+ if (typeof plus !== 'undefined' && plus.push) {
108
+ plus.globalEvent.addEventListener('newPath', ({ path }) => {
109
+ if (!path) {
110
+ return;
111
+ }
112
+ // 指定的页面为当前页面
113
+ const pages = getCurrentPages();
114
+ const currentPage = pages[pages.length - 1];
115
+ if (currentPage &&
116
+ currentPage.$page &&
117
+ currentPage.$page.fullPath === path) {
118
+ return;
119
+ }
120
+ // 简单起见,先尝试 navigateTo 跳转,失败后,再尝试 tabBar 跳转
121
+ uni.navigateTo({
122
+ url: path,
123
+ fail(res) {
124
+ if (res.errMsg.indexOf('tabbar') > -1) {
125
+ uni.switchTab({
126
+ url: path,
127
+ fail(res) {
128
+ console.error(res.errMsg);
129
+ },
130
+ });
131
+ }
132
+ else {
133
+ console.error(res.errMsg);
134
+ }
135
+ },
136
+ });
137
+ });
138
+ }
139
139
  }
140
140
 
141
- let channel;
142
- function postPushMessage(data) {
143
- if (!channel) {
144
- return;
145
- }
146
- channel.postMessage(data);
147
- }
148
- function initBroadcastChannel(gtPush) {
149
- if (typeof BroadcastChannel === 'undefined') {
150
- return;
151
- }
152
- channel = new BroadcastChannel('uni-push');
153
- channel.onmessage = function ({ data }) {
154
- // @ts-expect-error
155
- uni.invokePushCallback(data);
156
- };
157
- // eslint-disable-next-line no-restricted-globals
158
- document.addEventListener('visibilitychange', function () {
159
- // eslint-disable-next-line no-restricted-globals
160
- if (document.visibilityState === 'visible') {
161
- gtPush.enableSocket(true);
162
- }
163
- });
141
+ let channel;
142
+ function postPushMessage(data) {
143
+ if (!channel) {
144
+ return;
145
+ }
146
+ channel.postMessage(data);
147
+ }
148
+ function initBroadcastChannel(gtPush) {
149
+ if (typeof BroadcastChannel === 'undefined') {
150
+ return;
151
+ }
152
+ channel = new BroadcastChannel('uni-push');
153
+ channel.onmessage = function ({ data }) {
154
+ // @ts-expect-error
155
+ uni.invokePushCallback(data);
156
+ };
157
+ // eslint-disable-next-line no-restricted-globals
158
+ document.addEventListener('visibilitychange', function () {
159
+ // eslint-disable-next-line no-restricted-globals
160
+ if (document.visibilityState === 'visible') {
161
+ gtPush.enableSocket(true);
162
+ }
163
+ });
164
164
  }
165
165
 
166
- // if (process.env.UNI_PUSH_DEBUG) {
167
- // GtPush.setDebugMode(true)
168
- // }
169
- // @ts-expect-error
170
- uni.invokePushCallback({
171
- type: 'enabled',
172
- });
173
- const appid = process.env.UNI_APP_ID;
174
- if (!appid) {
175
- Promise.resolve().then(() => {
176
- // @ts-expect-error
177
- uni.invokePushCallback({
178
- type: 'clientId',
179
- cid: '',
180
- errMsg: 'manifest.json->appid is required',
181
- });
182
- });
183
- }
184
- else {
185
- // #ifdef APP
186
- initPushNotification();
187
- // #endif
188
- // #ifdef H5
189
- initBroadcastChannel(GtPush);
190
- // #endif
191
- // #ifdef MP || APP
192
- if (typeof uni.onAppShow === 'function') {
193
- uni.onAppShow(() => {
194
- GtPush.enableSocket(true);
195
- });
196
- }
197
- // #endif
198
- GtPush.init({
199
- appid,
200
- onError: (res) => {
201
- console.error(res.error);
202
- const data = {
203
- type: 'clientId',
204
- cid: '',
205
- errMsg: res.error,
206
- };
207
- // @ts-expect-error
208
- uni.invokePushCallback(data);
209
- // #ifdef H5
210
- postPushMessage(data);
211
- // #endif
212
- },
213
- onClientId: (res) => {
214
- const data = {
215
- type: 'clientId',
216
- cid: res.cid,
217
- };
218
- // @ts-expect-error
219
- uni.invokePushCallback(data);
220
- // #ifdef H5
221
- postPushMessage(data);
222
- // #endif
223
- },
224
- onlineState: (res) => {
225
- const data = {
226
- type: 'lineState',
227
- online: res.online,
228
- };
229
- // @ts-expect-error
230
- uni.invokePushCallback(data);
231
- // #ifdef H5
232
- postPushMessage(data);
233
- // #endif
234
- },
235
- onPushMsg: (res) => {
236
- const data = {
237
- type: 'pushMsg',
238
- message: res.message,
239
- };
240
- // @ts-expect-error
241
- uni.invokePushCallback(data);
242
- // #ifdef H5
243
- postPushMessage(data);
244
- // #endif
245
- },
246
- });
247
- // 仅在 jssdk 中监听
248
- // #ifdef APP
249
- uni.onPushMessage((res) => {
250
- if (res.type === 'receive' &&
251
- res.data &&
252
- res.data.force_notification) {
253
- // 创建通知栏
254
- uni.createPushMessage(res.data);
255
- res.stopped = true;
256
- }
257
- });
258
- // #endif
166
+ // if (process.env.UNI_PUSH_DEBUG) {
167
+ // GtPush.setDebugMode(true)
168
+ // }
169
+ // @ts-expect-error
170
+ uni.invokePushCallback({
171
+ type: 'enabled',
172
+ });
173
+ const appid = process.env.UNI_APP_ID;
174
+ if (!appid) {
175
+ Promise.resolve().then(() => {
176
+ // @ts-expect-error
177
+ uni.invokePushCallback({
178
+ type: 'clientId',
179
+ cid: '',
180
+ errMsg: 'manifest.json->appid is required',
181
+ });
182
+ });
183
+ }
184
+ else {
185
+ // #ifdef APP
186
+ initPushNotification();
187
+ // #endif
188
+ // #ifdef H5
189
+ initBroadcastChannel(GtPush);
190
+ // #endif
191
+ // #ifdef MP || APP
192
+ if (typeof uni.onAppShow === 'function') {
193
+ uni.onAppShow(() => {
194
+ GtPush.enableSocket(true);
195
+ });
196
+ }
197
+ // #endif
198
+ GtPush.init({
199
+ appid,
200
+ onError: (res) => {
201
+ console.error(res.error);
202
+ const data = {
203
+ type: 'clientId',
204
+ cid: '',
205
+ errMsg: res.error,
206
+ };
207
+ // @ts-expect-error
208
+ uni.invokePushCallback(data);
209
+ // #ifdef H5
210
+ postPushMessage(data);
211
+ // #endif
212
+ },
213
+ onClientId: (res) => {
214
+ const data = {
215
+ type: 'clientId',
216
+ cid: res.cid,
217
+ };
218
+ // @ts-expect-error
219
+ uni.invokePushCallback(data);
220
+ // #ifdef H5
221
+ postPushMessage(data);
222
+ // #endif
223
+ },
224
+ onlineState: (res) => {
225
+ const data = {
226
+ type: 'lineState',
227
+ online: res.online,
228
+ };
229
+ // @ts-expect-error
230
+ uni.invokePushCallback(data);
231
+ // #ifdef H5
232
+ postPushMessage(data);
233
+ // #endif
234
+ },
235
+ onPushMsg: (res) => {
236
+ const data = {
237
+ type: 'pushMsg',
238
+ message: res.message,
239
+ };
240
+ // @ts-expect-error
241
+ uni.invokePushCallback(data);
242
+ // #ifdef H5
243
+ postPushMessage(data);
244
+ // #endif
245
+ },
246
+ });
247
+ // 仅在 jssdk 中监听
248
+ // #ifdef APP
249
+ uni.onPushMessage((res) => {
250
+ if (res.type === 'receive' &&
251
+ res.data &&
252
+ res.data.force_notification) {
253
+ // 创建通知栏
254
+ uni.createPushMessage(res.data);
255
+ res.stopped = true;
256
+ }
257
+ });
258
+ // #endif
259
259
  }
@@ -1,45 +1,45 @@
1
- function initPushNotification() {
2
- // 仅 App 端
3
- if (typeof plus !== 'undefined' && plus.push) {
4
- plus.globalEvent.addEventListener('newPath', ({ path }) => {
5
- if (!path) {
6
- return;
7
- }
8
- // 指定的页面为当前页面
9
- const pages = getCurrentPages();
10
- const currentPage = pages[pages.length - 1];
11
- if (currentPage &&
12
- currentPage.$page &&
13
- currentPage.$page.fullPath === path) {
14
- return;
15
- }
16
- // 简单起见,先尝试 navigateTo 跳转,失败后,再尝试 tabBar 跳转
17
- uni.navigateTo({
18
- url: path,
19
- fail(res) {
20
- if (res.errMsg.indexOf('tabbar') > -1) {
21
- uni.switchTab({
22
- url: path,
23
- fail(res) {
24
- console.error(res.errMsg);
25
- },
26
- });
27
- }
28
- else {
29
- console.error(res.errMsg);
30
- }
31
- },
32
- });
33
- });
34
- }
1
+ function initPushNotification() {
2
+ // 仅 App 端
3
+ if (typeof plus !== 'undefined' && plus.push) {
4
+ plus.globalEvent.addEventListener('newPath', ({ path }) => {
5
+ if (!path) {
6
+ return;
7
+ }
8
+ // 指定的页面为当前页面
9
+ const pages = getCurrentPages();
10
+ const currentPage = pages[pages.length - 1];
11
+ if (currentPage &&
12
+ currentPage.$page &&
13
+ currentPage.$page.fullPath === path) {
14
+ return;
15
+ }
16
+ // 简单起见,先尝试 navigateTo 跳转,失败后,再尝试 tabBar 跳转
17
+ uni.navigateTo({
18
+ url: path,
19
+ fail(res) {
20
+ if (res.errMsg.indexOf('tabbar') > -1) {
21
+ uni.switchTab({
22
+ url: path,
23
+ fail(res) {
24
+ console.error(res.errMsg);
25
+ },
26
+ });
27
+ }
28
+ else {
29
+ console.error(res.errMsg);
30
+ }
31
+ },
32
+ });
33
+ });
34
+ }
35
35
  }
36
36
 
37
- // @ts-expect-error
38
- uni.invokePushCallback({
39
- type: 'enabled',
40
- offline: true,
41
- });
42
- Promise.resolve().then(() => {
43
- initPushNotification();
44
- plus.push.setAutoNotification && plus.push.setAutoNotification(false);
37
+ // @ts-expect-error
38
+ uni.invokePushCallback({
39
+ type: 'enabled',
40
+ offline: true,
41
+ });
42
+ Promise.resolve().then(() => {
43
+ initPushNotification();
44
+ plus.push.setAutoNotification && plus.push.setAutoNotification(false);
45
45
  });
package/lib/uni.plugin.js CHANGED
@@ -7,60 +7,60 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
7
 
8
8
  var path__default = /*#__PURE__*/_interopDefault(path);
9
9
 
10
- var index = () => [
11
- uniCliShared.defineUniMainJsPlugin((opts) => {
12
- let isEnableV1 = false;
13
- let isEnableV2 = false;
14
- let isOffline = false;
15
- return {
16
- name: 'uni:push',
17
- enforce: 'pre',
18
- config(config, env) {
19
- if (uniCliShared.isSsr(env.command, config)) {
20
- return;
21
- }
22
- const inputDir = process.env.UNI_INPUT_DIR;
23
- const platform = process.env.UNI_PLATFORM;
24
- isEnableV1 = uniCliShared.isEnableUniPushV1(inputDir, platform);
25
- isEnableV2 = uniCliShared.isEnableUniPushV2(inputDir, platform);
26
- // v1
27
- if (isEnableV1) {
28
- return;
29
- }
30
- if (!isEnableV2) {
31
- return;
32
- }
33
- // v2
34
- isOffline = platform === 'app' && uniCliShared.isUniPushOffline(inputDir);
35
- if (isOffline) {
36
- return;
37
- }
38
- return {
39
- define: {
40
- 'process.env.UNI_PUSH_DEBUG': false,
41
- },
42
- };
43
- },
44
- resolveId(id) {
45
- if (id === '@dcloudio/uni-push') {
46
- return uniCliShared.resolveBuiltIn(path__default.default.join('@dcloudio/uni-push', isOffline || isEnableV1
47
- ? 'dist/uni-push.plus.es.js'
48
- : 'dist/uni-push.es.js'));
49
- }
50
- },
51
- transform(code, id) {
52
- if (!opts.filter(id)) {
53
- return;
54
- }
55
- if (isEnableV1 || isEnableV2) {
56
- return {
57
- code: `import '@dcloudio/uni-push';` + code,
58
- map: null,
59
- };
60
- }
61
- },
62
- };
63
- }),
10
+ var index = () => [
11
+ uniCliShared.defineUniMainJsPlugin((opts) => {
12
+ let isEnableV1 = false;
13
+ let isEnableV2 = false;
14
+ let isOffline = false;
15
+ return {
16
+ name: 'uni:push',
17
+ enforce: 'pre',
18
+ config(config, env) {
19
+ if (uniCliShared.isSsr(env.command, config)) {
20
+ return;
21
+ }
22
+ const inputDir = process.env.UNI_INPUT_DIR;
23
+ const platform = process.env.UNI_PLATFORM;
24
+ isEnableV1 = uniCliShared.isEnableUniPushV1(inputDir, platform);
25
+ isEnableV2 = uniCliShared.isEnableUniPushV2(inputDir, platform);
26
+ // v1
27
+ if (isEnableV1) {
28
+ return;
29
+ }
30
+ if (!isEnableV2) {
31
+ return;
32
+ }
33
+ // v2
34
+ isOffline = platform === 'app' && uniCliShared.isUniPushOffline(inputDir);
35
+ if (isOffline) {
36
+ return;
37
+ }
38
+ return {
39
+ define: {
40
+ 'process.env.UNI_PUSH_DEBUG': false,
41
+ },
42
+ };
43
+ },
44
+ resolveId(id) {
45
+ if (id === '@dcloudio/uni-push') {
46
+ return uniCliShared.resolveBuiltIn(path__default.default.join('@dcloudio/uni-push', isOffline || isEnableV1
47
+ ? 'dist/uni-push.plus.es.js'
48
+ : 'dist/uni-push.es.js'));
49
+ }
50
+ },
51
+ transform(code, id) {
52
+ if (!opts.filter(id)) {
53
+ return;
54
+ }
55
+ if (isEnableV1 || isEnableV2) {
56
+ return {
57
+ code: `import '@dcloudio/uni-push';` + code,
58
+ map: null,
59
+ };
60
+ }
61
+ },
62
+ };
63
+ }),
64
64
  ];
65
65
 
66
66
  module.exports = index;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-push",
3
- "version": "3.0.0-alpha-3070720230316001",
3
+ "version": "3.0.0-alpha-3071220230324001",
4
4
  "description": "@dcloudio/uni-push",
5
5
  "main": "lib/uni-push.js",
6
6
  "module": "lib/uni-push.js",
@@ -20,6 +20,6 @@
20
20
  },
21
21
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
22
22
  "dependencies": {
23
- "@dcloudio/uni-cli-shared": "3.0.0-alpha-3070720230316001"
23
+ "@dcloudio/uni-cli-shared": "3.0.0-alpha-3071220230324001"
24
24
  }
25
25
  }