Implement the automatic update check and installation
This commit is contained in:
parent
70d8fc4d39
commit
660a4a670a
10 changed files with 176 additions and 122 deletions
35
lib/consts.dart
Normal file
35
lib/consts.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
class TTConsts {
|
||||
static const UPDATE_URL =
|
||||
"https://git.zontreck.com/AriasCreations/TimeTracker/raw/branch/main/latest-releases.json";
|
||||
static const VERSION = "1.0.0-dev.2";
|
||||
static bool UPDATE_AVAILABLE = false;
|
||||
static UpdateChannel UPDATE_CHANNEL = UpdateChannel.alpha;
|
||||
|
||||
static Future<void> checkUpdate() async {
|
||||
Dio dio = Dio();
|
||||
var reply = await dio.get(UPDATE_URL);
|
||||
var jsData = json.decode(reply.data as String);
|
||||
|
||||
String serverVersion = jsData[UPDATE_CHANNEL.toString()] as String;
|
||||
if (VERSION == serverVersion) {
|
||||
// Up to date
|
||||
UPDATE_AVAILABLE = false;
|
||||
} else
|
||||
UPDATE_AVAILABLE = true;
|
||||
}
|
||||
}
|
||||
|
||||
enum UpdateChannel {
|
||||
alpha,
|
||||
beta,
|
||||
stable;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue