Tracked players now updates in the background (off by default)
This commit is contained in:
parent
68784834fe
commit
8b5bf8c4d2
|
@ -92,9 +92,10 @@ void main() async {
|
||||||
}
|
}
|
||||||
|
|
||||||
// I dont want to store old cache
|
// I dont want to store old cache
|
||||||
Timer.periodic(Duration(minutes: 5), (Timer timer) {
|
Timer.periodic(Duration(minutes: 5), (Timer timer) async {
|
||||||
teto.cacheRoutine();
|
teto.cacheRoutine();
|
||||||
developer.log("Cache routine complete", name: "main");
|
developer.log("Cache routine complete, next one in ${DateTime.now().add(Duration(minutes: 5))}", name: "main");
|
||||||
|
if (prefs.getBool("updateInBG") == true) await teto.fetchTracked();
|
||||||
});
|
});
|
||||||
|
|
||||||
runApp(TranslationProvider(
|
runApp(TranslationProvider(
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:developer' as developer;
|
import 'dart:developer' as developer;
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:tetra_stats/data_objects/tetra_stats.dart';
|
import 'package:tetra_stats/data_objects/tetra_stats.dart';
|
||||||
import 'package:tetra_stats/data_objects/tetrio_multiplayer_replay.dart';
|
import 'package:tetra_stats/data_objects/tetrio_multiplayer_replay.dart';
|
||||||
|
@ -688,6 +689,21 @@ class TetrioService extends DB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// i want to know progress, so i trying to figure out this thing:
|
||||||
|
// Stream<TetrioPlayersLeaderboard> fetchTLLeaderboardAsStream() async {
|
||||||
|
// TetrioPlayersLeaderboard? cached = _cache.get("league", TetrioPlayersLeaderboard);
|
||||||
|
// if (cached != null) return cached;
|
||||||
|
|
||||||
|
// Uri url;
|
||||||
|
// if (kIsWeb) {
|
||||||
|
// url = Uri.https('ts.dan63.by', 'oskware_bridge.php', {"endpoint": "TLLeaderboard"});
|
||||||
|
// } else {
|
||||||
|
// url = Uri.https('ch.tetr.io', 'api/users/lists/league/all');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Stream<TetrioPlayersLeaderboard> stream = http.StreamedRequest("GET", url);
|
||||||
|
// }
|
||||||
|
|
||||||
TetrioPlayersLeaderboard? getCachedLeaderboard(){
|
TetrioPlayersLeaderboard? getCachedLeaderboard(){
|
||||||
return _cache.get("league", TetrioPlayersLeaderboard);
|
return _cache.get("league", TetrioPlayersLeaderboard);
|
||||||
}
|
}
|
||||||
|
@ -1157,4 +1173,15 @@ class TetrioService extends DB {
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> fetchTracked() async {
|
||||||
|
for (String userID in (await getAllPlayerToTrack())) {
|
||||||
|
TetrioPlayer player = await fetchPlayer(userID);
|
||||||
|
storeState(player);
|
||||||
|
sleep(Durations.extralong4);
|
||||||
|
TetraLeagueAlphaStream matches = await fetchTLStream(userID);
|
||||||
|
saveTLMatchesFromStream(matches);
|
||||||
|
sleep(Durations.extralong4);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,9 +311,11 @@ class _MainState extends State<MainView> with TickerProviderStateMixin {
|
||||||
chartsData = [];
|
chartsData = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (prefs.getBool("updateInBG") == true) {
|
||||||
backgroundUpdate = Timer(me.cachedUntil!.difference(DateTime.now()), () {
|
backgroundUpdate = Timer(me.cachedUntil!.difference(DateTime.now()), () {
|
||||||
changePlayer(me.userId);
|
changePlayer(me.userId);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return [me, records, states, tlMatches, compareWith, isTracking, news, topTR];
|
return [me, records, states, tlMatches, compareWith, isTracking, news, topTR];
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import 'package:tetra_stats/utils/open_in_browser.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
late String oldWindowTitle;
|
late String oldWindowTitle;
|
||||||
|
TextStyle subtitleStyle = const TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey);
|
||||||
|
|
||||||
class SettingsView extends StatefulWidget {
|
class SettingsView extends StatefulWidget {
|
||||||
const SettingsView({super.key});
|
const SettingsView({super.key});
|
||||||
|
@ -26,6 +27,7 @@ class SettingsState extends State<SettingsView> {
|
||||||
late SharedPreferences prefs;
|
late SharedPreferences prefs;
|
||||||
String defaultNickname = "Checking...";
|
String defaultNickname = "Checking...";
|
||||||
late bool showPositions;
|
late bool showPositions;
|
||||||
|
late bool updateInBG;
|
||||||
final TextEditingController _playertext = TextEditingController();
|
final TextEditingController _playertext = TextEditingController();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -47,6 +49,7 @@ class SettingsState extends State<SettingsView> {
|
||||||
Future<void> _getPreferences() async {
|
Future<void> _getPreferences() async {
|
||||||
prefs = await SharedPreferences.getInstance();
|
prefs = await SharedPreferences.getInstance();
|
||||||
showPositions = prefs.getBool("showPositions") ?? false;
|
showPositions = prefs.getBool("showPositions") ?? false;
|
||||||
|
updateInBG = prefs.getBool("updateInBG") ?? false;
|
||||||
_setDefaultNickname(prefs.getString("player"));
|
_setDefaultNickname(prefs.getString("player"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +94,7 @@ class SettingsState extends State<SettingsView> {
|
||||||
children: [
|
children: [
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(t.exportDB),
|
title: Text(t.exportDB),
|
||||||
subtitle: Text(t.exportDBDescription, style: const TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey)),
|
subtitle: Text(t.exportDBDescription, style: subtitleStyle),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (kIsWeb){
|
if (kIsWeb){
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(t.notForWeb)));
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(t.notForWeb)));
|
||||||
|
@ -145,7 +148,7 @@ class SettingsState extends State<SettingsView> {
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(t.importDB),
|
title: Text(t.importDB),
|
||||||
subtitle: Text(t.importDBDescription, style: const TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey)),
|
subtitle: Text(t.importDBDescription, style: subtitleStyle),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (kIsWeb){
|
if (kIsWeb){
|
||||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(t.notForWeb)));
|
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(t.notForWeb)));
|
||||||
|
@ -197,6 +200,7 @@ class SettingsState extends State<SettingsView> {
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(t.yourID),
|
title: Text(t.yourID),
|
||||||
|
subtitle: Text(t.yourIDText, style: subtitleStyle),
|
||||||
trailing: Text(defaultNickname),
|
trailing: Text(defaultNickname),
|
||||||
onTap: () => showDialog(
|
onTap: () => showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -242,6 +246,7 @@ class SettingsState extends State<SettingsView> {
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(t.language),
|
title: Text(t.language),
|
||||||
|
subtitle: Text("By default, the system language will be selected (if available among Tetra Stats locales, otherwise English)", style: subtitleStyle),
|
||||||
trailing: DropdownButton(
|
trailing: DropdownButton(
|
||||||
items: locales,
|
items: locales,
|
||||||
value: LocaleSettings.currentLocale,
|
value: LocaleSettings.currentLocale,
|
||||||
|
@ -261,6 +266,14 @@ class SettingsState extends State<SettingsView> {
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.go("/customization");
|
context.go("/customization");
|
||||||
},),
|
},),
|
||||||
|
ListTile(title: Text("Update stats in the background"),
|
||||||
|
subtitle: Text("While tetra stats is running, it can update stats of the current player when cache expires, as well, as tetra league stats of tracked players", style: const TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey)),
|
||||||
|
trailing: Switch(value: updateInBG, onChanged: (bool value){
|
||||||
|
prefs.setBool("updateInBG", value);
|
||||||
|
setState(() {
|
||||||
|
updateInBG = value;
|
||||||
|
});
|
||||||
|
}),),
|
||||||
ListTile(title: Text(t.lbStats),
|
ListTile(title: Text(t.lbStats),
|
||||||
subtitle: Text(t.lbStatsDescription, style: const TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey)),
|
subtitle: Text(t.lbStatsDescription, style: const TextStyle(fontFamily: "Eurostile Round Condensed", color: Colors.grey)),
|
||||||
trailing: Switch(value: showPositions, onChanged: (bool value){
|
trailing: Switch(value: showPositions, onChanged: (bool value){
|
||||||
|
|
Loading…
Reference in New Issue