analytics client
This commit is contained in:
parent
903cbba69a
commit
2a7265256d
@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'package:filcnaplo/models/config.dart';
|
||||
import 'package:filcnaplo/models/news.dart';
|
||||
import 'package:filcnaplo/models/release.dart';
|
||||
import 'package:filcnaplo/models/settings.dart';
|
||||
import 'package:filcnaplo/models/supporter.dart';
|
||||
import 'package:filcnaplo_kreta_api/models/school.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@ -41,10 +42,10 @@ class FilcAPI {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: implement `x-filc-id` header
|
||||
static Future<Config?> getConfig() async {
|
||||
static Future<Config?> getConfig(SettingsProvider settings) async {
|
||||
Map<String, String> headers = {
|
||||
"x-filc-id": "",
|
||||
"x-filc-id": settings.xFilcId,
|
||||
"user-agent": settings.config.userAgent,
|
||||
};
|
||||
|
||||
try {
|
||||
@ -52,9 +53,11 @@ class FilcAPI {
|
||||
|
||||
if (res.statusCode == 200) {
|
||||
return Config.fromJson(jsonDecode(res.body));
|
||||
} else {
|
||||
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||
} else if (res.statusCode == 429) {
|
||||
res = await http.get(Uri.parse(CONFIG));
|
||||
if (res.statusCode == 200) return Config.fromJson(jsonDecode(res.body));
|
||||
}
|
||||
throw "HTTP ${res.statusCode}: ${res.body}";
|
||||
} catch (error) {
|
||||
print("ERROR: FilcAPI.getConfig: $error");
|
||||
}
|
||||
@ -115,4 +118,6 @@ class FilcAPI {
|
||||
|
||||
return Future.value(null);
|
||||
}
|
||||
|
||||
// TODO: static Future<void> sendReport(ErrorReport report) async {}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class App extends StatelessWidget {
|
||||
setSystemChrome(context);
|
||||
|
||||
WidgetsBinding.instance?.addPostFrameCallback((_) {
|
||||
FilcAPI.getConfig().then((Config? config) {
|
||||
FilcAPI.getConfig(settings).then((Config? config) {
|
||||
settings.update(context, database: database, config: config ?? Config.fromJson({}));
|
||||
});
|
||||
});
|
||||
|
@ -9,7 +9,8 @@ Future<Database> initDB() async {
|
||||
var settingsDB = await createSettingsTable(db);
|
||||
|
||||
// Create table Users
|
||||
await db.execute("CREATE TABLE IF NOT EXISTS users (id TEXT NOT NULL, name TEXT, username TEXT, password TEXT, institute_code TEXT, student TEXT)");
|
||||
await db.execute(
|
||||
"CREATE TABLE IF NOT EXISTS users (id TEXT NOT NULL, name TEXT, username TEXT, password TEXT, institute_code TEXT, student TEXT, role INTEGER)");
|
||||
await db.execute("CREATE TABLE IF NOT EXISTS user_data ("
|
||||
"id TEXT NOT NULL, grades TEXT, timetable TEXT, exams TEXT, homework TEXT, messages TEXT, notes TEXT, events TEXT, absences TEXT)");
|
||||
|
||||
@ -30,6 +31,7 @@ Future<DatabaseStruct> createSettingsTable(Database db) async {
|
||||
"grade_color1": int, "grade_color2": int, "grade_color3": int, "grade_color4": int, "grade_color5": int, // grade colors
|
||||
"vibration_strength": int, "ab_weeks": int, "swap_ab_weeks": int,
|
||||
"notifications": int, "notifications_bitfield": int, "notification_poll_interval": int, // notifications
|
||||
"x_filc_id": String,
|
||||
});
|
||||
|
||||
// Create table Settings
|
||||
|
@ -6,6 +6,7 @@ import 'package:filcnaplo/theme.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
enum Pages { home, grades, timetable, messages, absences }
|
||||
enum UpdateChannel { stable, beta, dev }
|
||||
@ -47,6 +48,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
bool _swapABweeks;
|
||||
UpdateChannel _updateChannel;
|
||||
Config _config;
|
||||
String _xFilcId;
|
||||
|
||||
SettingsProvider({
|
||||
required String language,
|
||||
@ -66,6 +68,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
required bool swapABweeks,
|
||||
required UpdateChannel updateChannel,
|
||||
required Config config,
|
||||
required String xFilcId,
|
||||
}) : _language = language,
|
||||
_startPage = startPage,
|
||||
_rounding = rounding,
|
||||
@ -82,7 +85,8 @@ class SettingsProvider extends ChangeNotifier {
|
||||
_ABweeks = ABweeks,
|
||||
_swapABweeks = swapABweeks,
|
||||
_updateChannel = updateChannel,
|
||||
_config = config {
|
||||
_config = config,
|
||||
_xFilcId = xFilcId {
|
||||
PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
|
||||
_packageInfo = packageInfo;
|
||||
});
|
||||
@ -113,6 +117,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
swapABweeks: map["swap_ab_weeks"] == 1 ? true : false,
|
||||
updateChannel: UpdateChannel.values[map["update_channel"]],
|
||||
config: Config.fromJson(jsonDecode(map["config"] ?? "{}")),
|
||||
xFilcId: map["x_filc_id"],
|
||||
);
|
||||
}
|
||||
|
||||
@ -139,6 +144,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
"swap_ab_weeks": _swapABweeks ? 1 : 0,
|
||||
"notification_poll_interval": _notificationPollInterval,
|
||||
"config": jsonEncode(config.json),
|
||||
"x_filc_id": _xFilcId,
|
||||
};
|
||||
}
|
||||
|
||||
@ -167,6 +173,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
swapABweeks: false,
|
||||
updateChannel: UpdateChannel.stable,
|
||||
config: Config.fromJson({}),
|
||||
xFilcId: Uuid().v4(),
|
||||
);
|
||||
}
|
||||
|
||||
@ -189,6 +196,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
UpdateChannel get updateChannel => _updateChannel;
|
||||
PackageInfo? get packageInfo => _packageInfo;
|
||||
Config get config => _config;
|
||||
String get xFilcId => _xFilcId;
|
||||
|
||||
Future<void> update(
|
||||
BuildContext context, {
|
||||
@ -210,6 +218,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
bool? swapABweeks,
|
||||
UpdateChannel? updateChannel,
|
||||
Config? config,
|
||||
String? xFilcId,
|
||||
}) async {
|
||||
if (language != null && language != _language) _language = language;
|
||||
if (startPage != null && startPage != _startPage) _startPage = startPage;
|
||||
@ -229,6 +238,7 @@ class SettingsProvider extends ChangeNotifier {
|
||||
if (swapABweeks != null && swapABweeks != _swapABweeks) _swapABweeks = swapABweeks;
|
||||
if (updateChannel != null && updateChannel != _updateChannel) _updateChannel = updateChannel;
|
||||
if (config != null && config != _config) _config = config;
|
||||
if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId;
|
||||
|
||||
if (database == null) database = Provider.of<DatabaseProvider>(context, listen: false);
|
||||
await database.store.storeSettings(this);
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 8b3ec15500b0fb686c75383704c393c524d00878
|
||||
Subproject commit 08d802282c044be666f7b7ae55ae88b334ba515b
|
Loading…
x
Reference in New Issue
Block a user