mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-08 00:42:13 +02:00
Update version release notification handling (#2267)
* Update the GitHub version check to also utilise the date a release was done, to allow 1 month grace period before generating obsolete version message.
This commit is contained in:
parent
678add91f8
commit
3bca35d345
94
src/util.d
94
src/util.d
|
@ -361,12 +361,14 @@ string getFunctionName(alias func)() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the latest release version from GitHub
|
// Get the latest release version from GitHub
|
||||||
string getLatestReleaseVersion() {
|
JSONValue getLatestReleaseDetails() {
|
||||||
// Import curl just for this function
|
// Import curl just for this function
|
||||||
import std.net.curl;
|
import std.net.curl;
|
||||||
char[] content;
|
char[] content;
|
||||||
JSONValue json;
|
JSONValue githubLatest;
|
||||||
|
JSONValue versionDetails;
|
||||||
string latestTag;
|
string latestTag;
|
||||||
|
string publishedDate;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
content = get("https://api.github.com/repos/abraunegg/onedrive/releases/latest");
|
content = get("https://api.github.com/repos/abraunegg/onedrive/releases/latest");
|
||||||
|
@ -376,51 +378,101 @@ string getLatestReleaseVersion() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json = content.parseJSON();
|
githubLatest = content.parseJSON();
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
// unable to parse the content JSON, set to blank JSON
|
// unable to parse the content JSON, set to blank JSON
|
||||||
log.vdebug("Unable to parse GitHub JSON response");
|
log.vdebug("Unable to parse GitHub JSON response");
|
||||||
json = parseJSON("{}");
|
githubLatest = parseJSON("{}");
|
||||||
}
|
}
|
||||||
|
|
||||||
// json has to be a valid JSON object
|
// githubLatest has to be a valid JSON object
|
||||||
if (json.type() == JSONType.object){
|
if (githubLatest.type() == JSONType.object){
|
||||||
if ("tag_name" in json) {
|
// use the returned tag_name
|
||||||
|
if ("tag_name" in githubLatest) {
|
||||||
// use the provided tag
|
// use the provided tag
|
||||||
// "tag_name": "vA.B.CC" and strip 'v'
|
// "tag_name": "vA.B.CC" and strip 'v'
|
||||||
latestTag = strip(json["tag_name"].str, "v");
|
latestTag = strip(githubLatest["tag_name"].str, "v");
|
||||||
} else {
|
} else {
|
||||||
// set to latestTag zeros
|
// set to latestTag zeros
|
||||||
log.vdebug("'tag_name' unavailable in JSON response. Setting latest GitHub release version to 0.0.0");
|
log.vdebug("'tag_name' unavailable in JSON response. Setting GitHub 'tag_name' release version to 0.0.0");
|
||||||
latestTag = "0.0.0";
|
latestTag = "0.0.0";
|
||||||
}
|
}
|
||||||
|
// use the returned published_at date
|
||||||
|
if ("published_at" in githubLatest) {
|
||||||
|
// use the provided value
|
||||||
|
publishedDate = githubLatest["published_at"].str;
|
||||||
|
} else {
|
||||||
|
// set to v2.0.0 release date
|
||||||
|
log.vdebug("'published_at' unavailable in JSON response. Setting GitHub 'published_at' date to 2018-07-18T18:00:00Z");
|
||||||
|
publishedDate = "2018-07-18T18:00:00Z";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// JSONValue is not an object
|
// JSONValue is not an object
|
||||||
log.vdebug("Invalid JSON Object. Setting latest GitHub release version to 0.0.0");
|
log.vdebug("Invalid JSON Object. Setting GitHub 'tag_name' release version to 0.0.0");
|
||||||
latestTag = "0.0.0";
|
latestTag = "0.0.0";
|
||||||
|
log.vdebug("Invalid JSON Object. Setting GitHub 'published_at' date to 2018-07-18T18:00:00Z");
|
||||||
|
publishedDate = "2018-07-18T18:00:00Z";
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the latest github version
|
// return the latest github version and published date as our own JSON
|
||||||
return latestTag;
|
versionDetails = [
|
||||||
|
"latestTag": JSONValue(latestTag),
|
||||||
|
"publishedDate": JSONValue(publishedDate)
|
||||||
|
];
|
||||||
|
|
||||||
|
// return JSON
|
||||||
|
return versionDetails;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the application version versus GitHub latestTag
|
// Check the application version versus GitHub latestTag
|
||||||
void checkApplicationVersion() {
|
void checkApplicationVersion() {
|
||||||
// calculate if the client is current version or not
|
// Get the latest details from GitHub
|
||||||
string latestVersion = strip(getLatestReleaseVersion());
|
JSONValue latestVersionDetails = getLatestReleaseDetails();
|
||||||
|
string latestVersion = latestVersionDetails["latestTag"].str;
|
||||||
|
SysTime publishedDate = SysTime.fromISOExtString(latestVersionDetails["publishedDate"].str).toUTC();
|
||||||
|
SysTime releaseGracePeriod = publishedDate;
|
||||||
|
SysTime currentTime = Clock.currTime().toUTC();
|
||||||
|
|
||||||
|
// drop fraction seconds
|
||||||
|
publishedDate.fracSecs = Duration.zero;
|
||||||
|
currentTime.fracSecs = Duration.zero;
|
||||||
|
releaseGracePeriod.fracSecs = Duration.zero;
|
||||||
|
// roll the grace period forward to allow distributions to catch up based on their release cycles
|
||||||
|
releaseGracePeriod = releaseGracePeriod.add!"months"(1);
|
||||||
|
|
||||||
|
// what is this clients version?
|
||||||
auto currentVersionArray = strip(strip(import("version"), "v")).split("-");
|
auto currentVersionArray = strip(strip(import("version"), "v")).split("-");
|
||||||
string applicationVersion = currentVersionArray[0];
|
string applicationVersion = currentVersionArray[0];
|
||||||
|
|
||||||
// display warning if not current
|
// debug output
|
||||||
|
log.vdebug("applicationVersion: ", applicationVersion);
|
||||||
|
log.vdebug("latestVersion: ", latestVersion);
|
||||||
|
log.vdebug("publishedDate: ", publishedDate);
|
||||||
|
log.vdebug("currentTime: ", currentTime);
|
||||||
|
log.vdebug("releaseGracePeriod: ", releaseGracePeriod);
|
||||||
|
|
||||||
|
// display details if not current
|
||||||
if (applicationVersion != latestVersion) {
|
if (applicationVersion != latestVersion) {
|
||||||
// is application version is older than available on GitHub
|
// is application version is older than available on GitHub
|
||||||
|
// what warning do we present?
|
||||||
if (applicationVersion < latestVersion) {
|
if (applicationVersion < latestVersion) {
|
||||||
// application version is obsolete and unsupported
|
// if releaseGracePeriod > currentTime
|
||||||
writeln();
|
// display an information warning that there is a new release available
|
||||||
log.logAndNotify("WARNING: Your onedrive client version is obsolete and unsupported. Please upgrade your client version.");
|
if (releaseGracePeriod.toUnixTime() > currentTime.toUnixTime()) {
|
||||||
log.vlog("Application version: ", applicationVersion);
|
writeln();
|
||||||
log.vlog("Version available: ", latestVersion);
|
log.logAndNotify("INFO: A new onedrive client version is available. Please upgrade your client version when possible.");
|
||||||
writeln();
|
log.log("Current Application Version: ", applicationVersion);
|
||||||
|
log.log("Version Available: ", latestVersion);
|
||||||
|
writeln();
|
||||||
|
} else {
|
||||||
|
// outside grace period
|
||||||
|
// application version is obsolete and unsupported
|
||||||
|
writeln();
|
||||||
|
log.logAndNotify("WARNING: Your onedrive client version is now obsolete and unsupported. Please upgrade your client version.");
|
||||||
|
log.log("Current Application Version: ", applicationVersion);
|
||||||
|
log.log("Version Available: ", latestVersion);
|
||||||
|
writeln();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue