@@ -18,6 +18,7 @@ export const currentVersion = Pushy.currentVersion;
18
18
export const isFirstTime = Pushy . isFirstTime ;
19
19
export const isRolledBack = Pushy . isRolledBack ;
20
20
export const buildTime = Pushy . buildTime ;
21
+ let blockUpdate = Pushy . blockUpdate ;
21
22
22
23
if ( Platform . OS === 'android' && ! Pushy . isUsingBundleUrl ) {
23
24
throw new Error (
@@ -27,7 +28,7 @@ if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) {
27
28
28
29
/*
29
30
Return json:
30
- Package was expired:
31
+ Package expired:
31
32
{
32
33
expired: true,
33
34
downloadUrl: 'http://appstore/downloadUrl',
@@ -56,6 +57,14 @@ function assertRelease() {
56
57
57
58
export async function checkUpdate ( APPKEY , isRetry ) {
58
59
assertRelease ( ) ;
60
+ if ( blockUpdate && blockUpdate . until > Date . now ( ) ) {
61
+ console . warn (
62
+ `Pushy update is blocked until ${ new Date (
63
+ blockUpdate . until ,
64
+ ) . toLocaleString ( ) } . Reason: ${ blockUpdate . reason } `,
65
+ ) ;
66
+ return ;
67
+ }
59
68
let resp ;
60
69
try {
61
70
resp = await fetch ( getCheckUrl ( APPKEY ) , {
@@ -78,19 +87,35 @@ export async function checkUpdate(APPKEY, isRetry) {
78
87
return checkUpdate ( APPKEY , true ) ;
79
88
}
80
89
90
+ checkOperation ( resp ) ;
91
+
81
92
if ( resp . status !== 200 ) {
82
93
throw new Error ( ( await resp . json ( ) ) . message ) ;
83
94
}
84
95
85
96
return resp . json ( ) ;
86
97
}
87
98
99
+ function checkOperation ( resp ) {
100
+ if ( ! Array . isArray ( resp . op ) ) {
101
+ return ;
102
+ }
103
+ resp . op . forEach ( ( action ) => {
104
+ if ( action . type === 'block' ) {
105
+ blockUpdate = {
106
+ reason : action . reason ,
107
+ until : Date . now ( ) + action . duration ,
108
+ } ;
109
+ Pushy . setBlockUpdate ( blockUpdate ) ;
110
+ }
111
+ } ) ;
112
+ }
113
+
88
114
export async function downloadUpdate ( options ) {
89
115
assertRelease ( ) ;
90
116
if ( ! options . update ) {
91
117
return ;
92
118
}
93
-
94
119
if ( options . diffUrl ) {
95
120
await Pushy . downloadPatchFromPpk ( {
96
121
updateUrl : options . diffUrl ,
0 commit comments