Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions app/fonts/OpenDyslexic/OFL.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Copyright (c) 2019-07-29, Abbie Gonzalez (https://abbiecod.es|support@abbiecod.es),
with Reserved Font Name OpenDyslexic.
Copyright (c) 12/2012 - 2019
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL


-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------

PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.

The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.

DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.

"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).

"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).

"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.

"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.

PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:

1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.

2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.

3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.

4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.

5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.

TERMINATION
This license becomes null and void if any of the above conditions are
not met.

DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Binary file added app/fonts/OpenDyslexic/OpenDyslexic-Bold.otf
Binary file not shown.
Binary file not shown.
Binary file added app/fonts/OpenDyslexic/OpenDyslexic-Italic.otf
Binary file not shown.
Binary file added app/fonts/OpenDyslexic/OpenDyslexic-Regular.otf
Binary file not shown.
10 changes: 10 additions & 0 deletions app/fonts/OpenDyslexic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# OpenDyslexic

Unmodified OpenDyslexic font files from the author's repository:
https://github.com/antijingoist/opendyslexic/tree/1824da5c0e41dc3e13ffc7f3a636dcaf695d61b7/compiled

Upstream project: https://opendyslexic.org/
Current source repository: https://forge.hackers.town/antijingoist/opendyslexic

Bundled under the SIL Open Font License 1.1 in `OFL.txt`.
The app registers this license in Settings > About > Licenses.
2 changes: 1 addition & 1 deletion app/integration_test/support/tracking_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class TrackingValidationApp {
store.dispose();
preferences.dispose();
fixtureAuth.dispose();
await database.clearGuestLibrary();
await database.clearGuestLibrary(deleteFiles: (_) async {});
await database.close();
}
}
29 changes: 29 additions & 0 deletions app/lib/auth/auth_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,35 @@ class AuthApiClient {
return DateTime.parse(json['deletion_due_at'] as String);
}

Future<PapyrusUser> uploadProfilePhoto(String accessToken, Uint8List bytes, {required String displayName}) {
return _withUploadCooldown('/users/me/avatar', accessToken, () async {
final request = http.MultipartRequest('POST', config.endpoint('/users/me/avatar'))
..headers.addAll(_authHeaders(accessToken))
..fields['display_name'] = displayName
..files.add(
http.MultipartFile.fromBytes('file', bytes, filename: 'avatar.jpg', contentType: MediaType('image', 'jpeg')),
);

final response = await http.Response.fromStream(await _httpClient.send(request));
return PapyrusUser.fromJson(_decodeResponse(response));
});
}

Future<Uint8List> downloadProfilePhoto(String accessToken, String avatarUrl) async {
if (!RegExp(r'^/users/me/avatar/[0-9a-fA-F-]{36}$').hasMatch(avatarUrl)) {
throw const AuthApiException(statusCode: 0, message: 'Invalid profile photo');
}

final response = await _httpClient.get(config.endpoint(avatarUrl), headers: _authHeaders(accessToken));

if (response.statusCode >= 200 && response.statusCode < 300) {
return response.bodyBytes;
}

_decodeResponse(response);
throw const AuthApiException(statusCode: 0, message: 'Photo download failed');
}

