Move the update stuff to its own page

This commit is contained in:
zontreck 2025-05-14 20:54:17 -07:00
parent fcf5348f96
commit 4504708df8
6 changed files with 106 additions and 41 deletions

View file

@ -1,3 +1,3 @@
{
"alpha": "1.0.0-dev.2"
"alpha": "1.0.0-dev.4"
}

View file

@ -5,7 +5,7 @@ import 'package:dio/dio.dart';
class TTConsts {
static const UPDATE_URL =
"https://git.zontreck.com/AriasCreations/TimeTracker/raw/branch/main/latest-releases.json";
static const VERSION = "1.0.0-dev.3";
static const VERSION = "1.0.0-dev.4";
static bool UPDATE_AVAILABLE = false;
static UpdateChannel UPDATE_CHANNEL = UpdateChannel.alpha;

View file

@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:libacflutter/Constants.dart';
import 'package:ota_update/ota_update.dart';
import 'package:timetrack/consts.dart';
class HomePage extends StatefulWidget {
@ -37,47 +36,20 @@ class _HomePageState extends State<HomePage> {
Text("Time Tracker"),
Text("Created by Tara Piccari"),
Text("Copyright 2025 - Present"),
],
),
),
DrawerHeader(
child: Column(
children: [
Text("Version: ${TTConsts.VERSION}"),
Text("Update Channel: ${TTConsts.UPDATE_CHANNEL}"),
Text(
"* ${TTConsts.UPDATE_AVAILABLE ? "Update Is Available" : "You are up to date!"} *",
),
],
),
),
DrawerHeader(
child: Column(
children: [
ElevatedButton(
onPressed: () async {
await TTConsts.checkUpdate();
setState(() {});
},
child: Text("Check for Update"),
),
if (TTConsts.UPDATE_AVAILABLE)
ElevatedButton(
onPressed: () async {
OtaUpdate()
.execute(
"https://ci.zontreck.com/job/Projects/job/Dart/job/Time%20Tracker/job/main/lastSuccessfulBuild/artifact/build/app/outputs/flutter-apk/timetrack.apk",
destinationFilename: "timetrack.apk",
)
.listen((OtaEvent event) {
//setState(() => currentEvent = event);
});
},
child: Text("Install Update"),
),
],
ListTile(
title: Text("Update Settings.."),
subtitle: Text(
"Open the update settings. Channel, check for updates, and installation",
),
onTap: () async {
await Navigator.pushNamed(context, "/upd");
setState(() {});
},
leading: Icon(Icons.update),
),
],
),

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:timetrack/pages/HomePage.dart';
import 'package:timetrack/pages/UpdateSettings.dart';
class MainApp extends StatefulWidget {
const MainApp({super.key});
@ -20,7 +21,7 @@ class MainAppState extends State<MainApp> {
Widget build(BuildContext context) {
return MaterialApp(
title: "Time Tracker",
routes: {"/": (ctx) => HomePage()},
routes: {"/": (ctx) => HomePage(), "/upd": (ctx) => UpdateSettingsPage()},
theme: ThemeData.dark(),
);
}

View file

@ -0,0 +1,92 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:libacflutter/Constants.dart';
import 'package:ota_update/ota_update.dart';
import 'package:timetrack/consts.dart';
class UpdateSettingsPage extends StatefulWidget {
const UpdateSettingsPage({super.key});
@override
State<StatefulWidget> createState() {
return _UpdSet();
}
}
class _UpdSet extends State<UpdateSettingsPage> {
@override
void didChangeDependencies() {
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Time Tracker > Update Settings"),
backgroundColor: LibACFlutterConstants.TITLEBAR_COLOR,
),
body: SingleChildScrollView(
child: Column(
children: [
Text(
"Here, you can check for updates, and adjust various settings, such as the update channel",
style: TextStyle(fontSize: 24),
),
ListTile(
title: Text("Update Channel"),
leading: Icon(Icons.wifi_channel),
subtitle: Text("Current Channel: ${TTConsts.UPDATE_CHANNEL}"),
trailing: DropdownMenu(
dropdownMenuEntries: [
DropdownMenuEntry(value: UpdateChannel.alpha, label: "Alpha"),
DropdownMenuEntry(value: UpdateChannel.beta, label: "Beta"),
DropdownMenuEntry(
value: UpdateChannel.stable,
label: "Stable",
),
],
initialSelection: TTConsts.UPDATE_CHANNEL,
onSelected: (value) {
setState(() {
TTConsts.UPDATE_CHANNEL = value!;
});
},
),
),
ListTile(
title: Text("Check for updates.."),
leading: Icon(Icons.refresh),
subtitle: Text(
"Check for a update on the preferred update channel",
),
onTap: () async {
await TTConsts.checkUpdate();
setState(() {});
},
),
if (TTConsts.UPDATE_AVAILABLE)
ListTile(
title: Text("Install Update"),
leading: Icon(Icons.update),
subtitle: Text(
"Downloads and prompts you for installation of the update",
),
onTap: () {
OtaUpdate()
.execute(
"https://ci.zontreck.com/job/Projects/job/Dart/job/Time%20Tracker/job/main/lastSuccessfulBuild/artifact/build/app/outputs/flutter-apk/timetrack.apk",
destinationFilename: "timetrack.apk",
)
.listen((OtaEvent event) {
//setState(() => currentEvent = event);
});
},
),
],
),
),
);
}
}

View file

@ -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.0-dev.2
version: 1.0.0-dev.4
environment:
sdk: ^3.7.2