Skip to content

Commit

Permalink
Design improvement, downloader.dart fix, data mine notifier under test
Browse files Browse the repository at this point in the history
  • Loading branch information
Vonarian committed May 18, 2022
1 parent 9cea7e8 commit 01f0a47
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 67 deletions.
2 changes: 1 addition & 1 deletion assets/install/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.8.0
1.7.9.0
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Future<void> main() async {
await Window.hideWindowControls();
await Window.setEffect(
effect: WindowEffect.aero,
color: Colors.black.withOpacity(0.45),
color: Colors.black.withOpacity(0.55),
);
});
await protocolHandler.register('wtnews');
Expand All @@ -73,7 +73,7 @@ Future<void> main() async {
options.tracesSampleRate = 1.0;
options.enableAutoSessionTracking = true;
options.enableOutOfMemoryTracking = true;
options.reportPackages = false;
options.reportPackages = true;
options.release = 'WTNews@${file.readAsStringSync()}';
options.tracesSampler = (samplingContext) {
return 1.0;
Expand Down
76 changes: 44 additions & 32 deletions lib/pages/downloader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,21 @@ class _DownloaderState extends State<Downloader>
await windowManager.center();
try {
Data data = await Data.getData();

final deleteFile = File(p.joinAll(
[p.dirname(Platform.resolvedExecutable), 'data\\update.zip']));
final deleteFolder = Directory(
p.joinAll([p.dirname(Platform.resolvedExecutable), 'data\\out']));
if (await deleteFile.exists() || await deleteFolder.exists()) {
await deleteFile.delete(recursive: true);
await deleteFolder.delete(recursive: true);
}
Dio dio = Dio();
await dio.download(data.assets.last.browserDownloadUrl,
'${p.dirname(Platform.resolvedExecutable)}/data/update.zip',
onReceiveProgress: (downloaded, full) async {
progress = downloaded / full * 100;
setState(() {});
}).whenComplete(() async {
}, deleteOnError: true).whenComplete(() async {
final File filePath =
File('${p.dirname(Platform.resolvedExecutable)}/data/update.zip');
final Uint8List bytes = await File(
Expand Down Expand Up @@ -96,7 +103,6 @@ class _DownloaderState extends State<Downloader>
duration: const Duration(seconds: 10),
content: Text(e.toString())));
await Sentry.captureException(e, stackTrace: st);

error = true;
setState(() {});
}
Expand All @@ -106,38 +112,44 @@ class _DownloaderState extends State<Downloader>
double progress = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueGrey,
body: Center(
child: SizedBox(
height: 200,
width: 200,
child: CircularPercentIndicator(
center: !error
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Downloading',
return GestureDetector(
behavior: HitTestBehavior.translucent,
onPanStart: (details) {
windowManager.startDragging();
},
child: Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child: SizedBox(
height: 200,
width: 200,
child: CircularPercentIndicator(
center: !error
? Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Downloading',
style: TextStyle(fontSize: 15),
),
Text(
'${progress.toStringAsFixed(1)} %',
style: const TextStyle(fontSize: 15),
),
],
)
: const Center(
child: Text(
'ERROR',
style: TextStyle(fontSize: 15),
),
Text(
'${progress.toStringAsFixed(1)} %',
style: const TextStyle(fontSize: 15),
),
],
)
: const Center(
child: Text(
'ERROR',
style: TextStyle(fontSize: 15),
),
),
backgroundColor: Colors.blue,
percent: double.parse(progress.toStringAsFixed(0)) / 100,
radius: 100,
)),
));
backgroundColor: Colors.blue,
percent: double.parse(progress.toStringAsFixed(0)) / 100,
radius: 100,
)),
)),
);
}

final bool _showWindowBelowTrayIcon = false;
Expand Down
1 change: 0 additions & 1 deletion lib/pages/rss_feed.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:async';
import 'dart:io';
import 'dart:ui';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio/dio.dart';
Expand Down
13 changes: 6 additions & 7 deletions lib/pages/settings.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'dart:ui';