Future<AuthTokens> recoverAccount(
AccountDeletionAuthorization authorization, {
required String clientType,
Expand Down
10 changes: 10 additions & 0 deletions app/lib/auth/auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ class AuthRepository {
return apiClient.updateCurrentUser(accessToken: accessToken, displayName: displayName, avatarUrl: avatarUrl);
}

Future<PapyrusUser> uploadProfilePhoto(Uint8List bytes, {required String displayName}) {
return _withFreshAccessToken((accessToken) {
return apiClient.uploadProfilePhoto(accessToken, bytes, displayName: displayName);
});
}

Future<Uint8List> downloadProfilePhoto(String avatarUrl) {
return _withFreshAccessToken((accessToken) => apiClient.downloadProfilePhoto(accessToken, avatarUrl));
}

Future<String> forgotPassword(String email) {
return apiClient.forgotPassword(email);
}
Expand Down
6 changes: 0 additions & 6 deletions app/lib/config/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:papyrus/pages/catalogs_page.dart';
import 'package:papyrus/pages/catalog_book_page.dart';
import 'package:papyrus/pages/forgot_password_page.dart';
import 'package:papyrus/pages/login_page.dart';
import 'package:papyrus/pages/edit_profile_page.dart';
import 'package:papyrus/pages/profile_page.dart';
import 'package:papyrus/pages/licenses_page.dart';
import 'package:papyrus/pages/support_page.dart';
Expand Down Expand Up @@ -282,11 +281,6 @@ class AppRouter {
child: SupportPage(client: SupportApiClient(config: syncSettingsProvider.activeApiConfig)),
),
),
GoRoute(
name: 'EDIT_PROFILE',
path: 'edit',
pageBuilder: (context, state) => NoTransitionPage(key: state.pageKey, child: const EditProfilePage()),
),
],
),
// Developer Options (debug only)
Expand Down
45 changes: 39 additions & 6 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import 'dart:convert';
import 'package:http/http.dart' as http;

