Add in a update checker
This commit is contained in:
parent
3d2226947c
commit
31c4b62c14
6 changed files with 116 additions and 2 deletions
1
LATEST_VERSION
Normal file
1
LATEST_VERSION
Normal file
|
@ -0,0 +1 @@
|
||||||
|
1.0.053125+2326
|
|
@ -1,5 +1,5 @@
|
||||||
class Constants {
|
class Constants {
|
||||||
static const VERSION = "1.0.052825+1401";
|
static const VERSION = "1.0.053125+2326";
|
||||||
|
|
||||||
//static bool get isMobile => Platform.isAndroid || Platform.isIOS;
|
//static bool get isMobile => Platform.isAndroid || Platform.isIOS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:libacflutter/Constants.dart';
|
import 'package:libacflutter/Constants.dart';
|
||||||
import 'package:pokedex/Consts.dart';
|
import 'package:pokedex/Consts.dart';
|
||||||
import 'package:pokedex/Session.dart';
|
import 'package:pokedex/Session.dart';
|
||||||
|
import 'package:pokedex/UpdateCheck.dart';
|
||||||
import 'package:pokedex/filters.dart';
|
import 'package:pokedex/filters.dart';
|
||||||
import 'package:pokedex/pokemon.dart';
|
import 'package:pokedex/pokemon.dart';
|
||||||
import 'package:pokedex/pokemonHelpers.dart';
|
import 'package:pokedex/pokemonHelpers.dart';
|
||||||
|
@ -29,6 +32,7 @@ class _MainAppState extends State<MainApp> {
|
||||||
"/": (context) => Home(toggleTheme: toggleTheme),
|
"/": (context) => Home(toggleTheme: toggleTheme),
|
||||||
"/dex": (context) => DexEntry(),
|
"/dex": (context) => DexEntry(),
|
||||||
"/filters": (context) => FilterPage(),
|
"/filters": (context) => FilterPage(),
|
||||||
|
"/update": (context) => UpdateCheck(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +94,16 @@ class _HomeState extends State<Home> {
|
||||||
setState(() {});
|
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(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:math';
|
||||||
import 'package:pokedex/pokemon.dart';
|
import 'package:pokedex/pokemon.dart';
|
||||||
|
|
||||||
class SessionData {
|
class SessionData {
|
||||||
|
static bool isUpdateAvailable = false;
|
||||||
static bool enableDescription = true;
|
static bool enableDescription = true;
|
||||||
static bool darkMode = false;
|
static bool darkMode = false;
|
||||||
static int highest = 9;
|
static int highest = 9;
|
||||||
|
|
97
lib/UpdateCheck.dart
Normal file
97
lib/UpdateCheck.dart
Normal file
|
@ -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<StatefulWidget> createState() {
|
||||||
|
return _UPDCheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _UPDCheck extends State<UpdateCheck> {
|
||||||
|
Future<void> 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,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
# 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
|
# 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.
|
# 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:
|
environment:
|
||||||
sdk: ^3.7.0
|
sdk: ^3.7.0
|
||||||
|
@ -41,6 +41,7 @@ dependencies:
|
||||||
hosted: https://git.zontreck.com/api/packages/Packages/pub/
|
hosted: https://git.zontreck.com/api/packages/Packages/pub/
|
||||||
version: ^1.0.052725+1354
|
version: ^1.0.052725+1354
|
||||||
ota_update: ^7.0.1
|
ota_update: ^7.0.1
|
||||||
|
dio: ^5.8.0+1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue