switch to new gecko pref api
This commit is contained in:
@@ -34,7 +34,7 @@ final class EngineBoundIntentStreamProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$engineBoundIntentStreamHash() =>
|
String _$engineBoundIntentStreamHash() =>
|
||||||
r'd47f50ee8f548fe0416b8ed01bb02adbd79b3386';
|
r'fa7c3e0277b25e8129a12feaadf39db6b65a1cd5';
|
||||||
|
|
||||||
abstract class _$EngineBoundIntentStream
|
abstract class _$EngineBoundIntentStream
|
||||||
extends $StreamNotifier<SharedContent> {
|
extends $StreamNotifier<SharedContent> {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
import 'package:copy_with_extension/copy_with_extension.dart';
|
import 'package:copy_with_extension/copy_with_extension.dart';
|
||||||
import 'package:fast_equatable/fast_equatable.dart';
|
import 'package:fast_equatable/fast_equatable.dart';
|
||||||
|
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
|
||||||
import 'package:json_annotation/json_annotation.dart';
|
import 'package:json_annotation/json_annotation.dart';
|
||||||
|
|
||||||
part 'preference_setting.g.dart';
|
part 'preference_setting.g.dart';
|
||||||
@@ -55,9 +56,9 @@ class PreferenceSetting with FastEquatable {
|
|||||||
final Object value;
|
final Object value;
|
||||||
|
|
||||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||||
final Object? actualValue;
|
final GeckoPrefValue? current;
|
||||||
|
|
||||||
bool get isActive => value == actualValue;
|
bool get isActive => value == current?.value;
|
||||||
|
|
||||||
final String? title;
|
final String? title;
|
||||||
final String? description;
|
final String? description;
|
||||||
@@ -69,7 +70,7 @@ class PreferenceSetting with FastEquatable {
|
|||||||
required this.value,
|
required this.value,
|
||||||
required this.title,
|
required this.title,
|
||||||
required this.description,
|
required this.description,
|
||||||
this.actualValue,
|
this.current,
|
||||||
this.requireUserOptIn = false,
|
this.requireUserOptIn = false,
|
||||||
this.shouldBeDefault = false,
|
this.shouldBeDefault = false,
|
||||||
});
|
});
|
||||||
@@ -82,7 +83,7 @@ class PreferenceSetting with FastEquatable {
|
|||||||
@override
|
@override
|
||||||
List<Object?> get hashParameters => [
|
List<Object?> get hashParameters => [
|
||||||
value,
|
value,
|
||||||
actualValue,
|
current,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
requireUserOptIn,
|
requireUserOptIn,
|
||||||
|
|||||||
+7
-8
@@ -80,7 +80,7 @@ abstract class _$PreferenceSettingCWProxy {
|
|||||||
|
|
||||||
PreferenceSetting description(String? description);
|
PreferenceSetting description(String? description);
|
||||||
|
|
||||||
PreferenceSetting actualValue(Object? actualValue);
|
PreferenceSetting current(GeckoPrefValue? current);
|
||||||
|
|
||||||
PreferenceSetting requireUserOptIn(bool requireUserOptIn);
|
PreferenceSetting requireUserOptIn(bool requireUserOptIn);
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ abstract class _$PreferenceSettingCWProxy {
|
|||||||
Object value,
|
Object value,
|
||||||
String? title,
|
String? title,
|
||||||
String? description,
|
String? description,
|
||||||
Object? actualValue,
|
GeckoPrefValue? current,
|
||||||
bool requireUserOptIn,
|
bool requireUserOptIn,
|
||||||
bool shouldBeDefault,
|
bool shouldBeDefault,
|
||||||
});
|
});
|
||||||
@@ -121,8 +121,7 @@ class _$PreferenceSettingCWProxyImpl implements _$PreferenceSettingCWProxy {
|
|||||||
call(description: description);
|
call(description: description);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
PreferenceSetting actualValue(Object? actualValue) =>
|
PreferenceSetting current(GeckoPrefValue? current) => call(current: current);
|
||||||
call(actualValue: actualValue);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
PreferenceSetting requireUserOptIn(bool requireUserOptIn) =>
|
PreferenceSetting requireUserOptIn(bool requireUserOptIn) =>
|
||||||
@@ -144,7 +143,7 @@ class _$PreferenceSettingCWProxyImpl implements _$PreferenceSettingCWProxy {
|
|||||||
Object? value = const $CopyWithPlaceholder(),
|
Object? value = const $CopyWithPlaceholder(),
|
||||||
Object? title = const $CopyWithPlaceholder(),
|
Object? title = const $CopyWithPlaceholder(),
|
||||||
Object? description = const $CopyWithPlaceholder(),
|
Object? description = const $CopyWithPlaceholder(),
|
||||||
Object? actualValue = const $CopyWithPlaceholder(),
|
Object? current = const $CopyWithPlaceholder(),
|
||||||
Object? requireUserOptIn = const $CopyWithPlaceholder(),
|
Object? requireUserOptIn = const $CopyWithPlaceholder(),
|
||||||
Object? shouldBeDefault = const $CopyWithPlaceholder(),
|
Object? shouldBeDefault = const $CopyWithPlaceholder(),
|
||||||
}) {
|
}) {
|
||||||
@@ -161,10 +160,10 @@ class _$PreferenceSettingCWProxyImpl implements _$PreferenceSettingCWProxy {
|
|||||||
? _value.description
|
? _value.description
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: description as String?,
|
: description as String?,
|
||||||
actualValue: actualValue == const $CopyWithPlaceholder()
|
current: current == const $CopyWithPlaceholder()
|
||||||
? _value.actualValue
|
? _value.current
|
||||||
// ignore: cast_nullable_to_non_nullable
|
// ignore: cast_nullable_to_non_nullable
|
||||||
: actualValue as Object?,
|
: current as GeckoPrefValue?,
|
||||||
requireUserOptIn:
|
requireUserOptIn:
|
||||||
requireUserOptIn == const $CopyWithPlaceholder() ||
|
requireUserOptIn == const $CopyWithPlaceholder() ||
|
||||||
requireUserOptIn == null
|
requireUserOptIn == null
|
||||||
|
|||||||
+6
-8
@@ -65,7 +65,7 @@ Future<PreferenceSettingGroup> _preferenceSettingGroup(
|
|||||||
class _PreferenceRepository extends _$PreferenceRepository {
|
class _PreferenceRepository extends _$PreferenceRepository {
|
||||||
final _prefManager = GeckoPrefService();
|
final _prefManager = GeckoPrefService();
|
||||||
// Use BehaviorSubject instead of StreamController
|
// Use BehaviorSubject instead of StreamController
|
||||||
late BehaviorSubject<Map<String, Object>> _prefSubject;
|
late BehaviorSubject<Map<String, GeckoPrefValue>> _prefSubject;
|
||||||
|
|
||||||
Future<void> _updatePrefs() async {
|
Future<void> _updatePrefs() async {
|
||||||
final prefs = await _prefManager.getAllPrefs();
|
final prefs = await _prefManager.getAllPrefs();
|
||||||
@@ -83,8 +83,8 @@ class _PreferenceRepository extends _$PreferenceRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Raw<Stream<Map<String, Object>>> build() {
|
Raw<Stream<Map<String, GeckoPrefValue>>> build() {
|
||||||
_prefSubject = BehaviorSubject<Map<String, Object>>();
|
_prefSubject = BehaviorSubject<Map<String, GeckoPrefValue>>();
|
||||||
|
|
||||||
ref.onDispose(() async {
|
ref.onDispose(() async {
|
||||||
await _prefSubject.close();
|
await _prefSubject.close();
|
||||||
@@ -157,10 +157,8 @@ class UnifiedPreferenceSettingsRepository
|
|||||||
groupName,
|
groupName,
|
||||||
group.copyWith.settings(
|
group.copyWith.settings(
|
||||||
group.settings.map(
|
group.settings.map(
|
||||||
(prefName, setting) => MapEntry(
|
(prefName, setting) =>
|
||||||
prefName,
|
MapEntry(prefName, setting.copyWith.current(prefs[prefName])),
|
||||||
setting.copyWith.actualValue(prefs[prefName]),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -234,7 +232,7 @@ class PreferenceSettingsGroupRepository
|
|||||||
yield* prefStream.map(
|
yield* prefStream.map(
|
||||||
(prefs) => _statelessSettingGroup!.copyWith.settings(
|
(prefs) => _statelessSettingGroup!.copyWith.settings(
|
||||||
_statelessSettingGroup!.settings.map(
|
_statelessSettingGroup!.settings.map(
|
||||||
(key, value) => MapEntry(key, value.copyWith.actualValue(prefs[key])),
|
(key, value) => MapEntry(key, value.copyWith.current(prefs[key])),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
+14
-15
@@ -229,7 +229,7 @@ final class _PreferenceRepositoryProvider
|
|||||||
extends
|
extends
|
||||||
$NotifierProvider<
|
$NotifierProvider<
|
||||||
_PreferenceRepository,
|
_PreferenceRepository,
|
||||||
Raw<Stream<Map<String, Object>>>
|
Raw<Stream<Map<String, GeckoPrefValue>>>
|
||||||
> {
|
> {
|
||||||
const _PreferenceRepositoryProvider._()
|
const _PreferenceRepositoryProvider._()
|
||||||
: super(
|
: super(
|
||||||
@@ -250,22 +250,21 @@ final class _PreferenceRepositoryProvider
|
|||||||
_PreferenceRepository create() => _PreferenceRepository();
|
_PreferenceRepository create() => _PreferenceRepository();
|
||||||
|
|
||||||
/// {@macro riverpod.override_with_value}
|
/// {@macro riverpod.override_with_value}
|
||||||
Override overrideWithValue(Raw<Stream<Map<String, Object>>> value) {
|
Override overrideWithValue(Raw<Stream<Map<String, GeckoPrefValue>>> value) {
|
||||||
return $ProviderOverride(
|
return $ProviderOverride(
|
||||||
origin: this,
|
origin: this,
|
||||||
providerOverride: $SyncValueProvider<Raw<Stream<Map<String, Object>>>>(
|
providerOverride:
|
||||||
value,
|
$SyncValueProvider<Raw<Stream<Map<String, GeckoPrefValue>>>>(value),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _$_preferenceRepositoryHash() =>
|
String _$_preferenceRepositoryHash() =>
|
||||||
r'b2b7f75b3d30842b3006bb18af89f7ff90ba4ce7';
|
r'9a98b95677d4070def531ea1e5b900892045a1ef';
|
||||||
|
|
||||||
abstract class _$PreferenceRepository
|
abstract class _$PreferenceRepository
|
||||||
extends $Notifier<Raw<Stream<Map<String, Object>>>> {
|
extends $Notifier<Raw<Stream<Map<String, GeckoPrefValue>>>> {
|
||||||
Raw<Stream<Map<String, Object>>> build();
|
Raw<Stream<Map<String, GeckoPrefValue>>> build();
|
||||||
@$mustCallSuper
|
@$mustCallSuper
|
||||||
@override
|
@override
|
||||||
void runBuild() {
|
void runBuild() {
|
||||||
@@ -273,17 +272,17 @@ abstract class _$PreferenceRepository
|
|||||||
final ref =
|
final ref =
|
||||||
this.ref
|
this.ref
|
||||||
as $Ref<
|
as $Ref<
|
||||||
Raw<Stream<Map<String, Object>>>,
|
Raw<Stream<Map<String, GeckoPrefValue>>>,
|
||||||
Raw<Stream<Map<String, Object>>>
|
Raw<Stream<Map<String, GeckoPrefValue>>>
|
||||||
>;
|
>;
|
||||||
final element =
|
final element =
|
||||||
ref.element
|
ref.element
|
||||||
as $ClassProviderElement<
|
as $ClassProviderElement<
|
||||||
AnyNotifier<
|
AnyNotifier<
|
||||||
Raw<Stream<Map<String, Object>>>,
|
Raw<Stream<Map<String, GeckoPrefValue>>>,
|
||||||
Raw<Stream<Map<String, Object>>>
|
Raw<Stream<Map<String, GeckoPrefValue>>>
|
||||||
>,
|
>,
|
||||||
Raw<Stream<Map<String, Object>>>,
|
Raw<Stream<Map<String, GeckoPrefValue>>>,
|
||||||
Object?,
|
Object?,
|
||||||
Object?
|
Object?
|
||||||
>;
|
>;
|
||||||
@@ -341,7 +340,7 @@ final class UnifiedPreferenceSettingsRepositoryProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$unifiedPreferenceSettingsRepositoryHash() =>
|
String _$unifiedPreferenceSettingsRepositoryHash() =>
|
||||||
r'23c0da1fdc975bbfb88b3cf82f242dbe0d50cd87';
|
r'800e74a051113b4ebc3631b6ade55d66cb7e1af1';
|
||||||
|
|
||||||
final class UnifiedPreferenceSettingsRepositoryFamily extends $Family
|
final class UnifiedPreferenceSettingsRepositoryFamily extends $Family
|
||||||
with
|
with
|
||||||
@@ -455,7 +454,7 @@ final class PreferenceSettingsGroupRepositoryProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$preferenceSettingsGroupRepositoryHash() =>
|
String _$preferenceSettingsGroupRepositoryHash() =>
|
||||||
r'05db908036ffa999886f4e9dc4429aa85f8957f9';
|
r'8e025cdea5cef8a6ea029db6f9ebcd86abf906d8';
|
||||||
|
|
||||||
final class PreferenceSettingsGroupRepositoryFamily extends $Family
|
final class PreferenceSettingsGroupRepositoryFamily extends $Family
|
||||||
with
|
with
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ final class GeckoInferenceRepositoryProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$geckoInferenceRepositoryHash() =>
|
String _$geckoInferenceRepositoryHash() =>
|
||||||
r'5f99fd1e46a8ae291b63df044fe11917cd5d415c';
|
r'c4f52d2edfb8c5763577a17697202016645177da';
|
||||||
|
|
||||||
abstract class _$GeckoInferenceRepository extends $Notifier<void> {
|
abstract class _$GeckoInferenceRepository extends $Notifier<void> {
|
||||||
void build();
|
void build();
|
||||||
@@ -268,7 +268,7 @@ final class TopicSuggestionProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _$topicSuggestionHash() => r'5401b1cd91e53be6ad1b4c7a39a5253d380e05d4';
|
String _$topicSuggestionHash() => r'97480102ecfe9458d25cb4666cf4577333e26d66';
|
||||||
|
|
||||||
final class TopicSuggestionFamily extends $Family
|
final class TopicSuggestionFamily extends $Family
|
||||||
with
|
with
|
||||||
@@ -390,7 +390,7 @@ final class ContainerTabSuggestionsProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$containerTabSuggestionsHash() =>
|
String _$containerTabSuggestionsHash() =>
|
||||||
r'9e7e9b9d245959fcf8c87cb8822313ded801ebc0';
|
r'1b681736215826886241aea834f99ebfb9761197';
|
||||||
|
|
||||||
final class ContainerTabSuggestionsFamily extends $Family
|
final class ContainerTabSuggestionsFamily extends $Family
|
||||||
with $FunctionalFamilyOverride<FutureOr<List<String>?>, String?> {
|
with $FunctionalFamilyOverride<FutureOr<List<String>?>, String?> {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ final class EngineSettingsRepositoryProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
String _$engineSettingsRepositoryHash() =>
|
String _$engineSettingsRepositoryHash() =>
|
||||||
r'33acd89e783d8d91b9b56e86411fdfcab24a2c54';
|
r'17a4e505320e92a90ed8b62db263c283c5eaa839';
|
||||||
|
|
||||||
abstract class _$EngineSettingsRepository
|
abstract class _$EngineSettingsRepository
|
||||||
extends $StreamNotifier<EngineSettings> {
|
extends $StreamNotifier<EngineSettings> {
|
||||||
|
|||||||
+2
-86
@@ -25,92 +25,8 @@ var prefmanager = class extends ExtensionAPI {
|
|||||||
return {
|
return {
|
||||||
experiments: {
|
experiments: {
|
||||||
prefmanager: {
|
prefmanager: {
|
||||||
async resetPrefs(prefNames) {
|
async getPrefList() {
|
||||||
if (prefNames && prefNames.length > 0) {
|
return Services.prefs.getChildList("");
|
||||||
for (const prefName of prefNames) {
|
|
||||||
Services.prefs.clearUserPref(prefName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Services.prefs.resetPrefs();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async getPrefs(prefNames) {
|
|
||||||
const prefs = (prefNames && prefNames.length > 0)
|
|
||||||
? prefNames
|
|
||||||
: Services.prefs.getChildList("");
|
|
||||||
|
|
||||||
const result = {};
|
|
||||||
|
|
||||||
for (const prefName of prefs) {
|
|
||||||
try {
|
|
||||||
switch (Services.prefs.getPrefType(prefName)) {
|
|
||||||
case Services.prefs.PREF_BOOL:
|
|
||||||
result[prefName] = Services.prefs.getBoolPref(prefName);
|
|
||||||
break;
|
|
||||||
case Services.prefs.PREF_INT:
|
|
||||||
result[prefName] = Services.prefs.getIntPref(prefName);
|
|
||||||
break;
|
|
||||||
case Services.prefs.PREF_STRING:
|
|
||||||
result[prefName] = Services.prefs.getCharPref(prefName);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Skip complex values or invalid preferences
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
lazy.log.error(`Error reading preference ${prefName}: ${e}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lazy.log.debug(`getAll: retrieved ${Object.keys(result).length} preferences`);
|
|
||||||
return result;
|
|
||||||
},
|
|
||||||
async parsePrefsAndApply(prefsFileContent, predicate = null) {
|
|
||||||
let prefs = {};
|
|
||||||
let addPref = (kind, name, value) => {
|
|
||||||
if (predicate && !predicate(name)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
prefs[name] = value;
|
|
||||||
};
|
|
||||||
|
|
||||||
Services.prefs.parsePrefsFromBuffer(
|
|
||||||
prefsFileContent,
|
|
||||||
{
|
|
||||||
onStringPref: addPref,
|
|
||||||
onIntPref: addPref,
|
|
||||||
onBoolPref: addPref,
|
|
||||||
onError(message) {
|
|
||||||
throw new Error(
|
|
||||||
`Error parsing preferences "${message}"`
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
await BackgroundTasksUtils.withProfileLock(profileLock => {
|
|
||||||
for (let [name, value] of Object.entries(prefs)) {
|
|
||||||
switch (typeof value) {
|
|
||||||
case "boolean":
|
|
||||||
Services.prefs.setBoolPref(name, value);
|
|
||||||
break;
|
|
||||||
case "number":
|
|
||||||
Services.prefs.setIntPref(name, value);
|
|
||||||
break;
|
|
||||||
case "string":
|
|
||||||
Services.prefs.setCharPref(name, value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(
|
|
||||||
`Pref from default profile with name "${name}" has unrecognized type`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
lazy.log.debug(`applyPreferences: parsed prefs from buffer`, prefs);
|
|
||||||
return prefs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-13
@@ -28,20 +28,9 @@ function sendErrorForRequest(id) {
|
|||||||
port.onMessage.addListener(message => {
|
port.onMessage.addListener(message => {
|
||||||
let requestId = message["id"]
|
let requestId = message["id"]
|
||||||
switch (message["action"]) {
|
switch (message["action"]) {
|
||||||
case "parsePrefsAndApply":
|
case "getPrefList":
|
||||||
browser.experiments.prefmanager.parsePrefsAndApply(encoder.encode(message["args"]), null)
|
browser.experiments.prefmanager.getPrefList()
|
||||||
.then(sendJsonResultForRequest(requestId))
|
.then(sendJsonResultForRequest(requestId))
|
||||||
.catch(sendErrorForRequest(requestId))
|
.catch(sendErrorForRequest(requestId))
|
||||||
break
|
|
||||||
case "getPrefs":
|
|
||||||
browser.experiments.prefmanager.getPrefs(message["args"])
|
|
||||||
.then(sendJsonResultForRequest(requestId))
|
|
||||||
.catch(sendErrorForRequest(requestId))
|
|
||||||
break
|
|
||||||
case "resetPrefs":
|
|
||||||
browser.experiments.prefmanager.resetPrefs(message["args"])
|
|
||||||
.then(sendJsonResultForRequest(requestId))
|
|
||||||
.catch(sendErrorForRequest(requestId))
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+6
-62
@@ -4,74 +4,18 @@
|
|||||||
"description": "Experimental API for updating Geckoview preferences",
|
"description": "Experimental API for updating Geckoview preferences",
|
||||||
"functions": [
|
"functions": [
|
||||||
{
|
{
|
||||||
"name": "getPrefs",
|
"name": "getPrefList",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"description": "Retrieves preferences and their values",
|
"description": "Retrieves list of all preferences",
|
||||||
"async": true,
|
"async": true,
|
||||||
"parameters": [
|
"parameters": [],
|
||||||
{
|
|
||||||
"name": "prefNames",
|
|
||||||
"type": "array",
|
|
||||||
"optional": true,
|
|
||||||
"description": "Array of preference names to retrieve. If empty or null, retrieves all preferences",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"returns": {
|
"returns": {
|
||||||
"type": "object",
|
"array": "object",
|
||||||
"description": "Object containing the preferences as key-value pairs",
|
"description": "Object containing the preferences as key-value pairs",
|
||||||
"additionalProperties": {
|
"items": {
|
||||||
"type": "any",
|
"type": "string"
|
||||||
"description": "Preference values can be boolean, number, or string"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "parsePrefsAndApply",
|
|
||||||
"type": "function",
|
|
||||||
"description": "Reads and sets preferences from an encoded preferences file content",
|
|
||||||
"async": true,
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "prefsFileContent",
|
|
||||||
"type": "object",
|
|
||||||
"isInstanceOf": "Uint8Array",
|
|
||||||
"description": "Encoded content of the preferences file to parse (Uint8Array)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "predicate",
|
|
||||||
"type": "function",
|
|
||||||
"optional": true,
|
|
||||||
"description": "Optional filter function to determine which preferences to include"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"returns": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "Object containing the parsed preferences as key-value pairs",
|
|
||||||
"additionalProperties": {
|
|
||||||
"type": "any",
|
|
||||||
"description": "Preference values can be boolean, number, or string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "resetPrefs",
|
|
||||||
"type": "function",
|
|
||||||
"description": "Resets multiple or all preferences to their default values",
|
|
||||||
"async": true,
|
|
||||||
"parameters": [
|
|
||||||
{
|
|
||||||
"name": "prefNames",
|
|
||||||
"type": "array",
|
|
||||||
"optional": true,
|
|
||||||
"description": "Array of preference names to reset. If empty or null, resets all preferences",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+111
-27
@@ -6,13 +6,22 @@
|
|||||||
|
|
||||||
package eu.weblibre.flutter_mozilla_components.api
|
package eu.weblibre.flutter_mozilla_components.api
|
||||||
|
|
||||||
|
import eu.weblibre.flutter_mozilla_components.GlobalComponents
|
||||||
import eu.weblibre.flutter_mozilla_components.feature.PrefManagerFeature
|
import eu.weblibre.flutter_mozilla_components.feature.PrefManagerFeature
|
||||||
import eu.weblibre.flutter_mozilla_components.feature.ResultConsumer
|
import eu.weblibre.flutter_mozilla_components.feature.ResultConsumer
|
||||||
import eu.weblibre.flutter_mozilla_components.pigeons.GeckoPrefApi
|
import eu.weblibre.flutter_mozilla_components.pigeons.GeckoPrefApi
|
||||||
|
import eu.weblibre.flutter_mozilla_components.pigeons.GeckoPrefValue
|
||||||
|
import mozilla.components.ExperimentalAndroidComponentsApi
|
||||||
|
import mozilla.components.concept.engine.preferences.Branch
|
||||||
|
import mozilla.components.support.ktx.android.org.json.toList
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
|
|
||||||
class GeckoPrefApiImpl : GeckoPrefApi {
|
class GeckoPrefApiImpl : GeckoPrefApi {
|
||||||
|
private val components by lazy {
|
||||||
|
requireNotNull(GlobalComponents.components) { "Components not initialized" }
|
||||||
|
}
|
||||||
|
|
||||||
private fun List<String>?.toJson(): JSONArray {
|
private fun List<String>?.toJson(): JSONArray {
|
||||||
return JSONArray().apply {
|
return JSONArray().apply {
|
||||||
this@toJson?.forEach { put(it) }
|
this@toJson?.forEach { put(it) }
|
||||||
@@ -36,44 +45,119 @@ class GeckoPrefApiImpl : GeckoPrefApi {
|
|||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getPrefList(callback: (Result<List<String>>) -> Unit) {
|
||||||
|
PrefManagerFeature.scheduleRequest("getPrefList", Unit, object : ResultConsumer<JSONObject> {
|
||||||
|
override fun success(result: JSONObject) {
|
||||||
|
callback(Result.success(result.getJSONArray("result").toList()))
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
|
||||||
|
callback(Result.failure(Exception("$errorCode $errorMessage $errorDetails")))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalAndroidComponentsApi::class)
|
||||||
override fun getPrefs(
|
override fun getPrefs(
|
||||||
preferenceFilter: List<String>?,
|
preferenceFilter: List<String>,
|
||||||
callback: (Result<Map<String, Any>>) -> Unit
|
callback: (Result<Map<String, GeckoPrefValue>>) -> Unit
|
||||||
) {
|
) {
|
||||||
PrefManagerFeature.scheduleRequest("getPrefs", preferenceFilter.toJson(), object : ResultConsumer<JSONObject> {
|
components.core.engine.getBrowserPrefs(
|
||||||
override fun success(result: JSONObject) {
|
preferenceFilter, onSuccess = {
|
||||||
callback(Result.success(result.getJSONObject("result").toMap()))
|
callback(
|
||||||
|
Result.success(
|
||||||
|
it.associate {
|
||||||
|
it.pref to GeckoPrefValue(
|
||||||
|
value = it.value,
|
||||||
|
defaultValue = it.defaultValue,
|
||||||
|
userValue = it.userValue,
|
||||||
|
hasUserChangedValue = it.hasUserChangedValue,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onError = {
|
||||||
|
callback(Result.failure(Exception("${it.message} ${it.cause}")))
|
||||||
}
|
}
|
||||||
|
)
|
||||||
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
|
|
||||||
callback(Result.failure(Exception("$errorCode $errorMessage $errorDetails")))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun applyPrefs(prefBuffer: String, callback: (Result<Map<String, Any>>) -> Unit) {
|
@OptIn(ExperimentalAndroidComponentsApi::class)
|
||||||
PrefManagerFeature.scheduleRequest("parsePrefsAndApply", prefBuffer, object : ResultConsumer<JSONObject> {
|
override fun applyPrefs(
|
||||||
override fun success(result: JSONObject) {
|
prefs: Map<String, Any>,
|
||||||
callback(Result.success(result.getJSONObject("result").toMap()))
|
callback: (Result<Map<String, GeckoPrefValue>>) -> Unit
|
||||||
|
) {
|
||||||
|
var fault: Boolean = false;
|
||||||
|
|
||||||
|
for (pref in prefs) {
|
||||||
|
when (pref.value) {
|
||||||
|
is String -> components.core.engine.setBrowserPref(
|
||||||
|
pref.key,
|
||||||
|
pref.value as String,
|
||||||
|
Branch.USER,
|
||||||
|
onSuccess = {},
|
||||||
|
onError = {
|
||||||
|
callback(Result.failure(Exception("${it.message} ${it.cause}")))
|
||||||
|
fault = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
is Boolean -> components.core.engine.setBrowserPref(
|
||||||
|
pref.key,
|
||||||
|
pref.value as Boolean,
|
||||||
|
Branch.USER,
|
||||||
|
onSuccess = {},
|
||||||
|
onError = {
|
||||||
|
callback(Result.failure(Exception("${it.message} ${it.cause}")))
|
||||||
|
fault = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
is Long -> components.core.engine.setBrowserPref(
|
||||||
|
pref.key,
|
||||||
|
(pref.value as Long).toInt(),
|
||||||
|
Branch.USER,
|
||||||
|
onSuccess = {},
|
||||||
|
onError = {
|
||||||
|
callback(Result.failure(Exception("${it.message} ${it.cause}")))
|
||||||
|
fault = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> {
|
||||||
|
callback(Result.failure(Exception("Unsupported value type: ${pref.value::class.simpleName}")))
|
||||||
|
fault = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
|
if (fault) {
|
||||||
callback(Result.failure(Exception("$errorCode $errorMessage $errorDetails")))
|
return;
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
getPrefs(
|
||||||
|
prefs.keys.toList(),
|
||||||
|
callback = callback
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resetPrefs(preferenceNames: List<String>?, callback: (Result<Unit>) -> Unit) {
|
@OptIn(ExperimentalAndroidComponentsApi::class)
|
||||||
PrefManagerFeature.scheduleRequest("resetPrefs", preferenceNames.toJson(), object : ResultConsumer<JSONObject> {
|
override fun resetPrefs(preferenceNames: List<String>, callback: (Result<Unit>) -> Unit) {
|
||||||
override fun success(result: JSONObject) {
|
var fault: Boolean = false;
|
||||||
callback(Result.success(Unit))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
|
for (pref in preferenceNames) {
|
||||||
callback(Result.failure(Exception("$errorCode $errorMessage $errorDetails")))
|
components.core.engine.clearBrowserUserPref(
|
||||||
|
pref = pref,
|
||||||
|
onSuccess = {},
|
||||||
|
onError = {
|
||||||
|
callback(Result.failure(Exception("${it.message} ${it.cause}")))
|
||||||
|
fault = true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if (fault) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+73
-8
@@ -2194,6 +2194,43 @@ data class AddonCollection (
|
|||||||
|
|
||||||
override fun hashCode(): Int = toList().hashCode()
|
override fun hashCode(): Int = toList().hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Generated class from Pigeon that represents data sent in messages. */
|
||||||
|
data class GeckoPrefValue (
|
||||||
|
val value: Any? = null,
|
||||||
|
val defaultValue: Any? = null,
|
||||||
|
val userValue: Any? = null,
|
||||||
|
val hasUserChangedValue: Boolean
|
||||||
|
)
|
||||||
|
{
|
||||||
|
companion object {
|
||||||
|
fun fromList(pigeonVar_list: List<Any?>): GeckoPrefValue {
|
||||||
|
val value = pigeonVar_list[0]
|
||||||
|
val defaultValue = pigeonVar_list[1]
|
||||||
|
val userValue = pigeonVar_list[2]
|
||||||
|
val hasUserChangedValue = pigeonVar_list[3] as Boolean
|
||||||
|
return GeckoPrefValue(value, defaultValue, userValue, hasUserChangedValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fun toList(): List<Any?> {
|
||||||
|
return listOf(
|
||||||
|
value,
|
||||||
|
defaultValue,
|
||||||
|
userValue,
|
||||||
|
hasUserChangedValue,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other !is GeckoPrefValue) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (this === other) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return GeckoPigeonUtils.deepEquals(toList(), other.toList()) }
|
||||||
|
|
||||||
|
override fun hashCode(): Int = toList().hashCode()
|
||||||
|
}
|
||||||
private open class GeckoPigeonCodec : StandardMessageCodec() {
|
private open class GeckoPigeonCodec : StandardMessageCodec() {
|
||||||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
@@ -2507,6 +2544,11 @@ private open class GeckoPigeonCodec : StandardMessageCodec() {
|
|||||||
AddonCollection.fromList(it)
|
AddonCollection.fromList(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
191.toByte() -> {
|
||||||
|
return (readValue(buffer) as? List<Any?>)?.let {
|
||||||
|
GeckoPrefValue.fromList(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> super.readValueOfType(type, buffer)
|
else -> super.readValueOfType(type, buffer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2760,6 +2802,10 @@ private open class GeckoPigeonCodec : StandardMessageCodec() {
|
|||||||
stream.write(190)
|
stream.write(190)
|
||||||
writeValue(stream, value.toList())
|
writeValue(stream, value.toList())
|
||||||
}
|
}
|
||||||
|
is GeckoPrefValue -> {
|
||||||
|
stream.write(191)
|
||||||
|
writeValue(stream, value.toList())
|
||||||
|
}
|
||||||
else -> super.writeValue(stream, value)
|
else -> super.writeValue(stream, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3714,9 +3760,10 @@ interface GeckoIconsApi {
|
|||||||
}
|
}
|
||||||
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
|
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
|
||||||
interface GeckoPrefApi {
|
interface GeckoPrefApi {
|
||||||
fun getPrefs(preferenceFilter: List<String>?, callback: (Result<Map<String, Any>>) -> Unit)
|
fun getPrefList(callback: (Result<List<String>>) -> Unit)
|
||||||
fun applyPrefs(prefBuffer: String, callback: (Result<Map<String, Any>>) -> Unit)
|
fun getPrefs(preferenceFilter: List<String>, callback: (Result<Map<String, GeckoPrefValue>>) -> Unit)
|
||||||
fun resetPrefs(preferenceNames: List<String>?, callback: (Result<Unit>) -> Unit)
|
fun applyPrefs(prefs: Map<String, Any>, callback: (Result<Map<String, GeckoPrefValue>>) -> Unit)
|
||||||
|
fun resetPrefs(preferenceNames: List<String>, callback: (Result<Unit>) -> Unit)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/** The codec used by GeckoPrefApi. */
|
/** The codec used by GeckoPrefApi. */
|
||||||
@@ -3727,13 +3774,31 @@ interface GeckoPrefApi {
|
|||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun setUp(binaryMessenger: BinaryMessenger, api: GeckoPrefApi?, messageChannelSuffix: String = "") {
|
fun setUp(binaryMessenger: BinaryMessenger, api: GeckoPrefApi?, messageChannelSuffix: String = "") {
|
||||||
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
|
||||||
|
run {
|
||||||
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.getPrefList$separatedMessageChannelSuffix", codec)
|
||||||
|
if (api != null) {
|
||||||
|
channel.setMessageHandler { _, reply ->
|
||||||
|
api.getPrefList{ result: Result<List<String>> ->
|
||||||
|
val error = result.exceptionOrNull()
|
||||||
|
if (error != null) {
|
||||||
|
reply.reply(GeckoPigeonUtils.wrapError(error))
|
||||||
|
} else {
|
||||||
|
val data = result.getOrNull()
|
||||||
|
reply.reply(GeckoPigeonUtils.wrapResult(data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
channel.setMessageHandler(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
run {
|
run {
|
||||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.getPrefs$separatedMessageChannelSuffix", codec)
|
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.getPrefs$separatedMessageChannelSuffix", codec)
|
||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val preferenceFilterArg = args[0] as List<String>?
|
val preferenceFilterArg = args[0] as List<String>
|
||||||
api.getPrefs(preferenceFilterArg) { result: Result<Map<String, Any>> ->
|
api.getPrefs(preferenceFilterArg) { result: Result<Map<String, GeckoPrefValue>> ->
|
||||||
val error = result.exceptionOrNull()
|
val error = result.exceptionOrNull()
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
reply.reply(GeckoPigeonUtils.wrapError(error))
|
reply.reply(GeckoPigeonUtils.wrapError(error))
|
||||||
@@ -3752,8 +3817,8 @@ interface GeckoPrefApi {
|
|||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val prefBufferArg = args[0] as String
|
val prefsArg = args[0] as Map<String, Any>
|
||||||
api.applyPrefs(prefBufferArg) { result: Result<Map<String, Any>> ->
|
api.applyPrefs(prefsArg) { result: Result<Map<String, GeckoPrefValue>> ->
|
||||||
val error = result.exceptionOrNull()
|
val error = result.exceptionOrNull()
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
reply.reply(GeckoPigeonUtils.wrapError(error))
|
reply.reply(GeckoPigeonUtils.wrapError(error))
|
||||||
@@ -3772,7 +3837,7 @@ interface GeckoPrefApi {
|
|||||||
if (api != null) {
|
if (api != null) {
|
||||||
channel.setMessageHandler { message, reply ->
|
channel.setMessageHandler { message, reply ->
|
||||||
val args = message as List<Any?>
|
val args = message as List<Any?>
|
||||||
val preferenceNamesArg = args[0] as List<String>?
|
val preferenceNamesArg = args[0] as List<String>
|
||||||
api.resetPrefs(preferenceNamesArg) { result: Result<Unit> ->
|
api.resetPrefs(preferenceNamesArg) { result: Result<Unit> ->
|
||||||
val error = result.exceptionOrNull()
|
val error = result.exceptionOrNull()
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ export 'src/pigeons/gecko.g.dart'
|
|||||||
DohSettingsMode,
|
DohSettingsMode,
|
||||||
EmailHitResult,
|
EmailHitResult,
|
||||||
GeckoEngineSettings,
|
GeckoEngineSettings,
|
||||||
|
GeckoPrefValue,
|
||||||
GeckoSuggestion,
|
GeckoSuggestion,
|
||||||
GeckoSuggestionType,
|
GeckoSuggestionType,
|
||||||
GeoHitResult,
|
GeoHitResult,
|
||||||
|
|||||||
@@ -4,34 +4,25 @@
|
|||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
|
import 'package:flutter_mozilla_components/src/pigeons/gecko.g.dart';
|
||||||
|
|
||||||
final _apiInstance = GeckoPrefApi();
|
final _apiInstance = GeckoPrefApi();
|
||||||
|
|
||||||
class GeckoPrefService {
|
class GeckoPrefService {
|
||||||
Future<Map<String, Object>> getAllPrefs() {
|
Future<List<String>> getPrefList() {
|
||||||
return _apiInstance.getPrefs(null);
|
return _apiInstance.getPrefList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, Object>> getPrefs(List<String> prefs) {
|
Future<Map<String, GeckoPrefValue>> getAllPrefs() async {
|
||||||
|
return _apiInstance.getPrefs(await getPrefList());
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, GeckoPrefValue>> getPrefs(List<String> prefs) {
|
||||||
return _apiInstance.getPrefs(prefs);
|
return _apiInstance.getPrefs(prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, Object>> applyPrefs(Map<String, Object> prefs) {
|
Future<Map<String, GeckoPrefValue>> applyPrefs(Map<String, Object> prefs) {
|
||||||
final buffer = prefs.entries.map((pref) {
|
return _apiInstance.applyPrefs(prefs);
|
||||||
final value = switch (pref.value) {
|
|
||||||
final bool x => '$x',
|
|
||||||
final int x => '$x',
|
|
||||||
final String x => jsonEncode(x),
|
|
||||||
_ => throw Exception('Unknow pref type'),
|
|
||||||
};
|
|
||||||
|
|
||||||
return 'user_pref("${pref.key}", $value);';
|
|
||||||
}).join();
|
|
||||||
|
|
||||||
return _apiInstance.applyPrefs(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> resetPrefs(List<String> prefs) {
|
Future<void> resetPrefs(List<String> prefs) {
|
||||||
|
|||||||
@@ -2788,6 +2788,62 @@ class AddonCollection {
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GeckoPrefValue {
|
||||||
|
GeckoPrefValue({
|
||||||
|
this.value,
|
||||||
|
this.defaultValue,
|
||||||
|
this.userValue,
|
||||||
|
required this.hasUserChangedValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
Object? value;
|
||||||
|
|
||||||
|
Object? defaultValue;
|
||||||
|
|
||||||
|
Object? userValue;
|
||||||
|
|
||||||
|
bool hasUserChangedValue;
|
||||||
|
|
||||||
|
List<Object?> _toList() {
|
||||||
|
return <Object?>[
|
||||||
|
value,
|
||||||
|
defaultValue,
|
||||||
|
userValue,
|
||||||
|
hasUserChangedValue,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
Object encode() {
|
||||||
|
return _toList(); }
|
||||||
|
|
||||||
|
static GeckoPrefValue decode(Object result) {
|
||||||
|
result as List<Object?>;
|
||||||
|
return GeckoPrefValue(
|
||||||
|
value: result[0],
|
||||||
|
defaultValue: result[1],
|
||||||
|
userValue: result[2],
|
||||||
|
hasUserChangedValue: result[3]! as bool,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
// ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (other is! GeckoPrefValue || other.runtimeType != runtimeType) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (identical(this, other)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return _deepEquals(encode(), other.encode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
// ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||||
|
int get hashCode => Object.hashAll(_toList())
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class _PigeonCodec extends StandardMessageCodec {
|
class _PigeonCodec extends StandardMessageCodec {
|
||||||
const _PigeonCodec();
|
const _PigeonCodec();
|
||||||
@@ -2982,6 +3038,9 @@ class _PigeonCodec extends StandardMessageCodec {
|
|||||||
} else if (value is AddonCollection) {
|
} else if (value is AddonCollection) {
|
||||||
buffer.putUint8(190);
|
buffer.putUint8(190);
|
||||||
writeValue(buffer, value.encode());
|
writeValue(buffer, value.encode());
|
||||||
|
} else if (value is GeckoPrefValue) {
|
||||||
|
buffer.putUint8(191);
|
||||||
|
writeValue(buffer, value.encode());
|
||||||
} else {
|
} else {
|
||||||
super.writeValue(buffer, value);
|
super.writeValue(buffer, value);
|
||||||
}
|
}
|
||||||
@@ -3133,6 +3192,8 @@ class _PigeonCodec extends StandardMessageCodec {
|
|||||||
return ShareInternetResourceState.decode(readValue(buffer)!);
|
return ShareInternetResourceState.decode(readValue(buffer)!);
|
||||||
case 190:
|
case 190:
|
||||||
return AddonCollection.decode(readValue(buffer)!);
|
return AddonCollection.decode(readValue(buffer)!);
|
||||||
|
case 191:
|
||||||
|
return GeckoPrefValue.decode(readValue(buffer)!);
|
||||||
default:
|
default:
|
||||||
return super.readValueOfType(type, buffer);
|
return super.readValueOfType(type, buffer);
|
||||||
}
|
}
|
||||||
@@ -4268,7 +4329,35 @@ class GeckoPrefApi {
|
|||||||
|
|
||||||
final String pigeonVar_messageChannelSuffix;
|
final String pigeonVar_messageChannelSuffix;
|
||||||
|
|
||||||
Future<Map<String, Object>> getPrefs(List<String>? preferenceFilter) async {
|
Future<List<String>> getPrefList() async {
|
||||||
|
final String pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.getPrefList$pigeonVar_messageChannelSuffix';
|
||||||
|
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||||
|
pigeonVar_channelName,
|
||||||
|
pigeonChannelCodec,
|
||||||
|
binaryMessenger: pigeonVar_binaryMessenger,
|
||||||
|
);
|
||||||
|
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
|
||||||
|
final List<Object?>? pigeonVar_replyList =
|
||||||
|
await pigeonVar_sendFuture as List<Object?>?;
|
||||||
|
if (pigeonVar_replyList == null) {
|
||||||
|
throw _createConnectionError(pigeonVar_channelName);
|
||||||
|
} else if (pigeonVar_replyList.length > 1) {
|
||||||
|
throw PlatformException(
|
||||||
|
code: pigeonVar_replyList[0]! as String,
|
||||||
|
message: pigeonVar_replyList[1] as String?,
|
||||||
|
details: pigeonVar_replyList[2],
|
||||||
|
);
|
||||||
|
} else if (pigeonVar_replyList[0] == null) {
|
||||||
|
throw PlatformException(
|
||||||
|
code: 'null-error',
|
||||||
|
message: 'Host platform returned null value for non-null return value.',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return (pigeonVar_replyList[0] as List<Object?>?)!.cast<String>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, GeckoPrefValue>> getPrefs(List<String> preferenceFilter) async {
|
||||||
final String pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.getPrefs$pigeonVar_messageChannelSuffix';
|
final String pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.getPrefs$pigeonVar_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||||
pigeonVar_channelName,
|
pigeonVar_channelName,
|
||||||
@@ -4292,18 +4381,18 @@ class GeckoPrefApi {
|
|||||||
message: 'Host platform returned null value for non-null return value.',
|
message: 'Host platform returned null value for non-null return value.',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (pigeonVar_replyList[0] as Map<Object?, Object?>?)!.cast<String, Object>();
|
return (pigeonVar_replyList[0] as Map<Object?, Object?>?)!.cast<String, GeckoPrefValue>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, Object>> applyPrefs(String prefBuffer) async {
|
Future<Map<String, GeckoPrefValue>> applyPrefs(Map<String, Object> prefs) async {
|
||||||
final String pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.applyPrefs$pigeonVar_messageChannelSuffix';
|
final String pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.applyPrefs$pigeonVar_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||||
pigeonVar_channelName,
|
pigeonVar_channelName,
|
||||||
pigeonChannelCodec,
|
pigeonChannelCodec,
|
||||||
binaryMessenger: pigeonVar_binaryMessenger,
|
binaryMessenger: pigeonVar_binaryMessenger,
|
||||||
);
|
);
|
||||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[prefBuffer]);
|
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[prefs]);
|
||||||
final List<Object?>? pigeonVar_replyList =
|
final List<Object?>? pigeonVar_replyList =
|
||||||
await pigeonVar_sendFuture as List<Object?>?;
|
await pigeonVar_sendFuture as List<Object?>?;
|
||||||
if (pigeonVar_replyList == null) {
|
if (pigeonVar_replyList == null) {
|
||||||
@@ -4320,11 +4409,11 @@ class GeckoPrefApi {
|
|||||||
message: 'Host platform returned null value for non-null return value.',
|
message: 'Host platform returned null value for non-null return value.',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return (pigeonVar_replyList[0] as Map<Object?, Object?>?)!.cast<String, Object>();
|
return (pigeonVar_replyList[0] as Map<Object?, Object?>?)!.cast<String, GeckoPrefValue>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> resetPrefs(List<String>? preferenceNames) async {
|
Future<void> resetPrefs(List<String> preferenceNames) async {
|
||||||
final String pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.resetPrefs$pigeonVar_messageChannelSuffix';
|
final String pigeonVar_channelName = 'dev.flutter.pigeon.flutter_mozilla_components.GeckoPrefApi.resetPrefs$pigeonVar_messageChannelSuffix';
|
||||||
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||||
pigeonVar_channelName,
|
pigeonVar_channelName,
|
||||||
|
|||||||
@@ -1075,14 +1075,30 @@ abstract class GeckoIconsApi {
|
|||||||
IconResult loadIcon(IconRequest request);
|
IconResult loadIcon(IconRequest request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GeckoPrefValue {
|
||||||
|
final Object? value;
|
||||||
|
final Object? defaultValue;
|
||||||
|
final Object? userValue;
|
||||||
|
final bool hasUserChangedValue;
|
||||||
|
|
||||||
|
GeckoPrefValue(
|
||||||
|
this.value,
|
||||||
|
this.defaultValue,
|
||||||
|
this.userValue,
|
||||||
|
this.hasUserChangedValue,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@HostApi()
|
@HostApi()
|
||||||
abstract class GeckoPrefApi {
|
abstract class GeckoPrefApi {
|
||||||
@async
|
@async
|
||||||
Map<String, Object> getPrefs(List<String>? preferenceFilter);
|
List<String> getPrefList();
|
||||||
@async
|
@async
|
||||||
Map<String, Object> applyPrefs(String prefBuffer);
|
Map<String, GeckoPrefValue> getPrefs(List<String> preferenceFilter);
|
||||||
@async
|
@async
|
||||||
void resetPrefs(List<String>? preferenceNames);
|
Map<String, GeckoPrefValue> applyPrefs(Map<String, Object> prefs);
|
||||||
|
@async
|
||||||
|
void resetPrefs(List<String> preferenceNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
@HostApi()
|
@HostApi()
|
||||||
|
|||||||
Reference in New Issue
Block a user