import 'package:flutter/material.dart';
import 'package:papyrus/themes/app_motion.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:papyrus/themes/app_accessibility.dart';
import 'package:flutter_web_plugins/url_strategy.dart';
import 'package:papyrus/acquisition/acquisition_api_client.dart';
import 'package:papyrus/auth/auth_api_client.dart';
Expand All @@ -24,6 +26,7 @@ import 'package:papyrus/opds/opds_http_client.dart';
import 'package:papyrus/opds/opds_library.dart';
import 'package:papyrus/opds/opds_resource_cache.dart';
import 'package:papyrus/services/book_import_session.dart';
import 'package:papyrus/services/guest_account_deletion_service.dart';
import 'package:papyrus/platform/book_import_drop_registration.dart';
import 'package:papyrus/powersync/powersync_service.dart';
import 'package:papyrus/powersync/papyrus_powersync_connector.dart';
Expand Down Expand Up @@ -52,6 +55,11 @@ Future main() async {
ensureBookImportDropPluginRegistered();
usePathUrlStrategy();

LicenseRegistry.addLicense(() async* {
final license = await rootBundle.loadString('fonts/OpenDyslexic/OFL.txt');
yield LicenseEntryWithLineBreaks(['OpenDyslexic'], license);
});

try {
await GoalCalendar.deviceTimezone();
} catch (_) {
Expand Down Expand Up @@ -540,6 +548,15 @@ class _PapyrusState extends State<Papyrus> {
ChangeNotifierProvider.value(value: _bookStorageStatusController),
Provider.value(value: _powerSyncService),
Provider.value(value: _bookImportService),
Provider(
create: (_) => GuestAccountDeletionService(
auth: _authProvider,
library: _powerSyncService,
files: _bookImportService,
catalogs: _opdsCatalogs,
downloads: _opdsDownloads,
),
),
ChangeNotifierProvider.value(value: _opdsCatalogs),
ChangeNotifierProvider.value(value: _opdsDownloads),
Provider.value(value: _opdsHttpClient),
Expand All @@ -559,18 +576,34 @@ class _PapyrusState extends State<Papyrus> {
child: Consumer<PreferencesProvider>(
builder: (context, preferencesProvider, child) {
final isEink = preferencesProvider.isEinkMode;
final lightTheme = preferencesProvider.increaseContrast ? AppTheme.highContrastLight : AppTheme.light;
final darkTheme = preferencesProvider.increaseContrast ? AppTheme.highContrastDark : AppTheme.dark;

return MaterialApp.router(
title: 'Papyrus',
debugShowCheckedModeBanner: false,
theme: isEink ? AppTheme.eink : AppTheme.light,
darkTheme: isEink ? AppTheme.eink : AppTheme.dark,
theme: AppTheme.withTypography(
isEink ? AppTheme.eink : lightTheme,
dyslexiaFont: preferencesProvider.dyslexiaFont,
),
darkTheme: AppTheme.withTypography(
isEink ? AppTheme.eink : darkTheme,
dyslexiaFont: preferencesProvider.dyslexiaFont,
),
highContrastTheme: AppTheme.withTypography(
isEink ? AppTheme.eink : AppTheme.highContrastLight,
dyslexiaFont: preferencesProvider.dyslexiaFont,
),
highContrastDarkTheme: AppTheme.withTypography(
isEink ? AppTheme.eink : AppTheme.highContrastDark,
dyslexiaFont: preferencesProvider.dyslexiaFont,
),
themeMode: isEink ? ThemeMode.light : preferencesProvider.themeMode,
themeAnimationDuration: isEink || preferencesProvider.reduceAnimations
themeAnimationDuration:
isEink || preferencesProvider.reduceAnimations || MediaQuery.disableAnimationsOf(context)
? Duration.zero
: kThemeAnimationDuration,
builder: (context, child) =>
AppMotionScope(reduceAnimations: isEink || preferencesProvider.reduceAnimations, child: child!),
builder: (context, child) => AppAccessibilityScope(preferences: preferencesProvider, child: child!),
routerConfig: _appRouter.router,
);
},
Expand Down
10 changes: 10 additions & 0 deletions app/lib/opds/opds_catalog_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ class OpdsCatalogStore {
return result;
}

Future<void> clearScope(String scope) => _serialize(() async {
for (final catalog in load(scope)) {
await _secrets.delete(_secretKey(scope, catalog.id));
}

if (!await _prefs.remove(_key(scope))) {
throw const OpdsException('Could not remove saved catalogs.');
}
});

/// Omitted credentials preserve the existing secret unless the origin changes.
Future<void> save(String scope, OpdsCatalog catalog, {OpdsCredentials? credentials, bool clearCredentials = false}) =>
_serialize(() async {
Expand Down
10 changes: 10 additions & 0 deletions app/lib/opds/opds_catalogs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ class OpdsCatalogs extends ChangeNotifier {
}
}

Future<void> clearScope(String scope) async {
await cache?.clearScope(scope);
await library?.clearScope(scope);
await store.clearScope(scope);

if (_scope == scope && !_disposed) {
reload();
}
}

@override
void dispose() {
_disposed = true;
Expand Down
6 changes: 6 additions & 0 deletions app/lib/opds/opds_downloads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ class OpdsDownloads extends ChangeNotifier {
_notify();
}

Future<void> cancelAndWait() async {
final operations = _operations.values.toList();
reset();
await Future.wait(operations);
}

void _notify() {
if (!_disposed) {
notifyListeners();
Expand Down
17 changes: 17 additions & 0 deletions app/lib/opds/opds_library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:papyrus/data/data_store.dart';
import 'package:papyrus/opds/opds_models.dart';
import 'package:papyrus/opds/opds_http_client.dart';
import 'package:shared_preferences/shared_preferences.dart';

/// Captured before import, so its result cannot be attributed to another account.
Expand Down Expand Up @@ -157,6 +158,22 @@ class OpdsLibrary extends ChangeNotifier {
return _pending;
}

Future<void> clearScope(String scope) async {
if (_scope == scope) {
_generation++;
_imports = {};
}

_scopedImports.remove(scope);
await _pending;

if (!await _prefs.remove(_key(scope))) {
throw const OpdsException('Could not remove catalog import history.');
}

_changed();
}

void _changed() {
if (!_disposed) {
notifyListeners();
Expand Down
10 changes: 10 additions & 0 deletions app/lib/opds/opds_resource_cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ class OpdsResourceCache extends ChangeNotifier {

String _serialize() => jsonEncode({'version': 1, 'entries': _entries.values.toList()});

Future<void> clearScope(String scope) {
if (_scope == scope) {
_epoch++;
}

_entries.removeWhere((key, _) => (jsonDecode(key) as List).first == scope);
notifyListeners();
return _persist();
}

void _trim() {
while (_entries.isNotEmpty && (_entries.length > maxEntries || utf8.encode(_serialize()).length > maxBytes)) {
_entries.remove(_entries.keys.first);
Expand Down
Loading
Loading