-
Notifications
You must be signed in to change notification settings - Fork 41
/
update_sync.dart
73 lines (60 loc) · 1.97 KB
/
update_sync.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This source code is a part of Project Violet.
// Copyright (C) 2020-2023. violet-team. Licensed under the Apache-2.0 License.
import 'dart:convert';
import 'package:violet/log/log.dart';
import 'package:violet/network/wrapper.dart' as http;
class UpdateSyncManager {
static const String updateInfoURL =
'https://raw.githubusercontent.com/project-violet/violet-app/master/version.json';
static bool enableSensitiveUpdate = true;
// Current version
static const int majorVersion = 1;
static const int minorVersion = 29;
static const int patchVersion = 1;
static String get currentVersion =>
'$majorVersion.$minorVersion.$patchVersion';
static bool updateRequire = false;
static String latestVersion = '';
static String version = '';
static String updateMessage = '';
static String updateUrl = '';
static bool _checkIsNewVersion(List<int> ver) {
//
// Check Major Version Number
//
if (majorVersion < ver[0]) return true;
//
// Check Minor Version Number
//
if (majorVersion == ver[0] && minorVersion < ver[1]) return true;
//
// Check Patch Version Number
//
if (majorVersion == ver[0] &&
minorVersion == ver[1] &&
patchVersion < ver[2] &&
enableSensitiveUpdate) return true;
return false;
}
static Future<void> checkUpdateSync() async {
try {
var infoJson = await http.get(updateInfoURL);
var info = jsonDecode(infoJson.body).cast<String, dynamic>();
var ver = (info['version'] as String)
.split('.')
.map((e) => int.parse(e))
.toList();
if (_checkIsNewVersion(ver)) {
updateRequire = true;
version = info['version'] as String;
updateMessage = info['message'] as String;
updateUrl = info['download_link'] as String;
print(info);
}
latestVersion = info['version'] as String;
} catch (e, st) {
Logger.error('[Update-check] E: $e\n'
'$st');
}
}
}