import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -28,9 +27,9 @@ class _SettingsState extends ConsumerState<Settings> {
void initState() {
super.initState();
WidgetsBinding.instance!.addPostFrameCallback((_) async {
ref.read(isStartupEnabled.notifier).state =
ref.read(startupEnabled.notifier).state =
prefs.getBool('startup') ?? false;
if (ref.read(isStartupEnabled.notifier).state) {
if (ref.read(startupEnabled.notifier).state) {
await Process.run(pathToUpdateShortcut, []);
}
ref.read(playSound.notifier).state = prefs.getBool('playSound') ?? false;
Expand Down Expand Up @@ -86,7 +85,7 @@ class _SettingsState extends ConsumerState<Settings> {
title: const Text('Main'),
tiles: [
SettingsTile.switchTile(
initialValue: ref.watch(isStartupEnabled),
initialValue: ref.watch(startupEnabled),
onToggle: (value) {
if (value) {
Process.run(pathToUpdateShortcut, []);
Expand All @@ -95,7 +94,7 @@ class _SettingsState extends ConsumerState<Settings> {
ref.read(minimizeOnStart.notifier).state = false;
prefs.setBool('minimize', false);
}
ref.read(isStartupEnabled.notifier).state = value;
ref.read(startupEnabled.notifier).state = value;
prefs.setBool('startup', value);
},
title: const Text('Run at Startup'),
Expand Down Expand Up @@ -125,10 +124,10 @@ class _SettingsState extends ConsumerState<Settings> {
),
SettingsSection(tiles: [
SettingsTile.switchTile(
initialValue: prefs.getBool('checkDataMine'),
initialValue: ref.watch(checkDataMine),
onToggle: (value) async {
prefs.setBool('checkDataMine', value);
ref.read(playSound.notifier).state = value;
ref.read(checkDataMine.notifier).state = value;
},
title: const Text('DataMine Notifier'),
leading: Image.asset(
Expand Down
2 changes: 1 addition & 1 deletion lib/providers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';

final StateProvider<bool> isStartupEnabled = StateProvider((ref) => false);
final StateProvider<bool> startupEnabled = StateProvider((ref) => false);
final StateProvider<bool> playSound = StateProvider((ref) => true);
final StateProvider<bool> minimizeOnStart = StateProvider((ref) => false);
final StateProvider<bool> checkDataMine = StateProvider((ref) => false);
Expand Down
54 changes: 31 additions & 23 deletions lib/widgets/titlebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,32 @@ class _WindowTitleBarState extends ConsumerState<WindowTitleBar>
ref.read(checkDataMine.notifier).state =
prefs.getBool('checkDataMine') ?? false;
});

lastPubDate.addListener(() async {
await notify(lastPubDate.value!, lastItemLink!);
await prefs.setString('previous', lastPubDate.value!);
});
Timer.periodic(const Duration(seconds: 10), (timer) async {
if (ref.watch(checkDataMine)) {
rssFeed = await getDataMine();
if (rssFeed != null && rssFeed?.items != null) {
RssItem item = rssFeed!.items!.first;
if (item.description != null) {
String itemDescription = item.description!;
bool? isDataMine = (itemDescription.contains('Raw changes:') &&
itemDescription.contains('→') &&
itemDescription.contains('Current dev version')) ||
itemDescription.contains(' ');
if (isDataMine) notify(item.pubDate!, item.link!);
rssFeed = await getDataMine()
.timeout(const Duration(seconds: 10))
.whenComplete(() async {
if (rssFeed != null && rssFeed?.items != null) {
RssItem item = rssFeed!.items!.first;
if (item.description != null) {
String itemDescription = item.description!;
bool? isDataMine = (itemDescription.contains('Raw changes:') &&
itemDescription.contains('→') &&
itemDescription.contains('Current dev version')) ||
itemDescription.contains(' ');
if (isDataMine) {
if (lastPubDate.value != item.pubDate.toString()) {
lastPubDate.value = item.pubDate.toString();
lastItemLink = item.link;
}
}
}
}
}
});
}
});
}
Expand All @@ -86,17 +97,14 @@ class _WindowTitleBarState extends ConsumerState<WindowTitleBar>
return rssFeed;
}

Future<void> notify(DateTime pubDate, String url) async {
Future<void> notify(String pubDate, String url) async {
if (prefs.getString('previous') != null) {
String? previous = prefs.getString('previous');

bool isNew =
previous != pubDate.toString() && pubDate.toString() != lastPubDate;
if (isNew) {
if (prefs.getString('previous') != pubDate) {
String? previous = prefs.getString('previous');
if (kDebugMode) {
print('isNew');
print(previous);
print(pubDate.toString());
print(pubDate);
}

AppUtil().playSound(newSound);
Expand All @@ -110,9 +118,8 @@ class _WindowTitleBarState extends ConsumerState<WindowTitleBar>
launchUrl(Uri.parse(url));
}
});
await prefs.setString('previous', pubDate.toString());
await prefs.setString('previous', pubDate);
}
lastPubDate = pubDate.toString();
} else {
if (kDebugMode) {
print('Null');
Expand All @@ -128,7 +135,6 @@ class _WindowTitleBarState extends ConsumerState<WindowTitleBar>
}
});
await prefs.setString('previous', pubDate.toString());
lastPubDate = pubDate.toString();
}
}

Expand All @@ -137,10 +143,12 @@ class _WindowTitleBarState extends ConsumerState<WindowTitleBar>
trayManager.removeListener(this);
windowManager.removeListener(this);
protocolHandler.removeListener(this);
lastPubDate.removeListener(() {});
super.dispose();
}

String? lastPubDate;
ValueNotifier<String?> lastPubDate = ValueNotifier(null);
String? lastItemLink;
RssFeed? rssFeed;
@override
Widget build(BuildContext context) {
Expand Down

0 comments on commit 01f0a47

Please sign in to comment.