check update
Some checks failed
Flutter Release / get-version (push) Successful in 8s
Flutter Release / build-windows (push) Failing after 9s
Flutter Release / build-android (push) Failing after 1m12s
Flutter Release / create-release (push) Has been skipped

This commit is contained in:
2025-12-14 23:11:50 -05:00
parent e5fdbae3b2
commit 9ff0d62651
11 changed files with 970 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:window_manager/window_manager.dart';
import 'providers/price_provider.dart';
import 'providers/update_provider.dart';
import 'screens/home_screen.dart';
import 'services/notification_service.dart';
import 'widgets/loading_screen.dart';
@@ -61,8 +62,11 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => PriceProvider(),
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => PriceProvider()),
ChangeNotifierProvider(create: (_) => UpdateProvider()),
],
child: MaterialApp(
title: 'rmtPocketWatcher',
debugShowCheckedModeBanner: false,

View File

@@ -0,0 +1,95 @@
import 'package:flutter/foundation.dart';
import '../services/update_service.dart';
import '../services/storage_service.dart';
class UpdateProvider extends ChangeNotifier {
final UpdateService _updateService = UpdateService();
final StorageService _storageService = StorageService();
UpdateInfo? _availableUpdate;
bool _isChecking = false;
DateTime? _lastChecked;
bool _updateDismissed = false;
UpdateInfo? get availableUpdate => _availableUpdate;
bool get isChecking => _isChecking;
DateTime? get lastChecked => _lastChecked;
bool get hasUpdate => _availableUpdate != null && !_updateDismissed;
/// Check for updates manually
Future<void> checkForUpdates({bool force = false}) async {
if (_isChecking) return;
// Don't check too frequently unless forced
if (!force && _lastChecked != null) {
final timeSinceLastCheck = DateTime.now().difference(_lastChecked!);
if (timeSinceLastCheck.inHours < 1) {
if (kDebugMode) {
print('Skipping update check - last checked ${timeSinceLastCheck.inMinutes} minutes ago');
}
return;
}
}
_isChecking = true;
notifyListeners();
try {
final updateInfo = await _updateService.checkForUpdates();
_availableUpdate = updateInfo;
_lastChecked = DateTime.now();
_updateDismissed = false;
// Save last check time
await _storageService.setString('last_update_check', _lastChecked!.toIso8601String());
if (updateInfo != null) {
if (kDebugMode) {
print('Update available: ${updateInfo.latestVersion}');
}
// Check if this version was already dismissed
final dismissedVersion = await _storageService.getString('dismissed_update_version');
if (dismissedVersion == updateInfo.latestVersion) {
_updateDismissed = true;
}
}
} catch (e) {
if (kDebugMode) {
print('Error checking for updates: $e');
}
} finally {
_isChecking = false;
notifyListeners();
}
}
/// Dismiss the current update notification
Future<void> dismissUpdate() async {
if (_availableUpdate != null) {
_updateDismissed = true;
await _storageService.setString('dismissed_update_version', _availableUpdate!.latestVersion);
notifyListeners();
}
}
/// Initialize the provider and load saved state
Future<void> initialize() async {
// Load last check time
final lastCheckString = await _storageService.getString('last_update_check');
if (lastCheckString != null) {
_lastChecked = DateTime.tryParse(lastCheckString);
}
// Check for updates on startup (but don't force it)
await checkForUpdates();
}
/// Check for updates automatically in the background
void startPeriodicChecks() {
// Check every 4 hours
Stream.periodic(const Duration(hours: 4)).listen((_) {
checkForUpdates();
});
}
}

View File

@@ -2,13 +2,30 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/price_provider.dart';
import '../providers/update_provider.dart';
import '../widgets/price_chart.dart';
import '../widgets/alerts_panel.dart';
import '../widgets/vendor_table.dart';
import '../widgets/update_notification.dart';
class HomeScreen extends StatelessWidget {
class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});
@override
State<HomeScreen> createState() => _HomeScreenState();
}
class _HomeScreenState extends State<HomeScreen> {
@override
void initState() {
super.initState();
// Initialize update provider
WidgetsBinding.instance.addPostFrameCallback((_) {
context.read<UpdateProvider>().initialize();
context.read<UpdateProvider>().startPeriodicChecks();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -42,6 +59,33 @@ class HomeScreen extends StatelessWidget {
),
),
const SizedBox(width: 16),
// Update check button
Consumer<UpdateProvider>(
builder: (context, updateProvider, child) {
return IconButton(
icon: updateProvider.isChecking
? const SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Color(0xFF50E3C2),
),
)
: Icon(
updateProvider.hasUpdate ? Icons.system_update : Icons.refresh,
color: updateProvider.hasUpdate ? const Color(0xFF50E3C2) : Colors.white,
size: 16,
),
onPressed: updateProvider.isChecking
? null
: () => updateProvider.checkForUpdates(force: true),
tooltip: updateProvider.hasUpdate
? 'Update available'
: 'Check for updates',
);
},
),
IconButton(
icon: const Icon(Icons.minimize, color: Colors.white, size: 16),
onPressed: () {
@@ -64,6 +108,8 @@ class HomeScreen extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Update notification banner
const UpdateNotificationBanner(),
// Top stats row - Bloomberg style
Consumer<PriceProvider>(
builder: (context, provider, child) {

View File

@@ -51,4 +51,15 @@ class StorageService {
final prefs = await SharedPreferences.getInstance();
await prefs.setDouble(_customAuecKey, amount);
}
// Generic string storage methods for update checking
Future<String?> getString(String key) async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString(key);
}
Future<void> setString(String key, String value) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(key, value);
}
}

View File

@@ -0,0 +1,255 @@
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:package_info_plus/package_info_plus.dart';
import 'package:xml/xml.dart';
class UpdateService {
static const String _releasesRssUrl = 'https://git.hudsonriggs.systems/LambdaBankingConglomerate/rmtPocketWatcher/releases.rss';
/// Check if an update is available by comparing current version with latest release
Future<UpdateInfo?> checkForUpdates() async {
try {
// Get current app version
final packageInfo = await PackageInfo.fromPlatform();
final currentVersion = packageInfo.version;
if (kDebugMode) {
print('Current app version: $currentVersion');
print('Checking for updates at: $_releasesRssUrl');
}
// Fetch latest release from Gitea RSS feed
final response = await http.get(
Uri.parse(_releasesRssUrl),
headers: {
'Accept': 'application/rss+xml, application/xml, text/xml',
'User-Agent': 'rmtPocketWatcher/$currentVersion',
},
);
if (response.statusCode == 200) {
final document = XmlDocument.parse(response.body);
final items = document.findAllElements('item');
if (items.isEmpty) {
if (kDebugMode) {
print('No releases found in RSS feed');
}
return null;
}
// Get the latest release (first item in RSS feed)
final latestItem = items.first;
final title = latestItem.findElements('title').first.innerText;
final link = latestItem.findElements('link').first.innerText;
final description = latestItem.findElements('description').firstOrNull?.innerText ?? '';
final pubDate = latestItem.findElements('pubDate').first.innerText;
// Extract version from title (assuming format like "v1.2.3" or "Release v1.2.3")
final versionMatch = RegExp(r'v?(\d+\.\d+\.\d+)').firstMatch(title);
if (versionMatch == null) {
if (kDebugMode) {
print('Could not extract version from title: $title');
}
return null;
}
final latestVersion = versionMatch.group(1)!;
if (kDebugMode) {
print('Latest release version: $latestVersion');
print('Release title: $title');
}
// Compare versions
if (isNewerVersion(latestVersion, currentVersion)) {
return UpdateInfo(
currentVersion: currentVersion,
latestVersion: latestVersion,
releaseUrl: link,
releaseName: title,
releaseNotes: description,
publishedAt: _parseRssDate(pubDate),
assets: _generateAssetUrls(latestVersion), // Generate expected asset URLs
);
} else {
if (kDebugMode) {
print('App is up to date');
}
return null;
}
} else {
if (kDebugMode) {
print('Failed to fetch RSS feed: ${response.statusCode}');
print('Response: ${response.body}');
}
return null;
}
} catch (e) {
if (kDebugMode) {
print('Error checking for updates: $e');
}
return null;
}
}
/// Extract version number from git tag (e.g., "v1.2.3" -> "1.2.3")
@visibleForTesting
String extractVersionFromTag(String tag) {
return tag.startsWith('v') ? tag.substring(1) : tag;
}
/// Compare two version strings (e.g., "1.2.3" vs "1.2.2")
@visibleForTesting
bool isNewerVersion(String latest, String current) {
final latestParts = latest.split('.').map(int.parse).toList();
final currentParts = current.split('.').map(int.parse).toList();
// Ensure both have same number of parts
while (latestParts.length < currentParts.length) {
latestParts.add(0);
}
while (currentParts.length < latestParts.length) {
currentParts.add(0);
}
for (int i = 0; i < latestParts.length; i++) {
if (latestParts[i] > currentParts[i]) {
return true;
} else if (latestParts[i] < currentParts[i]) {
return false;
}
}
return false; // Versions are equal
}
/// Parse RSS date format to DateTime
DateTime _parseRssDate(String rssDate) {
try {
// RSS dates are typically in RFC 2822 format
// Example: "Mon, 02 Jan 2006 15:04:05 MST"
return DateTime.parse(rssDate);
} catch (e) {
if (kDebugMode) {
print('Failed to parse RSS date: $rssDate, error: $e');
}
return DateTime.now();
}
}
/// Generate expected asset URLs based on version and platform
List<ReleaseAsset> _generateAssetUrls(String version) {
final baseUrl = 'https://git.hudsonriggs.systems/LambdaBankingConglomerate/rmtPocketWatcher/releases/download/v$version';
return [
ReleaseAsset(
name: 'rmtPocketWatcher-windows-x64.exe',
downloadUrl: '$baseUrl/rmtPocketWatcher-windows-x64.exe',
size: 0, // Unknown size from RSS
contentType: 'application/octet-stream',
),
ReleaseAsset(
name: 'rmtPocketWatcher-windows-x64.msi',
downloadUrl: '$baseUrl/rmtPocketWatcher-windows-x64.msi',
size: 0,
contentType: 'application/octet-stream',
),
ReleaseAsset(
name: 'rmtPocketWatcher-macos.dmg',
downloadUrl: '$baseUrl/rmtPocketWatcher-macos.dmg',
size: 0,
contentType: 'application/octet-stream',
),
ReleaseAsset(
name: 'rmtPocketWatcher-linux.appimage',
downloadUrl: '$baseUrl/rmtPocketWatcher-linux.appimage',
size: 0,
contentType: 'application/octet-stream',
),
ReleaseAsset(
name: 'rmtPocketWatcher-android.apk',
downloadUrl: '$baseUrl/rmtPocketWatcher-android.apk',
size: 0,
contentType: 'application/vnd.android.package-archive',
),
];
}
}
class UpdateInfo {
final String currentVersion;
final String latestVersion;
final String releaseUrl;
final String releaseName;
final String releaseNotes;
final DateTime publishedAt;
final List<ReleaseAsset> assets;
UpdateInfo({
required this.currentVersion,
required this.latestVersion,
required this.releaseUrl,
required this.releaseName,
required this.releaseNotes,
required this.publishedAt,
required this.assets,
});
/// Get the appropriate download asset for the current platform
ReleaseAsset? getAssetForCurrentPlatform() {
if (kIsWeb) return null;
String platformPattern;
switch (defaultTargetPlatform) {
case TargetPlatform.windows:
platformPattern = r'windows|win|\.exe$|\.msi$';
break;
case TargetPlatform.macOS:
platformPattern = r'macos|mac|darwin|\.dmg$|\.pkg$';
break;
case TargetPlatform.linux:
platformPattern = r'linux|\.deb$|\.rpm$|\.appimage$';
break;
case TargetPlatform.android:
platformPattern = r'android|\.apk$';
break;
case TargetPlatform.iOS:
platformPattern = r'ios|\.ipa$';
break;
default:
return null;
}
final regex = RegExp(platformPattern, caseSensitive: false);
for (final asset in assets) {
if (regex.hasMatch(asset.name)) {
return asset;
}
}
return null;
}
}
class ReleaseAsset {
final String name;
final String downloadUrl;
final int size;
final String contentType;
ReleaseAsset({
required this.name,
required this.downloadUrl,
required this.size,
required this.contentType,
});
String get formattedSize {
if (size < 1024) return '${size}B';
if (size < 1024 * 1024) return '${(size / 1024).toStringAsFixed(1)}KB';
if (size < 1024 * 1024 * 1024) return '${(size / (1024 * 1024)).toStringAsFixed(1)}MB';
return '${(size / (1024 * 1024 * 1024)).toStringAsFixed(1)}GB';
}
}

View File

@@ -0,0 +1,308 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import '../providers/update_provider.dart';
import '../services/update_service.dart';
class UpdateNotificationBanner extends StatelessWidget {
const UpdateNotificationBanner({super.key});
@override
Widget build(BuildContext context) {
return Consumer<UpdateProvider>(
builder: (context, updateProvider, child) {
if (!updateProvider.hasUpdate) {
return const SizedBox.shrink();
}
final update = updateProvider.availableUpdate!;
return Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
margin: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: const Color(0xFF1A4B3A), // Dark green background
border: Border.all(color: const Color(0xFF50E3C2), width: 1),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
const Icon(
Icons.system_update,
color: Color(0xFF50E3C2),
size: 20,
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Update Available: v${update.latestVersion}',
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 14,
),
),
Text(
'Current: v${update.currentVersion}',
style: const TextStyle(
color: Colors.white70,
fontSize: 12,
),
),
],
),
),
TextButton(
onPressed: () => _showUpdateDialog(context, update),
style: TextButton.styleFrom(
foregroundColor: const Color(0xFF50E3C2),
),
child: const Text('View'),
),
IconButton(
onPressed: () => updateProvider.dismissUpdate(),
icon: const Icon(Icons.close, color: Colors.white70, size: 18),
tooltip: 'Dismiss',
),
],
),
);
},
);
}
void _showUpdateDialog(BuildContext context, UpdateInfo update) {
showDialog(
context: context,
builder: (context) => UpdateDialog(update: update),
);
}
}
class UpdateDialog extends StatelessWidget {
final UpdateInfo update;
const UpdateDialog({super.key, required this.update});
@override
Widget build(BuildContext context) {
final asset = update.getAssetForCurrentPlatform();
return AlertDialog(
backgroundColor: const Color(0xFF1A1F3A),
title: Row(
children: [
const Icon(Icons.system_update, color: Color(0xFF50E3C2)),
const SizedBox(width: 8),
Text(
'Update Available',
style: const TextStyle(color: Colors.white),
),
],
),
content: SizedBox(
width: 500,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildVersionInfo(),
const SizedBox(height: 16),
_buildReleaseInfo(),
if (update.releaseNotes.isNotEmpty) ...[
const SizedBox(height: 16),
_buildReleaseNotes(),
],
if (asset != null) ...[
const SizedBox(height: 16),
_buildDownloadInfo(asset),
],
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Later', style: TextStyle(color: Colors.white70)),
),
if (asset != null)
ElevatedButton(
onPressed: () => _downloadUpdate(asset.downloadUrl),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF50E3C2),
foregroundColor: Colors.black,
),
child: const Text('Download'),
),
ElevatedButton(
onPressed: () => _openReleasePage(update.releaseUrl),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF50E3C2),
foregroundColor: Colors.black,
),
child: const Text('View Release'),
),
],
);
}
Widget _buildVersionInfo() {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFF0A0E27),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFF50E3C2).withValues(alpha: 0.3)),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Current Version',
style: TextStyle(color: Colors.white70, fontSize: 12),
),
Text(
'v${update.currentVersion}',
style: const TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold),
),
],
),
const Icon(Icons.arrow_forward, color: Color(0xFF50E3C2)),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
const Text(
'Latest Version',
style: TextStyle(color: Colors.white70, fontSize: 12),
),
Text(
'v${update.latestVersion}',
style: const TextStyle(color: Color(0xFF50E3C2), fontSize: 16, fontWeight: FontWeight.bold),
),
],
),
],
),
);
}
Widget _buildReleaseInfo() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
update.releaseName,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
Text(
'Released ${_formatDate(update.publishedAt)}',
style: const TextStyle(color: Colors.white70, fontSize: 12),
),
],
);
}
Widget _buildReleaseNotes() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Release Notes',
style: TextStyle(
color: Colors.white,
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFF0A0E27),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFF50E3C2).withValues(alpha: 0.3)),
),
child: Text(
update.releaseNotes,
style: const TextStyle(color: Colors.white70, fontSize: 12),
maxLines: 8,
overflow: TextOverflow.ellipsis,
),
),
],
);
}
Widget _buildDownloadInfo(ReleaseAsset asset) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFF0A0E27),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFF50E3C2).withValues(alpha: 0.3)),
),
child: Row(
children: [
const Icon(Icons.download, color: Color(0xFF50E3C2), size: 20),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
asset.name,
style: const TextStyle(color: Colors.white, fontSize: 14),
),
Text(
asset.formattedSize,
style: const TextStyle(color: Colors.white70, fontSize: 12),
),
],
),
),
],
),
);
}
String _formatDate(DateTime date) {
final now = DateTime.now();
final difference = now.difference(date);
if (difference.inDays > 0) {
return '${difference.inDays} day${difference.inDays == 1 ? '' : 's'} ago';
} else if (difference.inHours > 0) {
return '${difference.inHours} hour${difference.inHours == 1 ? '' : 's'} ago';
} else {
return '${difference.inMinutes} minute${difference.inMinutes == 1 ? '' : 's'} ago';
}
}
void _downloadUpdate(String downloadUrl) async {
final uri = Uri.parse(downloadUrl);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
}
}
void _openReleasePage(String releaseUrl) async {
final uri = Uri.parse(releaseUrl);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
}
}
}