mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	setBlockUpdate
This commit is contained in:
		| @@ -27,6 +27,7 @@ static NSString *const paramLastVersion = @"lastVersion"; | |||||||
| static NSString *const paramCurrentVersion = @"currentVersion"; | static NSString *const paramCurrentVersion = @"currentVersion"; | ||||||
| static NSString *const paramIsFirstTime = @"isFirstTime"; | static NSString *const paramIsFirstTime = @"isFirstTime"; | ||||||
| static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK"; | static NSString *const paramIsFirstLoadOk = @"isFirstLoadOK"; | ||||||
|  | static NSString *const keyBlockUpdate = @"blockUpdate" | ||||||
| static NSString *const keyFirstLoadMarked = @"REACTNATIVECN_PUSHY_FIRSTLOADMARKED_KEY"; | static NSString *const keyFirstLoadMarked = @"REACTNATIVECN_PUSHY_FIRSTLOADMARKED_KEY"; | ||||||
| static NSString *const keyRolledBackMarked = @"REACTNATIVECN_PUSHY_ROLLEDBACKMARKED_KEY"; | static NSString *const keyRolledBackMarked = @"REACTNATIVECN_PUSHY_ROLLEDBACKMARKED_KEY"; | ||||||
| static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_PUSHY_ISPACKAGEUPDATEDMARKED_KEY"; | static NSString *const KeyPackageUpdatedMarked = @"REACTNATIVECN_PUSHY_ISPACKAGEUPDATEDMARKED_KEY"; | ||||||
| @@ -155,6 +156,7 @@ RCT_EXPORT_MODULE(RCTPushy); | |||||||
|     ret[@"buildTime"] = [RCTPushy buildTime]; |     ret[@"buildTime"] = [RCTPushy buildTime]; | ||||||
|     ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked]; |     ret[@"isRolledBack"] = [defaults objectForKey:keyRolledBackMarked]; | ||||||
|     ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked]; |     ret[@"isFirstTime"] = [defaults objectForKey:keyFirstLoadMarked]; | ||||||
|  |     ret[@"blockUpdate"] = [defaults objectForKey:keyBlockUpdate]; | ||||||
|     NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo]; |     NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo]; | ||||||
|     ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion]; |     ret[@"currentVersion"] = [pushyInfo objectForKey:paramCurrentVersion]; | ||||||
|      |      | ||||||
| @@ -188,6 +190,16 @@ RCT_EXPORT_MODULE(RCTPushy); | |||||||
|     return self; |     return self; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | RCT_EXPORT_METHOD(setBlockUpdate:(NSDictionary *)options) | ||||||
|  | { | ||||||
|  |     // NSMutableDictionary *blockUpdateInfo = [NSMutableDictionary new]; | ||||||
|  |     // blockUpdateInfo[@"reason"] = options[@"reason"]; | ||||||
|  |     // blockUpdateInfo[@"until"] = options[@"until"]; | ||||||
|  |     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | ||||||
|  |     [defaults setObject:options forKey:keyBlockUpdate]; | ||||||
|  |     [defaults synchronize]; | ||||||
|  | } | ||||||
|  |  | ||||||
| RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary *)options | RCT_EXPORT_METHOD(downloadUpdate:(NSDictionary *)options | ||||||
|                   resolver:(RCTPromiseResolveBlock)resolve |                   resolver:(RCTPromiseResolveBlock)resolve | ||||||
|                   rejecter:(RCTPromiseRejectBlock)reject) |                   rejecter:(RCTPromiseRejectBlock)reject) | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								lib/index.js
									
									
									
									
									
								
							| @@ -18,6 +18,7 @@ export const currentVersion = Pushy.currentVersion; | |||||||
| export const isFirstTime = Pushy.isFirstTime; | export const isFirstTime = Pushy.isFirstTime; | ||||||
| export const isRolledBack = Pushy.isRolledBack; | export const isRolledBack = Pushy.isRolledBack; | ||||||
| export const buildTime = Pushy.buildTime; | export const buildTime = Pushy.buildTime; | ||||||
|  | let blockUpdate = Pushy.blockUpdate; | ||||||
|  |  | ||||||
| if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) { | if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) { | ||||||
|   throw new Error( |   throw new Error( | ||||||
| @@ -27,7 +28,7 @@ if (Platform.OS === 'android' && !Pushy.isUsingBundleUrl) { | |||||||
|  |  | ||||||
| /* | /* | ||||||
| Return json: | Return json: | ||||||
| Package was expired: | Package expired: | ||||||
| { | { | ||||||
|   expired: true, |   expired: true, | ||||||
|   downloadUrl: 'http://appstore/downloadUrl', |   downloadUrl: 'http://appstore/downloadUrl', | ||||||
| @@ -56,6 +57,14 @@ function assertRelease() { | |||||||
|  |  | ||||||
| export async function checkUpdate(APPKEY, isRetry) { | export async function checkUpdate(APPKEY, isRetry) { | ||||||
|   assertRelease(); |   assertRelease(); | ||||||
|  |   if (blockUpdate && blockUpdate.until > Date.now()) { | ||||||
|  |     console.warn( | ||||||
|  |       `Pushy update is blocked until ${new Date( | ||||||
|  |         blockUpdate.until, | ||||||
|  |       ).toLocaleString()}. Reason: ${blockUpdate.reason}`, | ||||||
|  |     ); | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|   let resp; |   let resp; | ||||||
|   try { |   try { | ||||||
|     resp = await fetch(getCheckUrl(APPKEY), { |     resp = await fetch(getCheckUrl(APPKEY), { | ||||||
| @@ -78,6 +87,8 @@ export async function checkUpdate(APPKEY, isRetry) { | |||||||
|     return checkUpdate(APPKEY, true); |     return checkUpdate(APPKEY, true); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   checkOperation(resp); | ||||||
|  |  | ||||||
|   if (resp.status !== 200) { |   if (resp.status !== 200) { | ||||||
|     throw new Error((await resp.json()).message); |     throw new Error((await resp.json()).message); | ||||||
|   } |   } | ||||||
| @@ -85,12 +96,26 @@ export async function checkUpdate(APPKEY, isRetry) { | |||||||
|   return resp.json(); |   return resp.json(); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | function checkOperation(resp) { | ||||||
|  |   if (!Array.isArray(resp.op)) { | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |   resp.op.forEach((action) => { | ||||||
|  |     if (action.type === 'block') { | ||||||
|  |       blockUpdate = { | ||||||
|  |         reason: action.reason, | ||||||
|  |         until: Date.now() + action.duration, | ||||||
|  |       }; | ||||||
|  |       Pushy.setBlockUpdate(blockUpdate); | ||||||
|  |     } | ||||||
|  |   }); | ||||||
|  | } | ||||||
|  |  | ||||||
| export async function downloadUpdate(options) { | export async function downloadUpdate(options) { | ||||||
|   assertRelease(); |   assertRelease(); | ||||||
|   if (!options.update) { |   if (!options.update) { | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (options.diffUrl) { |   if (options.diffUrl) { | ||||||
|     await Pushy.downloadPatchFromPpk({ |     await Pushy.downloadPatchFromPpk({ | ||||||
|       updateUrl: options.diffUrl, |       updateUrl: options.diffUrl, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm