diff --git a/LATEST_VERSION b/LATEST_VERSION new file mode 100644 index 0000000..a1fa19c --- /dev/null +++ b/LATEST_VERSION @@ -0,0 +1 @@ +1.0.053125+2326 \ No newline at end of file diff --git a/lib/Consts.dart b/lib/Consts.dart index a72bde2..e3803da 100644 --- a/lib/Consts.dart +++ b/lib/Consts.dart @@ -1,5 +1,5 @@ class Constants { - static const VERSION = "1.0.052825+1401"; + static const VERSION = "1.0.053125+2326"; //static bool get isMobile => Platform.isAndroid || Platform.isIOS; } diff --git a/lib/MainApp.dart b/lib/MainApp.dart index 119bf93..017e7dc 100644 --- a/lib/MainApp.dart +++ b/lib/MainApp.dart @@ -1,7 +1,10 @@ +import 'dart:io'; + import 'package:flutter/material.dart'; import 'package:libacflutter/Constants.dart'; import 'package:pokedex/Consts.dart'; import 'package:pokedex/Session.dart'; +import 'package:pokedex/UpdateCheck.dart'; import 'package:pokedex/filters.dart'; import 'package:pokedex/pokemon.dart'; import 'package:pokedex/pokemonHelpers.dart'; @@ -29,6 +32,7 @@ class _MainAppState extends State { "/": (context) => Home(toggleTheme: toggleTheme), "/dex": (context) => DexEntry(), "/filters": (context) => FilterPage(), + "/update": (context) => UpdateCheck(), }, ); } @@ -90,6 +94,16 @@ class _HomeState extends State { setState(() {}); }, ), + if (Platform.isIOS || Platform.isAndroid) + ListTile( + title: Text("U P D A T E"), + subtitle: Text("Opens the update checker"), + leading: Icon(Icons.update), + onTap: () async { + await Navigator.pushNamed(context, "/update"); + setState(() {}); + }, + ), ], ), ), diff --git a/lib/Session.dart b/lib/Session.dart index 31cb5f2..d09665f 100644 --- a/lib/Session.dart +++ b/lib/Session.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:pokedex/pokemon.dart'; class SessionData { + static bool isUpdateAvailable = false; static bool enableDescription = true; static bool darkMode = false; static int highest = 9; diff --git a/lib/UpdateCheck.dart b/lib/UpdateCheck.dart new file mode 100644 index 0000000..f370f84 --- /dev/null +++ b/lib/UpdateCheck.dart @@ -0,0 +1,97 @@ +import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:libacflutter/Constants.dart'; +import 'package:ota_update/ota_update.dart'; +import 'package:pokedex/Consts.dart'; +import 'package:pokedex/Session.dart'; + +class UpdateCheck extends StatefulWidget { + @override + State createState() { + return _UPDCheck(); + } +} + +class _UPDCheck extends State { + Future checkUpdate() async { + Dio dio = Dio(); + // retrieve the latest version info file. + var reply = await dio.get( + "https://git.zontreck.com/zontreck/PokeDex/raw/branch/main/LATEST_VERSION", + ); + String replyStr = reply.data as String; + replyStr = replyStr.trim(); + + // Check if version mismatch! + if (replyStr != Constants.VERSION) { + SessionData.isUpdateAvailable = true; + } else { + SessionData.isUpdateAvailable = false; + } + } + + @override + void initState() { + // Check for updates + checkUpdate(); + + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text("PokeDex - Update Checker"), + backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR, + ), + body: Padding( + padding: EdgeInsetsGeometry.all(8), + child: SingleChildScrollView( + child: Column( + children: [ + ListTile( + title: Text("Check for updates..."), + subtitle: Text("Checks for an update immediately."), + leading: Icon(Icons.update_outlined), + onTap: () async { + await checkUpdate(); + setState(() {}); + }, + ), + + if (SessionData.isUpdateAvailable) + ListTile( + title: Text("Install Update"), + subtitle: Text("Download and install the available update"), + leading: Icon(Icons.system_update), + onTap: () async { + // Do the update! + + SessionData.isUpdateAvailable = false; + setState(() {}); + + OtaUpdate updater = OtaUpdate(); + updater.execute( + "https://ci.zontreck.com/job/Projects/job/Dart/job/PokeDex/job/main/lastSuccessfulBuild/artifact/pokedex.apk", + destinationFilename: "pokedex.apk", + ); + }, + ), + if (!SessionData.isUpdateAvailable) + ListTile( + title: Text("No Available Update"), + subtitle: Text( + "There is not a update available at this time.", + ), + leading: Icon(Icons.disabled_by_default), + tileColor: LibACFlutterConstants.TITLEBAR_COLOR, + ), + ], + ), + ), + ), + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 330f3ca..3e291dc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.052825+1401 +version: 1.0.053125+2326 environment: sdk: ^3.7.0 @@ -41,6 +41,7 @@ dependencies: hosted: https://git.zontreck.com/api/packages/Packages/pub/ version: ^1.0.052725+1354 ota_update: ^7.0.1 + dio: ^5.8.0+1 dev_dependencies: flutter_test: