-
-
Notifications
You must be signed in to change notification settings - Fork 539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] Pinning and Tags #1541
Merged
[FEAT] Pinning and Tags #1541
Changes from 3 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
b516bc8
feat: add pinning
prateekmedia 5cc25c6
fix: sort codes correctly based on pinning status
prateekmedia 5f921e7
fix: go back to otpauth instead of converting to json
prateekmedia 38b0046
fix: remove toString and update toExportFormat code
prateekmedia e26c817
fix: parsing of rawData and sorting while fetching codes
prateekmedia a22f38c
fix: add toasts for pin, update card ui, add pin svgs
prateekmedia adbb8f3
fix: encoding and decoding logic
prateekmedia 17ad0a9
fix: disable privacy screen on debug mode
prateekmedia 12635be
fix: complete pinned design
prateekmedia 5a18fe3
feat: tags selection by text field
prateekmedia 35672ee
feat: tags ui and logic complete
prateekmedia f065481
chore: add doc
prateekmedia 77b30ef
fix: complete edit and delete tag logic
prateekmedia c9c7f0c
fix: width of popup menu button
prateekmedia e7ed34b
fix: update tag colors
prateekmedia ee5362a
fix: unselect tag on tap on selected one
prateekmedia 8d096ec
chore: bump version
prateekmedia 49c0295
fix: use Future.wait for edit and delete tag
prateekmedia e4b2bf0
chore: bump packages
prateekmedia ab93eb4
fix: bump gradlew files
prateekmedia 25fb9cf
fix: add new ente button
prateekmedia b860d3a
fix: push theme for button
prateekmedia c6084c6
fix: add code error widget
prateekmedia 8370d2a
fix: try to fix button tint
prateekmedia 838983e
fix: logics and ui (button, error code)
prateekmedia d1a15b1
fix: logics and ui (button, error code)
prateekmedia b5d49af
fix(auth): errors in merge
prateekmedia 270f1f1
chore(auth): update pubspec.lock
prateekmedia 612ed18
fix(auth): border radius of gradient_button.dart
prateekmedia 45eda72
fix(auth): remove boxShadow from gradient_button.dart
prateekmedia 68f0a1d
fix(auth): add mounted check for tags
prateekmedia 62441b8
fix(auth): don't make app unusable on error
prateekmedia 54f6f86
fix(auth): code display for new codes
prateekmedia aa5c41b
fix(auth): toast on desktop
prateekmedia 7628991
fix(auth): revert remove linesplitter
prateekmedia 851c04f
fix(auth): don't export display
prateekmedia 3c79325
chore(auth): rename toExportFormat
prateekmedia ef318d8
fix(auth): move color to ente color scheme
prateekmedia d88a7ec
fix(auth): incorrect text during export
prateekmedia e1239a6
fix(auth): use global logger
prateekmedia 0810967
fix(auth): store error in Code
prateekmedia a9d63a1
fix(auth): separate fedora workflow
prateekmedia f3c05d2
fix(auth): improve workflow
prateekmedia ea37b5a
fix: don't try to publish aab in fedora workflow
prateekmedia 639ef13
fix[auth]: update dependencies of appimage
prateekmedia 35aa8fc
fix(auth): workflow for fedora
prateekmedia 1b84410
fix(cut): save button getting cut
prateekmedia da70ba7
feat(auth): add new icons
prateekmedia 7c43908
fix(auth): revert manifest
prateekmedia 6496eea
fix(auth): ignore files
prateekmedia 5ef92e3
fix(auth): remove all codes
prateekmedia 36685f4
fix(auth): store all colors in EnteColorScheme
prateekmedia ea72300
fix(auth): encode ',' as %2C for correctly importing later on
prateekmedia 10e717a
fix(auth): update splash
prateekmedia 7a64371
fix(auth): don't package splash with app
prateekmedia 4040525
fix(auth): update splash screen
prateekmedia 297c3af
fix(auth): update dark mode splash
prateekmedia 4abdc62
fix(auth): update light mode splash
prateekmedia 5195aaa
[auth] Add code display test
ua741 9e11377
fix(auth): don't append codeDisplay twice
prateekmedia 2bc4081
fix(auth): splash icon
prateekmedia b714392
fix(auth): update parse error message
prateekmedia d762bf0
fix(auth): revert demo code
prateekmedia eb7d6d4
fix(auth): update getAllTags logic
prateekmedia 47d9d3c
Merge branch 'main' into auth-v3
ua741 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:ente_auth/models/code_display.dart'; | ||
import 'package:ente_auth/utils/totp_util.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
class Code { | ||
static const defaultDigits = 6; | ||
|
@@ -12,10 +16,16 @@ class Code { | |
final String secret; | ||
final Algorithm algorithm; | ||
final Type type; | ||
|
||
/// otpauth url in the code | ||
final String rawData; | ||
final int counter; | ||
bool? hasSynced; | ||
|
||
final CodeDisplay? display; | ||
|
||
bool get isPinned => display?.pinned ?? false; | ||
|
||
Code( | ||
this.account, | ||
this.issuer, | ||
|
@@ -27,6 +37,7 @@ class Code { | |
this.counter, | ||
this.rawData, { | ||
this.generatedID, | ||
this.display, | ||
}); | ||
|
||
Code copyWith({ | ||
|
@@ -38,6 +49,7 @@ class Code { | |
Algorithm? algorithm, | ||
Type? type, | ||
int? counter, | ||
CodeDisplay? display, | ||
}) { | ||
final String updateAccount = account ?? this.account; | ||
final String updateIssuer = issuer ?? this.issuer; | ||
|
@@ -47,6 +59,7 @@ class Code { | |
final Algorithm updatedAlgo = algorithm ?? this.algorithm; | ||
final Type updatedType = type ?? this.type; | ||
final int updatedCounter = counter ?? this.counter; | ||
final CodeDisplay? updatedDisplay = display ?? this.display; | ||
|
||
return Code( | ||
updateAccount, | ||
|
@@ -59,6 +72,7 @@ class Code { | |
updatedCounter, | ||
"otpauth://${updatedType.name}/$updateIssuer:$updateAccount?algorithm=${updatedAlgo.name}&digits=$updatedDigits&issuer=$updateIssuer&period=$updatePeriod&secret=$updatedSecret${updatedType == Type.hotp ? "&counter=$updatedCounter" : ""}", | ||
generatedID: generatedID, | ||
display: updatedDisplay, | ||
); | ||
} | ||
|
||
|
@@ -80,7 +94,7 @@ class Code { | |
); | ||
} | ||
|
||
static Code fromRawData(String rawData) { | ||
static Code fromOTPAuthUrl(String rawData, {CodeDisplay? display}) { | ||
Uri uri = Uri.parse(rawData); | ||
try { | ||
return Code( | ||
|
@@ -93,12 +107,13 @@ class Code { | |
_getType(uri), | ||
_getCounter(uri), | ||
rawData, | ||
display: CodeDisplay.fromUri(uri), | ||
); | ||
} catch (e) { | ||
// if account name contains # without encoding, | ||
// rest of the url are treated as url fragment | ||
if (rawData.contains("#")) { | ||
return Code.fromRawData(rawData.replaceAll("#", '%23')); | ||
return Code.fromOTPAuthUrl(rawData.replaceAll("#", '%23')); | ||
} else { | ||
rethrow; | ||
} | ||
|
@@ -122,6 +137,25 @@ class Code { | |
} | ||
} | ||
|
||
static Code fromExportJson(Map rawJson) { | ||
try { | ||
Code resultCode = Code.fromOTPAuthUrl( | ||
rawJson['rawData'], | ||
display: CodeDisplay.fromJson(rawJson['display']), | ||
); | ||
return resultCode; | ||
} catch (e) { | ||
debugPrint("Failed to parse code from export json $e"); | ||
rethrow; | ||
} | ||
} | ||
|
||
String toExportFormat() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return Uri.parse( | ||
rawData + "&codeDisplay=" + jsonEncode(display ?? CodeDisplay()), | ||
).toString(); | ||
} | ||
|
||
static String _getIssuer(Uri uri) { | ||
try { | ||
if (uri.queryParameters.containsKey("issuer")) { | ||
|
@@ -184,7 +218,7 @@ class Code { | |
} | ||
|
||
static Type _getType(Uri uri) { | ||
if (uri.host == "totp") { | ||
if (uri.host == "totp" || uri.host == "steam") { | ||
return Type.totp; | ||
} else if (uri.host == "hotp") { | ||
return Type.hotp; | ||
|
@@ -204,7 +238,8 @@ class Code { | |
other.secret == secret && | ||
other.counter == counter && | ||
other.type == type && | ||
other.rawData == rawData; | ||
other.rawData == rawData && | ||
other.display == display; | ||
} | ||
|
||
@override | ||
|
@@ -216,7 +251,13 @@ class Code { | |
secret.hashCode ^ | ||
type.hashCode ^ | ||
counter.hashCode ^ | ||
rawData.hashCode; | ||
rawData.hashCode ^ | ||
display.hashCode; | ||
} | ||
|
||
@override | ||
String toString() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not having a |
||
return 'Code(account: $account, issuer: $issuer, digits: $digits, period: $period, secret: $secret, algorithm: $algorithm, type: $type, counter: $counter, rawData: $rawData, display: $display)'; | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'dart:convert'; | ||
|
||
/// Used to store the display settings of a code. | ||
class CodeDisplay { | ||
final bool pinned; | ||
final bool trashed; | ||
final int lastUsedAt; | ||
final int tapCount; | ||
final List<String> tags; | ||
|
||
CodeDisplay({ | ||
this.pinned = false, | ||
this.trashed = false, | ||
this.lastUsedAt = 0, | ||
this.tapCount = 0, | ||
this.tags = const [], | ||
}); | ||
|
||
// copyWith | ||
CodeDisplay copyWith({ | ||
bool? pinned, | ||
bool? trashed, | ||
int? lastUsedAt, | ||
int? tapCount, | ||
List<String>? tags, | ||
}) { | ||
final bool updatedPinned = pinned ?? this.pinned; | ||
final bool updatedTrashed = trashed ?? this.trashed; | ||
final int updatedLastUsedAt = lastUsedAt ?? this.lastUsedAt; | ||
final int updatedTapCount = tapCount ?? this.tapCount; | ||
final List<String> updatedTags = tags ?? this.tags; | ||
|
||
return CodeDisplay( | ||
pinned: updatedPinned, | ||
trashed: updatedTrashed, | ||
lastUsedAt: updatedLastUsedAt, | ||
tapCount: updatedTapCount, | ||
tags: updatedTags, | ||
); | ||
} | ||
|
||
factory CodeDisplay.fromJson(Map<String, dynamic>? json) { | ||
if (json == null) { | ||
return CodeDisplay(); | ||
} | ||
return CodeDisplay( | ||
pinned: json['pinned'] ?? false, | ||
trashed: json['trashed'] ?? false, | ||
lastUsedAt: json['lastUsedAt'] ?? 0, | ||
tapCount: json['tapCount'] ?? 0, | ||
); | ||
} | ||
|
||
static CodeDisplay? fromUri(Uri uri) { | ||
if (!uri.queryParameters.containsKey("codeDisplay")) return null; | ||
final String codeDisplay = uri.queryParameters['codeDisplay']!; | ||
final decodedDisplay = jsonDecode(codeDisplay); | ||
|
||
return CodeDisplay.fromJson(decodedDisplay); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'pinned': pinned, | ||
'trashed': trashed, | ||
'lastUsedAt': lastUsedAt, | ||
'tapCount': tapCount, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: user logger.severe instead of debugPrint, also let's log stacktrace?