Skip to content

Save encoded URI for ACX DevTools #1890

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

Merged
merged 2 commits into from
Jan 14, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ library cross_extension_communication;
import 'package:js/js.dart';

import 'chrome_api.dart';
import 'data_types.dart';
import 'debug_session.dart';
import 'logger.dart';
import 'storage.dart';
Expand Down Expand Up @@ -85,7 +84,7 @@ void _respondWithChromeResult(Object? chromeResult, Function sendResponse) {
}

void _respondWithEncodedUri(int tabId, Function sendResponse) async {
final encodedUri = await fetchStorageObject<EncodedUri>(
final encodedUri = await fetchStorageObject<String>(
type: StorageObject.encodedUri, tabId: tabId);
sendResponse(encodedUri ?? '');
}
Expand Down
1 change: 0 additions & 1 deletion dwds/debug_extension_mv3/web/data_serializers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ part 'data_serializers.g.dart';
DevToolsOpener,
DevToolsUrl,
DevToolsRequest,
EncodedUri,
ExtensionEvent,
ExtensionRequest,
ExtensionResponse,
Expand Down
1 change: 0 additions & 1 deletion dwds/debug_extension_mv3/web/data_serializers.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions dwds/debug_extension_mv3/web/data_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,6 @@ abstract class DevToolsOpener
bool get newWindow;
}

// TODO(elliette): Standardize on uri or url here and across DWDS, instead of a
// combination of both.
abstract class EncodedUri implements Built<EncodedUri, EncodedUriBuilder> {
static Serializer<EncodedUri> get serializer => _$encodedUriSerializer;

factory EncodedUri([Function(EncodedUriBuilder) updates]) = _$EncodedUri;

EncodedUri._();

String get uri;
}

abstract class DevToolsUrl implements Built<DevToolsUrl, DevToolsUrlBuilder> {
static Serializer<DevToolsUrl> get serializer => _$devToolsUrlSerializer;

Expand Down
118 changes: 0 additions & 118 deletions dwds/debug_extension_mv3/web/data_types.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions dwds/debug_extension_mv3/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ void _routeDwdsEvent(String eventData, SocketClient client, int tabId) {
if (message.method == 'dwds.devtoolsUri') {
_openDevTools(message.params, dartAppTabId: tabId);
}
if (message.method == 'dwds.encodedUri') {
setStorageObject(
type: StorageObject.encodedUri,
value: message.params,
tabId: tabId,
);
}
}
}

Expand Down
11 changes: 8 additions & 3 deletions dwds/debug_extension_mv3/web/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Future<bool> setStorageObject<T>({
void Function()? callback,
}) {
final storageKey = _createStorageKey(type, tabId);
final json = jsonEncode(serializers.serialize(value));
final json =
value is String ? value : jsonEncode(serializers.serialize(value));
final storageObj = <String, String>{storageKey: json};
final completer = Completer<bool>();
final storageArea = _getStorageArea(type.persistance);
Expand Down Expand Up @@ -73,9 +74,13 @@ Future<T?> fetchStorageObject<T>({required StorageObject type, int? tabId}) {
debugWarn('Does not exist.', prefix: storageKey);
completer.complete(null);
} else {
final value = serializers.deserialize(jsonDecode(json)) as T;
debugLog('Fetched: $json', prefix: storageKey);
completer.complete(value);
if (T == String) {
completer.complete(json as T);
} else {
final value = serializers.deserialize(jsonDecode(json)) as T;
completer.complete(value);
}
}
}));
return completer.future;
Expand Down