Compare commits

...

6 Commits

8 changed files with 70 additions and 25 deletions

View File

@ -1,9 +1,11 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:obtainium/components/generated_form.dart';
import 'package:obtainium/custom_errors.dart';
import 'package:obtainium/providers/settings_provider.dart';
import 'package:obtainium/providers/source_provider.dart';
import 'package:url_launcher/url_launcher_string.dart';
class GitHub implements AppSource {
@override
@ -137,7 +139,7 @@ class GitHub implements AppSource {
@override
List<GeneratedFormItem> moreSourceSettingsFormItems = [
GeneratedFormItem(
label: 'GitHub Credentials (Increases Rate Limit)',
label: 'GitHub Personal Access Token (Increases Rate Limit)',
id: 'github-creds',
required: false,
additionalValidators: [
@ -153,6 +155,23 @@ class GitHub implements AppSource {
}
return null;
}
],
hint: 'username:token',
belowWidgets: [
const SizedBox(
height: 8,
),
GestureDetector(
onTap: () {
launchUrlString(
'https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token',
mode: LaunchMode.externalApplication);
},
child: const Text(
'About GitHub PATs',
style: TextStyle(
decoration: TextDecoration.underline, fontSize: 12),
))
])
];
}

View File

@ -11,6 +11,8 @@ class GeneratedFormItem {
late int max;
late List<String? Function(String? value)> additionalValidators;
late String id;
late List<Widget> belowWidgets;
late String? hint;
GeneratedFormItem(
{this.label = 'Input',
@ -18,7 +20,9 @@ class GeneratedFormItem {
this.required = true,
this.max = 1,
this.additionalValidators = const [],
this.id = 'input'});
this.id = 'input',
this.belowWidgets = const [],
this.hint});
}
class GeneratedForm extends StatefulWidget {
@ -91,7 +95,8 @@ class _GeneratedFormState extends State<GeneratedForm> {
});
},
decoration: InputDecoration(
helperText: e.value.label + (e.value.required ? ' *' : '')),
helperText: e.value.label + (e.value.required ? ' *' : ''),
hintText: e.value.hint),
minLines: e.value.max <= 1 ? null : e.value.max,
maxLines: e.value.max <= 1 ? 1 : e.value.max,
validator: (value) {
@ -157,7 +162,13 @@ class _GeneratedFormState extends State<GeneratedForm> {
width: 20,
));
}
rowItems.add(Expanded(child: rowInput.value));
rowItems.add(Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
rowInput.value,
...widget.items[rowInputs.key][rowInput.key].belowWidgets
])));
});
rows.add(rowItems);
});

View File

@ -14,7 +14,7 @@ import 'package:dynamic_color/dynamic_color.dart';
import 'package:device_info_plus/device_info_plus.dart';
const String currentReleaseTag =
'v0.5.0-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES
'v0.5.3-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES
const String bgUpdateCheckTaskName = 'bg-update-check';
@ -37,7 +37,6 @@ bgUpdateCheck(int? ignoreAfterMicroseconds) async {
await appsProvider.checkUpdates(ignoreAfter: ignoreAfter);
} catch (e) {
if (e is RateLimitError) {
// Ignore these (scheduling another task as below does not work)
String nextTaskName =
'$bgUpdateCheckTaskName-${nextIgnoreAfter.microsecondsSinceEpoch.toString()}';
Workmanager().registerOneOffTask(nextTaskName, nextTaskName,
@ -108,14 +107,21 @@ void main() async {
ChangeNotifierProvider(create: (context) => SettingsProvider()),
Provider(create: (context) => NotificationsProvider())
],
child: const MyApp(),
child: const Obtainium(),
));
}
var defaultThemeColour = Colors.deepPurple;
class MyApp extends StatelessWidget {
const MyApp({super.key});
class Obtainium extends StatefulWidget {
const Obtainium({super.key});
@override
State<Obtainium> createState() => _ObtainiumState();
}
class _ObtainiumState extends State<Obtainium> {
var existingUpdateInterval = -1;
@override
Widget build(BuildContext context) {
@ -144,18 +150,21 @@ class MyApp extends StatelessWidget {
]);
}
// Register the background update task according to the user's setting
if (settingsProvider.updateInterval == 0) {
Workmanager().cancelByUniqueName(bgUpdateCheckTaskName);
} else {
Workmanager().registerPeriodicTask(
bgUpdateCheckTaskName, bgUpdateCheckTaskName,
frequency: Duration(minutes: settingsProvider.updateInterval),
initialDelay: Duration(minutes: settingsProvider.updateInterval),
constraints: Constraints(networkType: NetworkType.connected),
existingWorkPolicy: ExistingWorkPolicy.keep,
backoffPolicy: BackoffPolicy.linear,
backoffPolicyDelay:
const Duration(minutes: minUpdateIntervalMinutes));
if (existingUpdateInterval != settingsProvider.updateInterval) {
existingUpdateInterval = settingsProvider.updateInterval;
if (existingUpdateInterval == 0) {
Workmanager().cancelByUniqueName(bgUpdateCheckTaskName);
} else {
Workmanager().registerPeriodicTask(
bgUpdateCheckTaskName, bgUpdateCheckTaskName,
frequency: Duration(minutes: existingUpdateInterval),
initialDelay: Duration(minutes: existingUpdateInterval),
constraints: Constraints(networkType: NetworkType.connected),
existingWorkPolicy: ExistingWorkPolicy.replace,
backoffPolicy: BackoffPolicy.linear,
backoffPolicyDelay:
const Duration(minutes: minUpdateIntervalMinutes));
}
}
}

View File

@ -293,6 +293,11 @@ class AppsProvider with ChangeNotifier {
}
await saveApps([newApp]);
return newApp;
} else if ((newApp.lastUpdateCheck?.microsecondsSinceEpoch ?? 0) -
(currentApp.lastUpdateCheck?.microsecondsSinceEpoch ?? 0) >
5000000) {
currentApp.lastUpdateCheck = newApp.lastUpdateCheck;
await saveApps([currentApp]);
}
return null;
}
@ -306,7 +311,7 @@ class AppsProvider with ChangeNotifier {
if (ignoreAfter != null) {
appIds = appIds
.where((id) =>
apps[id]!.app.lastUpdateCheck != null &&
apps[id]!.app.lastUpdateCheck == null ||
apps[id]!.app.lastUpdateCheck!.isBefore(ignoreAfter))
.toList();
}

View File

@ -129,5 +129,6 @@ class SettingsProvider with ChangeNotifier {
void setSettingString(String settingId, String value) {
prefs?.setString(settingId, value);
notifyListeners();
}
}

View File

@ -407,7 +407,7 @@ packages:
name: permission_handler_android
url: "https://pub.dartlang.org"
source: hosted
version: "10.0.0"
version: "10.1.0"
permission_handler_apple:
dependency: transitive
description:

View File

@ -17,7 +17,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: 0.5.0+21 # When changing this, update the tag in main() accordingly
version: 0.5.3+24 # When changing this, update the tag in main() accordingly
environment:
sdk: '>=2.19.0-79.0.dev <3.0.0'

View File

@ -13,7 +13,7 @@ import 'package:obtainium/main.dart';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpWidget(const Obtainium());
// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);