Prevent some repeated actions
This commit is contained in:
parent
dba4a98fd0
commit
f4c62cc3d1
@ -154,7 +154,7 @@ public class UpdateContext {
|
|||||||
String lastVersion = getCurrentVersion();
|
String lastVersion = getCurrentVersion();
|
||||||
SharedPreferences.Editor editor = sp.edit();
|
SharedPreferences.Editor editor = sp.edit();
|
||||||
editor.putString("currentVersion", hash);
|
editor.putString("currentVersion", hash);
|
||||||
if (lastVersion != null) {
|
if (lastVersion != null && lastVersion != hash) {
|
||||||
editor.putString("lastVersion", lastVersion);
|
editor.putString("lastVersion", lastVersion);
|
||||||
}
|
}
|
||||||
editor.putBoolean("firstTime", true);
|
editor.putBoolean("firstTime", true);
|
||||||
|
37
lib/index.js
37
lib/index.js
@ -85,8 +85,17 @@ function assertRelease() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let checkingThrottling = false;
|
||||||
export async function checkUpdate(APPKEY, isRetry) {
|
export async function checkUpdate(APPKEY, isRetry) {
|
||||||
assertRelease();
|
assertRelease();
|
||||||
|
if (checkingThrottling) {
|
||||||
|
logger('repeated checking, ignored');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkingThrottling = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
checkingThrottling = false;
|
||||||
|
}, 3000);
|
||||||
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
|
if (blockUpdate && blockUpdate.until > Date.now() / 1000) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
|
`热更新已暂停,原因:${blockUpdate.reason}。请在"${new Date(
|
||||||
@ -145,11 +154,25 @@ function checkOperation(op) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let downloadingThrottling = false;
|
||||||
|
let downloadedHash;
|
||||||
export async function downloadUpdate(options, eventListeners) {
|
export async function downloadUpdate(options, eventListeners) {
|
||||||
assertRelease();
|
assertRelease();
|
||||||
if (!options.update) {
|
if (!options.update) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (downloadedHash === options.hash) {
|
||||||
|
logger(`duplicated downloaded hash ${downloadedHash}, ignored`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (downloadingThrottling) {
|
||||||
|
logger('repeated downloading, ignored');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
downloadingThrottling = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
downloadingThrottling = false;
|
||||||
|
}, 3000);
|
||||||
let progressHandler;
|
let progressHandler;
|
||||||
if (eventListeners) {
|
if (eventListeners) {
|
||||||
if (eventListeners.onDownloadProgress) {
|
if (eventListeners.onDownloadProgress) {
|
||||||
@ -188,7 +211,7 @@ export async function downloadUpdate(options, eventListeners) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
progressHandler && progressHandler.remove();
|
progressHandler && progressHandler.remove();
|
||||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
downloadedHash = options.hash;
|
||||||
return options.hash;
|
return options.hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,14 +221,26 @@ export function switchVersion(hash) {
|
|||||||
Pushy.reloadUpdate({ hash });
|
Pushy.reloadUpdate({ hash });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let readyHash;
|
||||||
export function switchVersionLater(hash) {
|
export function switchVersionLater(hash) {
|
||||||
assertRelease();
|
assertRelease();
|
||||||
|
if (readyHash === hash) {
|
||||||
|
logger(`duplicated ready hash ${readyHash}, ignored`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
readyHash = hash;
|
||||||
logger('switchVersionLater');
|
logger('switchVersionLater');
|
||||||
Pushy.setNeedUpdate({ hash });
|
Pushy.setNeedUpdate({ hash });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let marked = false;
|
||||||
export function markSuccess() {
|
export function markSuccess() {
|
||||||
assertRelease();
|
assertRelease();
|
||||||
|
if (marked) {
|
||||||
|
logger('repeated markSuccess, ignored');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
marked = true;
|
||||||
logger('markSuccess');
|
logger('markSuccess');
|
||||||
Pushy.markSuccess();
|
Pushy.markSuccess();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user