style: format code
This commit is contained in:
@@ -8,79 +8,76 @@ import ru.m.Device;
|
||||
import ru.m.update.Version;
|
||||
|
||||
@:enum abstract PackageType(String) from String to String {
|
||||
var APK = "apk";
|
||||
var DEB = "deb";
|
||||
var EXE = "exe";
|
||||
var ARCHIVE = "archive";
|
||||
var APK = "apk";
|
||||
var DEB = "deb";
|
||||
var EXE = "exe";
|
||||
var ARCHIVE = "archive";
|
||||
}
|
||||
|
||||
typedef PackageInfo = {
|
||||
var platform:Platform;
|
||||
var type:PackageType;
|
||||
var path:String;
|
||||
var filename:String;
|
||||
var url:String;
|
||||
var version:String;
|
||||
var platform:Platform;
|
||||
var type:PackageType;
|
||||
var path:String;
|
||||
var filename:String;
|
||||
var url:String;
|
||||
var version:String;
|
||||
}
|
||||
|
||||
typedef PackagesBundle = {
|
||||
var name:String;
|
||||
var version:String;
|
||||
var packages:Array<PackageInfo>;
|
||||
var name:String;
|
||||
var version:String;
|
||||
var packages:Array<PackageInfo>;
|
||||
}
|
||||
|
||||
class Updater {
|
||||
private static inline var TAG = "Update";
|
||||
|
||||
private static inline var TAG = "Update";
|
||||
public var type(get, null):PackageType;
|
||||
public var bundle(default, null):PackagesBundle;
|
||||
|
||||
public var type(get, null):PackageType;
|
||||
public var bundle(default, null):PackagesBundle;
|
||||
private var url:String;
|
||||
private var version:Version;
|
||||
|
||||
private var url:String;
|
||||
private var version:Version;
|
||||
public function new(version:String, url:String) {
|
||||
this.url = url;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public function new(version:String, url:String) {
|
||||
this.url = url;
|
||||
this.version = version;
|
||||
private function get_type():PackageType {
|
||||
return switch Device.platform {
|
||||
case ANDROID: APK;
|
||||
case LINUX: DEB;
|
||||
case WINDOWS: EXE;
|
||||
case _: null;
|
||||
}
|
||||
}
|
||||
|
||||
private function get_type():PackageType {
|
||||
return switch Device.platform {
|
||||
case ANDROID: APK;
|
||||
case LINUX: DEB;
|
||||
case WINDOWS: EXE;
|
||||
case _: null;
|
||||
private function resolveBundle():Promise<PackagesBundle> {
|
||||
return bundle != null ? Promise.promise(bundle) : new JsonLoader().GET(url).then(function(bundle) {
|
||||
this.bundle = bundle;
|
||||
return this.bundle;
|
||||
});
|
||||
}
|
||||
|
||||
public function check():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle):Bool {
|
||||
this.bundle = bundle;
|
||||
return Lambda.exists(bundle.packages,
|
||||
function(item) return (item.platform == Device.platform && item.type == type
|
||||
&& version < Version.fromString(item.version)));
|
||||
});
|
||||
}
|
||||
|
||||
public function download():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle) {
|
||||
for (item in bundle.packages) {
|
||||
if (item.platform == Device.platform && item.type == type) {
|
||||
L.i(TAG, 'download: ${item.url}');
|
||||
Lib.getURL(new URLRequest(item.url));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private function resolveBundle():Promise<PackagesBundle> {
|
||||
return bundle != null ? Promise.promise(bundle) : new JsonLoader().GET(url).then(function(bundle) {
|
||||
this.bundle = bundle;
|
||||
return this.bundle;
|
||||
});
|
||||
}
|
||||
|
||||
public function check():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle):Bool {
|
||||
this.bundle = bundle;
|
||||
return Lambda.exists(bundle.packages, function(item) return (
|
||||
item.platform == Device.platform &&
|
||||
item.type == type &&
|
||||
version < Version.fromString(item.version)
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
public function download():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle) {
|
||||
for (item in bundle.packages) {
|
||||
if (item.platform == Device.platform && item.type == type) {
|
||||
L.i(TAG, 'download: ${item.url}');
|
||||
Lib.getURL(new URLRequest(item.url));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user