Skip to content

Commit 3c9abde

Browse files
committed
feat(Update Check): Automatically Check for updates and redirect
1 parent 8942678 commit 3c9abde

File tree

5 files changed

+79
-3
lines changed

5 files changed

+79
-3
lines changed

lib/pages/home_page.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'package:mujslcm/pages/marks.dart';
66
import 'package:mujslcm/pages/settings.dart';
77
import 'package:mujslcm/pages/timetable.dart';
88
import 'package:mujslcm/pages/cgpa.dart';
9+
import 'package:mujslcm/utils/checkupdates.dart';
910
import 'login.dart';
1011
import 'package:mujslcm/session_manager.dart';
1112
import 'package:flutter_svg/flutter_svg.dart';
@@ -35,6 +36,7 @@ class _HomePageState extends State<HomePage> {
3536
@override
3637
void initState() {
3738
super.initState();
39+
check_update(context);
3840
_pages = [
3941
Information(),
4042
HomeScreen(name: widget.name, newCookies: widget.newCookies),
@@ -64,7 +66,7 @@ class _HomePageState extends State<HomePage> {
6466
appBar: AppBar(
6567
backgroundColor: const Color(0xFF121316),
6668
title: const Text(
67-
"SLCM SWITCH",
69+
"MUJ SWITCH",
6870
style: TextStyle(
6971
color: Colors.white,
7072
fontFamily: "Roboto",

lib/pages/redirects.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ String otpIndexURL = loginURL + "/Home/IndexOTP";
1515
String HomeURL = loginURL + "/Home/Dashboard";
1616
String OnExpireURL = loginURL + "/Home/OnExpire";
1717
String ResendOTPUrl = loginURL + "/Home/ResendOTP";
18+
19+
// Check Updates
20+
21+
String repolink =
22+
"https://api.github.com/repos/DK10WS/SLCM_APP/releases/latest";

lib/utils/checkupdates.dart

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import "package:flutter/material.dart";
2+
import "package:mujslcm/pages/redirects.dart";
3+
import "package:package_info_plus/package_info_plus.dart";
4+
import 'package:url_launcher/url_launcher.dart';
5+
import "util.dart";
6+
7+
Future<String> getAppVersion() async {
8+
PackageInfo packageInfo = await PackageInfo.fromPlatform();
9+
return packageInfo.version;
10+
}
11+
12+
Future<void> _launchURL(String url) async {
13+
final uri = Uri.parse(url);
14+
if (await canLaunchUrl(uri)) {
15+
await launchUrl(uri, mode: LaunchMode.externalApplication);
16+
} else {
17+
throw 'Could not launch $url';
18+
}
19+
}
20+
21+
Future<Object?> check_update(context) async {
22+
final appversion = await getAppVersion();
23+
final response = await get(repolink, headers);
24+
if ("v$appversion" != response.data["tag_name"]) {
25+
return showDialog(
26+
context: context,
27+
builder: (BuildContext context) => Dialog(
28+
backgroundColor: const Color(0xFF232531),
29+
child: Padding(
30+
padding: const EdgeInsets.all(8),
31+
child: Column(
32+
mainAxisSize: MainAxisSize.min,
33+
mainAxisAlignment: MainAxisAlignment.center,
34+
children: <Widget>[
35+
const Padding(
36+
padding: EdgeInsets.all(8.0),
37+
child: Text(
38+
"New Update",
39+
style: TextStyle(color: Colors.white, fontSize: 20),
40+
),
41+
),
42+
const SizedBox(height: 10),
43+
Padding(
44+
padding: const EdgeInsets.all(8.0),
45+
child: Text(
46+
"Version ${response.data["tag_name"]} is out check out",
47+
style:
48+
const TextStyle(color: Colors.white, fontSize: 15),
49+
),
50+
),
51+
const SizedBox(height: 15),
52+
Align(
53+
alignment: Alignment.bottomRight,
54+
child: TextButton(
55+
onPressed: () {
56+
_launchURL(
57+
"https://github.com/DK10WS/SLCM_APP/releases/");
58+
},
59+
child: const Text('Download',
60+
style: TextStyle(
61+
color: Color(0xFFD5E7B5), fontSize: 15)),
62+
),
63+
)
64+
],
65+
),
66+
),
67+
));
68+
}
69+
return null;
70+
}

lib/utils/login.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:mujslcm/utils/util.dart';
22
import "package:mujslcm/pages/redirects.dart";
3-
import 'package:shared_preferences/shared_preferences.dart';
43
import 'package:html/parser.dart' show parse;
54

65
String extractSessionId(String cookie) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1616
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1717
# In Windows, build-name is used as the major, minor, and patch parts
1818
# of the product and file versions while build-number is used as the build suffix.
19-
version: 1.0.5+1
19+
version: 1.0.6+1
2020

2121
environment:
2222
sdk: ^3.5.4

0 commit comments

Comments
 (0)