Skip to content

Commit

Permalink
Fix a few issues in LCP (that were introduced during migration to nul…
Browse files Browse the repository at this point in the history
…l-safety). Upgrade a few deps.
  • Loading branch information
jmgeffroy committed Jan 24, 2024
1 parent 78f7a44 commit 7327f5f
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 1,106 deletions.
445 changes: 0 additions & 445 deletions components/commons/pubspec.lock

This file was deleted.

2 changes: 1 addition & 1 deletion components/commons/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
archive: ^3.3.7
archive: ^3.4.10
crypto: ^3.0.3
dartx: ^1.2.0
dfunc: ^0.9.0
Expand Down
2 changes: 1 addition & 1 deletion components/lcp/lib/license/license.dart
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class License implements LcpLicense {

_validateStatusDocument(await data);

return Try.success(_documents.license.rights.end);
return Try.success(_documents.license.rights?.end);
// } on CancellationException {
// // Passthrough for cancelled coroutines
// rethrow;
Expand Down
90 changes: 38 additions & 52 deletions components/lcp/lib/license/license_validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,11 @@ class LicenseValidation {

void validate(LicenseValidationDocument document, Observer completion) {
LVEvent event;
switch (document.runtimeType) {
case LicenseValidationLicenseDocument:
if (document is LicenseValidationLicenseDocument) {
event = RetrievedLicenseDataEvent(document.data);
break;
case LicenseValidationStatusDocument:
} else if (document is LicenseValidationStatusDocument) {
event = RetrievedStatusDataEvent(document.data);
break;
default:
} else {
throw LcpException.unknown;
}
_log("validate $event");
Expand All @@ -158,52 +155,41 @@ class LicenseValidation {
Future<void> _handle(LVState state) async {
_log("state: ${state.runtimeType}");
try {
switch (state.runtimeType) {
case StartState:
if (state is StartState) {
_notifyObservers(null, null);
break;
case ValidateLicenseState:
_validateLicense((state as ValidateLicenseState).data);
break;
case FetchStatusState:
await _fetchStatus((state as FetchStatusState).license);
break;
case ValidateStatusState:
_validateStatus((state as ValidateStatusState).data);
break;
case FetchLicenseState:
await _fetchLicense((state as FetchLicenseState).status);
break;
case CheckLicenseStatusState:
CheckLicenseStatusState checkLicenseStatusState =
state as CheckLicenseStatusState;
_checkLicenseStatus(
checkLicenseStatusState.license, checkLicenseStatusState.status);
break;
case RetrievePassphraseState:
await _requestPassphrase((state as RetrievePassphraseState).license);
break;
case ValidateIntegrityState:
ValidateIntegrityState validateIntegrityState =
state as ValidateIntegrityState;
await _validateIntegrity(validateIntegrityState.license,
validateIntegrityState.passphrase);
break;
case RegisterDeviceState:
RegisterDeviceState registerDeviceState =
state as RegisterDeviceState;
await _registerDevice(
registerDeviceState.documents.license, registerDeviceState.link);
break;
case ValidState:
_notifyObservers((state as ValidState).documents, null);
break;
case FailureState:
_notifyObservers(null, (state as FailureState).error);
break;
case CancelledState:
}
else if (state is ValidateLicenseState) {
_validateLicense(state.data);
}
else if (state is FetchStatusState) {
await _fetchStatus(state.license);
}
else if (state is ValidateStatusState) {
_validateStatus(state.data);
}
else if (state is FetchLicenseState) {
await _fetchLicense(state.status);
}
else if (state is CheckLicenseStatusState) {
_checkLicenseStatus(state.license, state.status);
}
else if (state is RetrievePassphraseState) {
await _requestPassphrase(state.license);
}
else if (state is ValidateIntegrityState) {
await _validateIntegrity(state.license, state.passphrase);
}
else if (state is RegisterDeviceState) {
await _registerDevice(state.documents.license, state.link);
}
else if (state is ValidState) {
_notifyObservers(state.documents, null);
}
else if (state is FailureState) {
_notifyObservers(null, state.error);
}
else if (state is CancelledState) {
_notifyObservers(null, null);
break;
}
} on Exception catch (error, stacktrace) {
_log("LicenseValidation._handle ERROR: $state",
Expand Down Expand Up @@ -277,8 +263,8 @@ class LicenseValidation {
void _checkLicenseStatus(LicenseDocument license, StatusDocument? status) {
LicenseStatus? error;
DateTime now = DateTime.now();
DateTime start = license.rights.start ?? now;
DateTime end = license.rights.end ?? now;
DateTime start = license.rights?.start ?? now;
DateTime end = license.rights?.end ?? now;
if (start.isAfter(now) || now.isAfter(end)) {
if (status != null) {
DateTime? date = status.statusUpdated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,12 @@ class LicenseValidationStateMachine {
})
..state<CancelledState>((b) {})
..onTransition((t) {
switch(t.value) {
case Valid:
if (t.value is Valid) {
_log("validTransition: ${t.value}");
licenseValidation.state = t.value.toState;
case Invalid:
_log("invalidTransition: ${t.value}");
}
});
else if (t.value is Invalid) {
_log("invalidTransition: ${t.value}");
}});
});
}
5 changes: 2 additions & 3 deletions components/lcp/lib/license/model/license_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class LicenseDocument {
/// Used to associate the License Document with resources that are not
/// locally available.
final Links _links;
final Rights rights;
final Rights? rights;

/// The user owning the License.
final User user;
Expand Down Expand Up @@ -122,9 +122,8 @@ class LicenseDocument {
throw Exception(
LcpError.errorDescription(LcpErrorCase.publicationLinkNotFound));
}
// TODO What to do if user or rights is null? Can it happen?
return LicenseDocument._(id, issued, updated, provider, encryption, links,
rights!, user!, signature, jsonObject, text, data);
rights, user!, signature, jsonObject, text, data);
}

/// Returns the first link containing the given rel.
Expand Down
2 changes: 1 addition & 1 deletion components/lcp/lib/material_renew_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MaterialRenewListener implements RenewListener {
if (license == null) {
return DateTime.now();
}
DateTime start = (license!.license.rights.end ?? DateTime.now());
DateTime start = (license!.license.rights?.end ?? DateTime.now());
DateTime end = maximumDate ?? DateTime.now().add(const Duration(days: 365));
return await showDatePicker(
context: context,
Expand Down
4 changes: 2 additions & 2 deletions components/lcp/lib/persistence/licenses.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class Licenses implements DeviceRepository, LicensesRepository {
LicensesTable.name,
{
LicensesTable.id: license.id,
LicensesTable.printsleft: license.rights.print,
LicensesTable.copiesleft: license.rights.copy,
LicensesTable.printsleft: license.rights?.print,
LicensesTable.copiesleft: license.rights?.copy,
},
conflictAlgorithm: ConflictAlgorithm.replace);
}
Expand Down
12 changes: 6 additions & 6 deletions components/lcp/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.3.0'
flutter: '>=3.10.0'

dependencies:
flutter:
Expand All @@ -15,11 +15,11 @@ dependencies:
dartx: ^1.2.0
device_info_plus: ^9.1.1
dfunc: ^0.9.0
ffi: ^2.1.0
ffi: 2.1.0
fimber: ^0.7.0
flutter_archive: ^5.0.0
flutter_archive: ^6.0.0
mno_fsm: ^0.2.3
path_provider: ^2.1.1
path_provider: ^2.1.2
shared_preferences: ^2.2.2
sqflite: ^2.3.0
universal_io: ^2.2.2
Expand All @@ -32,12 +32,12 @@ dependencies:
path: ../shared

dependency_overrides:
intl: ^0.18.1 # multiple_localization 0.3.0 requires intl 0.17.0
intl: ^0.19.0 # multiple_localization 0.3.0 requires intl 0.17.0
meta: ^1.11.0 # mno_shared 0.1.3 requires meta 1.9.1
collection: ^1.18.0 # universal_io 2.2.1 requires it

dev_dependencies:
test: ^1.24.9
test: ^1.25.1
lints: ^3.0.0

assets:
Expand Down
2 changes: 1 addition & 1 deletion components/navigator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.3.0'
flutter: '>=3.10.0'

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class FetcherRequestHandler extends RequestHandler {
///
/// A [transformData] parameter is optional.
FetcherRequestHandler(this.publication, this.viewportWidthGetter,
{List<String> googleFonts = const []})
: _htmlInjector = HtmlInjector(publication, viewportWidthGetter,
{List<String> googleFonts = const [], HtmlInjector? htmlInjector})
: _htmlInjector = htmlInjector ?? HtmlInjector(publication, viewportWidthGetter,
googleFonts: googleFonts);

Fetcher get _fetcher => publication.fetcher;
Expand Down
2 changes: 1 addition & 1 deletion components/server/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish_to: none

environment:
sdk: '>=3.0.0 <4.0.0'
flutter: '>=3.3.0'
flutter: '>=3.10.0'

dependencies:
flutter:
Expand Down
6 changes: 4 additions & 2 deletions demo-app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
namespace "com.mantano.iridium.app"

compileSdkVersion 34

sourceSets {
Expand All @@ -38,9 +40,9 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.mantano.iridium.IridiumApp"
applicationId "com.mantano.iridium.app"
minSdkVersion 23
targetSdkVersion 33
targetSdkVersion 34
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion demo-app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish_to: none

environment:
sdk: '>=2.18.0 <4.0.0'
flutter: '>=3.3.0'
flutter: '>=3.10.0'

dependencies:
flutter:
Expand Down
2 changes: 1 addition & 1 deletion reader_widget/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import 'package:example/utils/utils.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_fimber/flutter_fimber.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:iridium_reader_widget/views/viewers/epub_screen.dart';
import 'package:mno_webview/webview.dart';
import 'package:universal_io/io.dart' hide Link;

Future<void> main() async {
Expand Down
2 changes: 1 addition & 1 deletion reader_widget/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ version: 1.0.0+1

environment:
sdk: ">=3.0.0 <4.0.0"
flutter: '>=3.3.0'
flutter: '>=3.10.0'

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
Expand Down
Loading

0 comments on commit 7327f5f

Please sign in to comment.