[client] Updater update
This commit is contained in:
@@ -1,7 +1,27 @@
|
||||
package ru.m;
|
||||
|
||||
@:enum abstract Platform(String) from String to String {
|
||||
var ANDROID = "android";
|
||||
var LINUX = "linux";
|
||||
var WINDOWS = "windows";
|
||||
}
|
||||
|
||||
class Device {
|
||||
|
||||
public static var platform(get, null):Platform;
|
||||
|
||||
private static function get_platform():Platform {
|
||||
#if android
|
||||
return ANDROID;
|
||||
#elseif linux
|
||||
return LINUX;
|
||||
#elseif windows
|
||||
return WINDOWS;
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
|
||||
private static var MOBILES(default, never):Array<String> = [
|
||||
"Android", "webOS", "iPhone", "iPad", "iPod", "BlackBerry", "Windows Phone",
|
||||
];
|
||||
|
||||
@@ -4,9 +4,18 @@ import haxework.net.JsonLoader;
|
||||
import openfl.Lib;
|
||||
import openfl.net.URLRequest;
|
||||
import promhx.Promise;
|
||||
import ru.m.Device;
|
||||
|
||||
@:enum abstract PackageType(String) from String to String {
|
||||
var APK = "apk";
|
||||
var DEB = "deb";
|
||||
var EXE = "exe";
|
||||
var ARCHIVE = "archive";
|
||||
}
|
||||
|
||||
typedef PackageInfo = {
|
||||
var type:String;
|
||||
var platform:Platform;
|
||||
var type:PackageType;
|
||||
var path:String;
|
||||
var filename:String;
|
||||
var url:String;
|
||||
@@ -22,7 +31,7 @@ class Updater {
|
||||
|
||||
private static inline var TAG = "Update";
|
||||
|
||||
public var type(get, null):String;
|
||||
public var type(get, null):PackageType;
|
||||
public var bundle(default, null):PackagesBundle;
|
||||
|
||||
private var url:String;
|
||||
@@ -33,14 +42,13 @@ class Updater {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
private function get_type():String {
|
||||
#if android
|
||||
return "android";
|
||||
#elseif linux
|
||||
return "debian";
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
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> {
|
||||
@@ -53,14 +61,16 @@ class Updater {
|
||||
public function check():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle):Bool {
|
||||
this.bundle = bundle;
|
||||
return bundle.version != version && Lambda.exists(bundle.packages, function(item) return item.type == type);
|
||||
return bundle.version != version && Lambda.exists(bundle.packages, function(item) {
|
||||
return item.platform == Device.platform && item.type == type;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function download():Promise<Bool> {
|
||||
return resolveBundle().then(function(bundle:PackagesBundle) {
|
||||
for (item in bundle.packages) {
|
||||
if (item.type == type) {
|
||||
if (item.platform == Device.platform && item.type == type) {
|
||||
L.i(TAG, 'download: ${item.url}');
|
||||
Lib.getURL(new URLRequest(item.url));
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user