Skip to content

Commit

Permalink
wip - autofill save repetition bug
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Aug 31, 2023
1 parent 8a411eb commit 414641b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
35 changes: 33 additions & 2 deletions lib/cubit/autofill_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:bloc/bloc.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter_autofill_service/flutter_autofill_service.dart';
import 'package:kdbx/kdbx.dart';
import 'package:keevault/logging/logger.dart';
import 'package:meta/meta.dart';
import 'package:collection/collection.dart';

import '../config/platform.dart';
Expand Down Expand Up @@ -48,6 +48,8 @@ class AutofillCubit extends Cubit<AutofillState> {
return;
}

// saveRequested can remain true for a long time after initial save request was made.
// Once user confirms save, autofill service will clear the intent data so then will become false.
if (saveRequested) {
if (state is AutofillSaving || state is AutofillSaved) {
// After launching with a save intent, if we then restore after the save
Expand All @@ -59,8 +61,37 @@ class AutofillCubit extends Cubit<AutofillState> {
//
// A first simple attempt at a solution is below
// See https://github.com/kee-org/keevault2/issues/9 for next steps
final newRequest = (state as AutofillModeActive).androidMetadata.toJson() != androidMetadata!.toJson();
final t1 = (state as AutofillModeActive).androidMetadata; //.toJson();
final t2 = androidMetadata!; //.toJson();
// androidMetadata.
// l.w(MapEquality().equals(t1, t2));

// var equality = DeepCollectionEquality((a, b) {
// // Custom equality function that ignores hashcodes
// if (a is AutofillWebDomain && b is AutofillWebDomain) {
// return a.domain == b.domain;
// }
// return DeepCollectionEquality().equals(a, b);
// });
final e1 = setEquals(t1.webDomains, t2.webDomains);
final e2 = setEquals(t1.packageNames, t2.packageNames);
final e3 = t1.saveInfo == t2.saveInfo;

l.w(e1);
l.w(e2);
l.w(e3);
// l.w(t1);
// l.w(t2);
// final newRequest = (state as AutofillModeActive).androidMetadata.toJson() != androidMetadata!.toJson();
final newRequest = !(e1 && e2 && e3);
l.e('request is new? $newRequest');
// always true.
//TODO: mapEquals sort of thing?
// if saved and unchanged, maybe reset state to available?
if (!newRequest) {
if (state is AutofillSaved) {
emit(AutofillAvailable(enabled));
}
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,10 @@ packages:
description:
path: "."
ref: master
resolved-ref: b623282b8b0bfeb6f57c25be84243171a2b4c0a6
resolved-ref: "7d4e54bc430b22a87d4a30d8fb0f70d5ac243197"
url: "https://github.com/kee-org/flutter_autofill_service.git"
source: git
version: "0.17.0"
version: "0.17.1"
flutter_bloc:
dependency: "direct main"
description:
Expand Down

0 comments on commit 414641b

Please sign in to comment.