Skip to content

Commit

Permalink
Add DecryptPolicy settings
Browse files Browse the repository at this point in the history
See #33
  • Loading branch information
amake committed Dec 24, 2023
1 parent 8c26533 commit 72b09bc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/src/components/view_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ class InheritedViewSettings extends InheritedWidget {
_update(data.copyWith(saveChangesPolicy: value));
}

DecryptPolicy get decryptPolicy => data.decryptPolicy;
void setDecryptPolicy(DecryptPolicy value, {bool persist = false}) {
if (persist) {
_prefs.setDecryptPolicy(value);
}
_update(data.copyWith(decryptPolicy: value));
}

bool get fullWidth => data.fullWidth;
set fullWidth(bool value) => _update(data.copyWith(fullWidth: value));

Expand All @@ -124,6 +132,7 @@ class ViewSettingsData {
prefs.remoteImagesPolicy ?? kDefaultRemoteImagesPolicy,
localLinksPolicy: prefs.localLinksPolicy ?? kDefaultLocalLinksPolicy,
saveChangesPolicy: prefs.saveChangesPolicy ?? kDefaultSaveChangesPolicy,
decryptPolicy: prefs.decryptPolicy ?? kDefaultDecryptPolicy,
fullWidth: prefs.fullWidth ?? kDefaultFullWidth,
);
}
Expand All @@ -136,6 +145,7 @@ class ViewSettingsData {
required this.remoteImagesPolicy,
required this.localLinksPolicy,
required this.saveChangesPolicy,
required this.decryptPolicy,
required this.fullWidth,
});

Expand All @@ -146,6 +156,7 @@ class ViewSettingsData {
final RemoteImagesPolicy remoteImagesPolicy;
final LocalLinksPolicy localLinksPolicy;
final SaveChangesPolicy saveChangesPolicy;
final DecryptPolicy decryptPolicy;
final bool fullWidth;

ViewSettingsData copyWith({
Expand All @@ -156,6 +167,7 @@ class ViewSettingsData {
RemoteImagesPolicy? remoteImagesPolicy,
LocalLinksPolicy? localLinksPolicy,
SaveChangesPolicy? saveChangesPolicy,
DecryptPolicy? decryptPolicy,
bool? fullWidth,
}) =>
ViewSettingsData(
Expand All @@ -166,6 +178,7 @@ class ViewSettingsData {
remoteImagesPolicy: remoteImagesPolicy ?? this.remoteImagesPolicy,
localLinksPolicy: localLinksPolicy ?? this.localLinksPolicy,
saveChangesPolicy: saveChangesPolicy ?? this.saveChangesPolicy,
decryptPolicy: decryptPolicy ?? this.decryptPolicy,
fullWidth: fullWidth ?? this.fullWidth,
);

Expand All @@ -179,6 +192,7 @@ class ViewSettingsData {
remoteImagesPolicy == other.remoteImagesPolicy &&
localLinksPolicy == other.localLinksPolicy &&
saveChangesPolicy == other.saveChangesPolicy &&
decryptPolicy == other.decryptPolicy &&
fullWidth == other.fullWidth;

@override
Expand All @@ -190,6 +204,7 @@ class ViewSettingsData {
remoteImagesPolicy,
localLinksPolicy,
saveChangesPolicy,
decryptPolicy,
fullWidth,
);
}
31 changes: 31 additions & 0 deletions lib/src/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ enum LocalLinksPolicy { deny, ask }

enum SaveChangesPolicy { allow, deny, ask }

enum DecryptPolicy { deny, ask }

const kDefaultFontFamily = 'Fira Code';
const kDefaultTextScale = 1.0;
const String? kDefaultQueryString = null;
const kDefaultReaderMode = false;
const kDefaultRemoteImagesPolicy = RemoteImagesPolicy.ask;
const kDefaultLocalLinksPolicy = LocalLinksPolicy.ask;
const kDefaultSaveChangesPolicy = SaveChangesPolicy.ask;
const kDefaultDecryptPolicy = DecryptPolicy.ask;
const kDefaultFullWidth = false;

const kMaxRecentFiles = 10;
Expand All @@ -27,6 +30,7 @@ const _kReaderModeKey = 'reader_mode';
const _kRemoteImagesPolicyKey = 'remote_images_policy';
const _kLocalLinksPolicyKey = 'local_links_policy';
const _kSaveChangesPolicyKey = 'save_changes_policy';
const _kDecryptPolicyKey = 'decrypt_policy';
const _kRecentFilesJsonKey = 'recent_files_json';
const _kAccessibleDirectoriesKey = 'accessible_directories_json';
const _kFullWidthKey = 'full_width';
Expand Down Expand Up @@ -90,6 +94,12 @@ class Preferences extends InheritedWidget {
Future<bool> setSaveChangesPolicy(SaveChangesPolicy? value) =>
_setOrRemove(_kSaveChangesPolicyKey, value.persistableString);

DecryptPolicy? get decryptPolicy =>
DecryptPolicyPersistence.fromString(_prefs.getString(_kDecryptPolicyKey));

Future<bool> setDecryptPolicy(DecryptPolicy? value) =>
_setOrRemove(_kDecryptPolicyKey, value.persistableString);

/// List of identifiers
List<String> get accessibleDirs =>
_prefs.getStringList(_kAccessibleDirectoriesKey) ?? [];
Expand Down Expand Up @@ -228,3 +238,24 @@ extension SaveChangesPolicyPersistence on SaveChangesPolicy? {
const _kSaveChangesPolicyAllow = 'save_changes_policy_allow';
const _kSaveChangesPolicyDeny = 'save_changes_policy_deny';
const _kSaveChangesPolicyAsk = 'save_changes_policy_ask';

extension DecryptPolicyPersistence on DecryptPolicy? {
static DecryptPolicy? fromString(String? value) {
switch (value) {
case _kDecryptPolicyDeny:
return DecryptPolicy.deny;
case _kDecryptPolicyAsk:
return DecryptPolicy.ask;
}
return null;
}

String? get persistableString => switch (this) {
DecryptPolicy.deny => _kDecryptPolicyDeny,
DecryptPolicy.ask => _kDecryptPolicyAsk,
null => null,
};
}

const _kDecryptPolicyDeny = 'decrypt_policy_deny';
const _kDecryptPolicyAsk = 'decrypt_policy_ask';

0 comments on commit 72b09bc

Please sign in to comment.