Skip to content
Open
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
48 changes: 31 additions & 17 deletions mobile/apps/auth/lib/ui/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class _HomePageState extends State<HomePage> {
List<String> tags = [];
List<Code> _filteredCodes = [];
StreamSubscription<CodesUpdatedEvent>? _streamSubscription;
StreamSubscription<String>? _deepLinkSubscription;
StreamSubscription<TriggerLogoutEvent>? _triggerLogoutEvent;
StreamSubscription<IconsChangedEvent>? _iconsChangedEvent;
StreamSubscription<MultiSelectActionRequestedEvent>?
Expand Down Expand Up @@ -1191,6 +1192,7 @@ class _HomePageState extends State<HomePage> {
@override
void dispose() {
_streamSubscription?.cancel();
_deepLinkSubscription?.cancel();
_triggerLogoutEvent?.cancel();
_iconsChangedEvent?.cancel();
_multiSelectActionSubscription?.cancel();
Expand Down Expand Up @@ -1865,29 +1867,26 @@ class _HomePageState extends State<HomePage> {
}
}

late final AppLinks _appLinks = AppLinks();

Future<bool> _initDeepLinks() async {
// Platform messages may fail, so we use a try/catch PlatformException.
final appLinks = AppLinks();
bool hadInitialLink = false;
try {
String? initialLink;
initialLink = await appLinks.getInitialLinkString();
// Parse the link and warn the user, if it is not correct,
// but keep in mind it could be `null`.
final initialLink = await _appLinks.getInitialLinkString();
if (initialLink != null) {
_handleDeeplink(context, initialLink);
return true;
hadInitialLink = true;
} else {
_logger.info("No initial link received.");
}
} on PlatformException {
// Handle exception by warning the user their action did not succeed
// return?
_logger.severe("PlatformException thrown while getting initial link");
}

// Attach a listener to the stream
// Always attach a listener for future deep links
if (!kIsWeb && !Platform.isLinux) {
appLinks.stringLinkStream.listen(
_deepLinkSubscription = _appLinks.stringLinkStream.listen(
(link) {
_handleDeeplink(context, link);
},
Expand All @@ -1896,7 +1895,7 @@ class _HomePageState extends State<HomePage> {
},
);
}
return false;
return hadInitialLink;
}

int lastScanTime = DateTime.now().millisecondsSinceEpoch - 1000;
Expand All @@ -1908,12 +1907,27 @@ class _HomePageState extends State<HomePage> {
if (!(isAccountConfigured || isOfflineModeEnabled) || link == null) {
return;
}
if (DateTime.now().millisecondsSinceEpoch - lastScanTime < 1000) {
_logger.info("Ignoring potential event for same deeplink");
return;
}
lastScanTime = DateTime.now().millisecondsSinceEpoch;
if (mounted && link.toLowerCase().startsWith("otpauth://")) {
final lowerLink = link.toLowerCase();
if (mounted && (lowerLink.startsWith("ente-auth://") || lowerLink.startsWith("enteauth://"))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about ente-auth:// pattern, any reason you included it here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw ente-auth:// pattern (with a -) is registered in AndroidManifest.xml:

<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="ente-auth"/>
</intent-filter>

along with the enteauth:// pattern (without a -):

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="enteauth" />
</intent-filter>

Let me know if I should remove the one with the -.

try {
final uri = Uri.parse(link);
if (uri.host != "search") return;
final searchQuery = uri.queryParameters['query'];
if (searchQuery != null && searchQuery.isNotEmpty) {
_showSearchBox = true;
_textController.text = searchQuery;
_searchText = searchQuery;
_applyFilteringAndRefresh();
}
} catch (e) {
_logger.warning("Malformed ente-auth deep link: $link", e);
}
} else if (mounted && lowerLink.startsWith("otpauth://")) {
if (DateTime.now().millisecondsSinceEpoch - lastScanTime < 1000) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to extract this above the if-else ladder, so it applies to both enteauth and otpauth

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback!

I skipped the throttling only for ente-auth://search links on purpose, because it's OK to repeat a search query (it's idempotent, as it just filters the list).

However, the throttle already existed for OTP code additions (with otpauth:// links), I assume this is because otputh:// links add elements to the list, so we wanted to debounce that logic.

If I moved the throttle above the if-else, it adds an unnecessary delay to search deep links.

_logger.info("Ignoring potential event for same deeplink");
return;
}
lastScanTime = DateTime.now().millisecondsSinceEpoch;
try {
final newCode = Code.fromOTPAuthUrl(link);
getNextTotp(newCode);
Expand Down