Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 4ee8e80

Browse files
committed
check for updates
1 parent 9cc9d5b commit 4ee8e80

5 files changed

Lines changed: 54 additions & 15 deletions

File tree

lib/helpers.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:catcher/model/platform_type.dart';
88
import 'package:flutter/foundation.dart';
99
import 'package:flutter/widgets.dart';
1010
import 'package:flutter_riverpod/flutter_riverpod.dart';
11+
import 'package:http/http.dart';
1112
import 'package:lb_planner/routes.dart';
1213
import 'package:lb_planner/widgets.dart';
1314
import 'package:lbplanner_engine/lbplanner_engine.dart';

lib/helpers/updater.dart

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class UpdateProvider extends ChangeNotifier {
2525
String get latestVersionName => kUpdater.latestVersionName;
2626

2727
/// The name of the current version
28-
String get versionName => "Closed Beta v${kUpdater.currentVersion}";
28+
String get versionName => "Open Beta v${kUpdater.currentVersion}";
2929

3030
/// The status of the update.
3131
UpdateStatus get status => _status;
@@ -140,41 +140,79 @@ class Updater extends GitHubUpdater {
140140
String get appName => "LB Planner";
141141

142142
@override
143-
String get currentVersion => "0.0.1";
143+
String get currentVersion => "0.0.2";
144144

145145
@override
146-
String get linuxFileName => throw UnimplementedError("Linux is not supported yet");
146+
String get linuxFileName => "LB.Planner.AppImage";
147147

148148
@override
149-
String get macFileName => throw UnimplementedError("Mac is not supported yet");
149+
String get macFileName => "LB.Planner.Setup.dmg";
150150

151151
@override
152152
String get repo => "lb_planner";
153153

154154
@override
155-
String get repoOwner => "necodeIT";
155+
String get repoOwner => "bmceachnie";
156156

157157
@override
158-
String get windowsFileName => "Setup.exe";
158+
String get windowsFileName => "LB.Planner.Setup.exe";
159+
160+
String _latestVersion = "";
161+
String _latestReleaseName = "";
162+
bool _updateAvailable = false;
163+
164+
@override
165+
String get latestVersion => _latestVersion;
166+
167+
@override
168+
String get latestVersionName => _latestReleaseName;
159169

160170
@override
161-
bool get updateAvailable => false;
171+
bool get updateAvailable => _updateAvailable;
162172

163173
@override
164174
Future<bool> update() async {
165-
return true;
166175
if (gPluginVersion == null) {
167176
log("Failed checking for updates because plugin version is unkown!", LogTypes.error);
168177
return false;
169178
}
170179

171-
var gh = await super.update();
180+
log("Checking for updates...", LogTypes.tracking);
181+
182+
if (!await connectivity.checkConnection()) {
183+
error("Could not check for updates, you may be using an outadet version! Please check your internet connection");
184+
log("Failed checking for updates: Missing internet connection", LogTypes.error);
185+
return false;
186+
}
187+
188+
var client = Client();
172189

173-
if (!gh) return false;
190+
try {
191+
var response = await client.get(Uri.parse("$repoUrl/releases"));
192+
var json = jsonDecode(response.body);
174193

175-
var l = Version.fromString(latestVersion);
194+
for (var release in json) {
195+
if (release["prerelease"] == true) continue;
196+
if (release["target_commitish"] != "app") continue;
176197

177-
return gPluginVersion!.majorVersion >= l.majorVersion;
198+
_latestVersion = release["tag_name"].toString().replaceAll("f", "");
199+
_latestReleaseName = release["name"];
200+
201+
break;
202+
}
203+
204+
var l = Version.fromString(latestVersion);
205+
206+
_updateAvailable = gPluginVersion!.majorVersion >= l.majorVersion && latestVersion != currentVersion;
207+
208+
log(updateAvailable ? "New update available" : "No update available", LogTypes.success);
209+
210+
return updateAvailable;
211+
} catch (e) {
212+
log("Failed checking for updates: $e", LogTypes.error);
213+
214+
return false;
215+
}
178216
}
179217
}
180218

lib/routes/update/update.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class _UpdateRouteState extends State<UpdateRoute> {
7474
onPressed: () {
7575
var userTheme = NcThemes.current.name == sakuraTheme.name ? "sakura" : NcThemes.current.name.toLowerCase();
7676

77-
var urlToLaunch = 'https://projekte.tgm.ac.at/lb-planner/docs/?theme=$userTheme&section=0&heading=2';
77+
var urlToLaunch = 'https://projekte.tgm.ac.at/lb-planner?theme=$userTheme';
7878

7979
launchUrl(Uri.parse(urlToLaunch));
8080
},

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ packages:
479479
source: hosted
480480
version: "0.15.1"
481481
http:
482-
dependency: transitive
482+
dependency: "direct main"
483483
description:
484484
name: http
485485
url: "https://pub.dartlang.org"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ dependencies:
4848
flutter_sticky_header: ^0.6.1
4949
flutter_vector_icons: ^1.0.0
5050
font_awesome_flutter: ^10.1.0
51+
http: ^0.13.5
5152
intl: ^0.17.0
5253
lbplanner_engine:
5354
git:
@@ -84,7 +85,6 @@ dependency_overrides:
8485
# uncomment to test
8586
# nekolib_ui:
8687
# path: ../nekolib/ui
87-
8888
# For information on the generic Dart part of this file, see the
8989
# following page: https://dart.dev/tools/pub/pubspec
9090
# The following section is specific to Flutter.

0 commit comments

Comments
 (0)