Skip to content

Commit

Permalink
chore: propagate hotfixes from master to develop (#1200)
Browse files Browse the repository at this point in the history
chore: propagate hotfixes from master to develop
  • Loading branch information
limwa authored Mar 8, 2024
2 parents fe5915f + 687fdf7 commit 27b0414
Show file tree
Hide file tree
Showing 17 changed files with 147 additions and 156 deletions.
2 changes: 1 addition & 1 deletion uni/assets/text/TermsAndConditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ If you would like to contact us to understand more about this Agreement or wish
concerning any matter relating to it, you may send an email to [[email protected]](mailto:[email protected]).
\
\
This document was last updated on February 28, 2023.
This document was last updated on March 6, 2024.
62 changes: 28 additions & 34 deletions uni/lib/controller/cleanup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:uni/controller/local_storage/database/app_bus_stop_database.dart';
Expand All @@ -22,24 +23,19 @@ Future<void> cleanupStoredData(BuildContext context) async {
final faculties = PreferencesController.getUserFaculties();
await prefs.clear();

unawaited(
Future.wait([
AppLecturesDatabase().deleteLectures(),
AppExamsDatabase().deleteExams(),
AppCoursesDatabase().deleteCourses(),
AppUserDataDatabase().deleteUserData(),
AppLastUserInfoUpdateDatabase().deleteLastUpdate(),
AppBusStopDatabase().deleteBusStops(),
AppCourseUnitsDatabase().deleteCourseUnits(),
NetworkRouter.killSigarraAuthentication(faculties),
]),
);
await Future.wait([
AppLecturesDatabase().deleteLectures(),
AppExamsDatabase().deleteExams(),
AppCoursesDatabase().deleteCourses(),
AppUserDataDatabase().deleteUserData(),
AppLastUserInfoUpdateDatabase().deleteLastUpdate(),
AppBusStopDatabase().deleteBusStops(),
AppCourseUnitsDatabase().deleteCourseUnits(),
NetworkRouter.killSigarraAuthentication(faculties),
]);

final path = (await getApplicationDocumentsDirectory()).path;
final directory = Directory(path);
if (directory.existsSync()) {
directory.deleteSync(recursive: true);
}
final toCleanDirectory = await getApplicationDocumentsDirectory();
await cleanDirectory(toCleanDirectory, DateTime.now());
}

Future<void> cleanupCachedFiles() async {
Expand All @@ -53,26 +49,24 @@ Future<void> cleanupCachedFiles() async {

final toCleanDirectory = await getApplicationDocumentsDirectory();
final threshold = DateTime.now().subtract(const Duration(days: 30));
final directories = toCleanDirectory.listSync(followLinks: false);

for (final directory in directories) {
if (directory is Directory) {
final files = directory.listSync(recursive: true, followLinks: false);
await cleanDirectory(toCleanDirectory, threshold);

final oldFiles = files.where((file) {
try {
final fileDate = File(file.path).lastModifiedSync();
return fileDate.isBefore(threshold);
} catch (e) {
return false;
}
});
await PreferencesController.setLastCleanUpDate(DateTime.now());
}

for (final file in oldFiles) {
await File(file.path).delete();
}
Future<void> cleanDirectory(Directory directory, DateTime threshold) async {
final entities = directory.listSync(recursive: true, followLinks: false);
final toDeleteEntities = entities.whereType<File>().where((file) {
try {
final fileDate = file.lastModifiedSync();
return fileDate.isBefore(threshold) && path.extension(file.path) != '.db';
} catch (e) {
return false;
}
}
});

await PreferencesController.setLastCleanUpDate(DateTime.now());
for (final entity in toDeleteEntities) {
entity.deleteSync();
}
}
52 changes: 34 additions & 18 deletions uni/lib/controller/fetchers/departures_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:html/dom.dart';
import 'package:html/parser.dart';
import 'package:http/io_client.dart' as http;
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/bus.dart';
import 'package:uni/model/entities/bus_stop.dart';
Expand All @@ -26,24 +28,38 @@ class DeparturesFetcher {

final response = await _client.get(url.toUri());
final htmlResponse = parse(response.body);

final scriptText = htmlResponse
.querySelectorAll('table script')
.where((element) => element.text.contains(_stopCode))
.map((e) => e.text)
.first;

final callParam = scriptText
.substring(scriptText.indexOf('('))
.split(',')
.firstWhere((element) => element.contains(')'));

final csrfToken = callParam.substring(
callParam.indexOf("'") + 1,
callParam.lastIndexOf("'"),
);

return csrfToken;
try {
final scriptText = htmlResponse
.querySelectorAll('table script')
.where((element) => element.text.contains(_stopCode))
.map((e) => e.text)
.first;

final callParam = scriptText
.substring(scriptText.indexOf('('))
.split(',')
.firstWhere((element) => element.contains(')'));

final csrfToken = callParam.substring(
callParam.indexOf("'") + 1,
callParam.lastIndexOf("'"),
);
return csrfToken;
} catch (e, stackTrace) {
unawaited(
Sentry.captureEvent(
SentryEvent(
throwable: e,
request: SentryRequest(
url: url,
data: response.body,
),
),
stackTrace: stackTrace,
),
);
rethrow;
}
}

void throwCSRFTokenError() {
Expand Down
13 changes: 6 additions & 7 deletions uni/lib/controller/parsers/parser_schedule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Future<List<Lecture>> parseScheduleMultipleRequests(
for (final (week, response) in responsesPerWeeks) {
lectures += await parseSchedule(response, week);
}

if (lectures.isEmpty) {
return Future.error(Exception('Found empty schedule'));
}

return lectures;
}

Expand Down Expand Up @@ -70,11 +75,5 @@ Future<List<Lecture>> parseSchedule(
lectures.add(lec);
}

final lecturesList = lectures.toList()..sort((a, b) => a.compare(b));

if (lecturesList.isEmpty) {
return Future.error(Exception('Found empty schedule'));
}

return lecturesList;
return lectures.toList()..sort((a, b) => a.compare(b));
}
13 changes: 7 additions & 6 deletions uni/lib/generated/intl/messages_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
import 'package:intl/src/intl_helpers.dart';
Expand All @@ -20,8 +21,8 @@ import 'messages_pt_PT.dart' as messages_pt_pt;

typedef Future<dynamic> LibraryLoader();
Map<String, LibraryLoader> _deferredLibraries = {
'en': () => new Future.value(null),
'pt_PT': () => new Future.value(null),
'en': () => new SynchronousFuture(null),
'pt_PT': () => new SynchronousFuture(null),
};

MessageLookupByLibrary? _findExact(String localeName) {
Expand All @@ -36,18 +37,18 @@ MessageLookupByLibrary? _findExact(String localeName) {
}

/// User programs should call this before using [localeName] for messages.
Future<bool> initializeMessages(String localeName) async {
Future<bool> initializeMessages(String localeName) {
var availableLocale = Intl.verifiedLocale(
localeName, (locale) => _deferredLibraries[locale] != null,
onFailure: (_) => null);
if (availableLocale == null) {
return new Future.value(false);
return new SynchronousFuture(false);
}
var lib = _deferredLibraries[availableLocale];
await (lib == null ? new Future.value(false) : lib());
lib == null ? new SynchronousFuture(false) : lib();
initializeInternalMessageLookup(() => new CompositeMessageLookup());
messageLookup.addLocale(availableLocale, _findGeneratedMessagesFor);
return new Future.value(true);
return new SynchronousFuture(true);
}

bool _messagesExistFor(String locale) {
Expand Down
14 changes: 8 additions & 6 deletions uni/lib/generated/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -19,12 +20,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'en';

static m0(time) => "last refresh at ${time}";
static String m0(time) => "last refresh at ${time}";

static m1(time) =>
static String m1(time) =>
"${Intl.plural(time, zero: 'Refreshed ${time} minutes ago', one: 'Refreshed ${time} minute ago', other: 'Refreshed ${time} minutes ago')}";

static m2(title) => "${Intl.select(title, {
static String m2(title) => "${Intl.select(title, {
'horario': 'Schedule',
'exames': 'Exams',
'area': 'Personal Area',
Expand All @@ -41,7 +42,7 @@ class MessageLookup extends MessageLookupByLibrary {
})}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function>{
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("About us"),
"academic_services":
MessageLookupByLibrary.simpleMessage("Academic services"),
Expand Down Expand Up @@ -277,7 +278,8 @@ class MessageLookup extends MessageLookupByLibrary {
"terms": MessageLookupByLibrary.simpleMessage("Terms and Conditions"),
"theme": MessageLookupByLibrary.simpleMessage("Theme"),
"title": MessageLookupByLibrary.simpleMessage("Title"),
"uc_info": MessageLookupByLibrary.simpleMessage("Open UC page in app"),
"try_again": MessageLookupByLibrary.simpleMessage("Try again"),
"uc_info": MessageLookupByLibrary.simpleMessage("Open UC page"),
"unavailable": MessageLookupByLibrary.simpleMessage("Unavailable"),
"valid_email":
MessageLookupByLibrary.simpleMessage("Please enter a valid email"),
Expand Down
15 changes: 8 additions & 7 deletions uni/lib/generated/intl/messages_pt_PT.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// ignore_for_file:unnecessary_brace_in_string_interps, unnecessary_new
// ignore_for_file:prefer_single_quotes,comment_references, directives_ordering
// ignore_for_file:annotate_overrides,prefer_generic_function_type_aliases
// ignore_for_file:unused_import, file_names
// ignore_for_file:unused_import, file_names, avoid_escaping_inner_quotes
// ignore_for_file:unnecessary_string_interpolations, unnecessary_string_escapes

import 'package:intl/intl.dart';
import 'package:intl/message_lookup_by_library.dart';
Expand All @@ -19,12 +20,12 @@ typedef String MessageIfAbsent(String messageStr, List<dynamic> args);
class MessageLookup extends MessageLookupByLibrary {
String get localeName => 'pt_PT';

static m0(time) => "última atualização às ${time}";
static String m0(time) => "última atualização às ${time}";

static m1(time) =>
static String m1(time) =>
"${Intl.plural(time, zero: 'Atualizado há ${time} minutos', one: 'Atualizado há ${time} minuto', other: 'Atualizado há ${time} minutos')}";

static m2(title) => "${Intl.select(title, {
static String m2(title) => "${Intl.select(title, {
'horario': 'Horário',
'exames': 'Exames',
'area': 'Área Pessoal',
Expand All @@ -41,7 +42,7 @@ class MessageLookup extends MessageLookupByLibrary {
})}";

final messages = _notInlinedMessages(_notInlinedMessages);
static _notInlinedMessages(_) => <String, Function>{
static Map<String, Function> _notInlinedMessages(_) => <String, Function>{
"about": MessageLookupByLibrary.simpleMessage("Sobre nós"),
"academic_services":
MessageLookupByLibrary.simpleMessage("Serviços académicos"),
Expand Down Expand Up @@ -279,8 +280,8 @@ class MessageLookup extends MessageLookupByLibrary {
"terms": MessageLookupByLibrary.simpleMessage("Termos e Condições"),
"theme": MessageLookupByLibrary.simpleMessage("Tema"),
"title": MessageLookupByLibrary.simpleMessage("Título"),
"uc_info":
MessageLookupByLibrary.simpleMessage("Abrir página da UC na app"),
"try_again": MessageLookupByLibrary.simpleMessage("Tentar de novo"),
"uc_info": MessageLookupByLibrary.simpleMessage("Abrir página da UC"),
"unavailable": MessageLookupByLibrary.simpleMessage("Indisponível"),
"valid_email": MessageLookupByLibrary.simpleMessage(
"Por favor insere um email válido"),
Expand Down
10 changes: 10 additions & 0 deletions uni/lib/generated/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion uni/lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,7 @@
"confirm_logout": "Do you really want to log out? Your local data will be deleted and you will have to log in again.",
"@confirm_logout": {},
"collect_usage_stats": "Collect usage statistics",
"@usage_stats": {}
"@usage_stats": {},
"try_again": "Try again",
"@try_again": {}
}
4 changes: 3 additions & 1 deletion uni/lib/l10n/intl_pt_PT.arb
Original file line number Diff line number Diff line change
Expand Up @@ -313,5 +313,7 @@
"confirm_logout": "Tens a certeza de que queres terminar sessão? Os teus dados locais serão apagados e terás de iniciar sessão novamente.",
"@confirm_logout": {},
"collect_usage_stats": "Partilhar estatísticas de uso",
"@collect_usage_stats": {}
"@collect_usage_stats": {},
"try_again": "Tentar de novo",
"@try_again": {}
}
Loading

0 comments on commit 27b0414

Please sign in to comment.