forked from Sarsilmazxx02/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate get & set preference APIs to use the standard server connecti…
…on. (flutter#8284)
- Loading branch information
1 parent
3127636
commit f4cb8be
Showing
12 changed files
with
191 additions
and
52 deletions.
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
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
45 changes: 45 additions & 0 deletions
45
packages/devtools_app/lib/src/shared/server/_preferences_api.dart
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,45 @@ | ||
// Copyright 2024 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be found | ||
// in the LICENSE file. | ||
|
||
part of 'server.dart'; | ||
|
||
/// Requests the DevTools preference for the [key]. | ||
/// | ||
/// This value is stored in the file '~/.flutter-devtools/.devtools'. | ||
Future<Object?> getPreferenceValue(String key) async { | ||
if (!isDevToolsServerAvailable) return null; | ||
|
||
final uri = Uri( | ||
path: PreferencesApi.getPreferenceValue, | ||
queryParameters: { | ||
PreferencesApi.preferenceKeyProperty: key, | ||
}, | ||
); | ||
final resp = await request(uri.toString()); | ||
if (resp?.statusOk ?? false) { | ||
return jsonDecode(resp!.body); | ||
} else { | ||
logWarning(resp, PreferencesApi.getPreferenceValue); | ||
return null; | ||
} | ||
} | ||
|
||
/// Sets the DevTools preference [value] for the [key]. | ||
/// | ||
/// This value is stored in the file '~/.flutter-devtools/.devtools'. | ||
Future<void> setPreferenceValue(String key, Object value) async { | ||
if (!isDevToolsServerAvailable) return; | ||
|
||
final uri = Uri( | ||
path: PreferencesApi.setPreferenceValue, | ||
queryParameters: { | ||
PreferencesApi.preferenceKeyProperty: key, | ||
apiParameterValueKey: value, | ||
}, | ||
); | ||
final resp = await request(uri.toString()); | ||
if (resp == null || !resp.statusOk) { | ||
logWarning(resp, PreferencesApi.setPreferenceValue); | ||
} | ||
} |
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
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
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
50 changes: 50 additions & 0 deletions
50
packages/devtools_shared/lib/src/server/handlers/_preferences.dart
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,50 @@ | ||
// Copyright 2024 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// ignore_for_file: avoid_classes_with_only_static_members | ||
|
||
part of '../server_api.dart'; | ||
|
||
abstract class _PreferencesApiHandler { | ||
static shelf.Response getPreferenceValue<T>( | ||
ServerApi api, | ||
Map<String, String> queryParams, | ||
DevToolsUsage devToolsStore, | ||
) { | ||
final missingRequiredParams = ServerApi._checkRequiredParameters( | ||
[PreferencesApi.preferenceKeyProperty], | ||
queryParams: queryParams, | ||
api: api, | ||
requestName: PreferencesApi.getPreferenceValue, | ||
); | ||
if (missingRequiredParams != null) return missingRequiredParams; | ||
|
||
return _StorageHandler.handleGetStorageValue<T>( | ||
api, | ||
devToolsStore, | ||
key: queryParams[PreferencesApi.preferenceKeyProperty]!, | ||
); | ||
} | ||
|
||
static shelf.Response setPreferenceValue<T>( | ||
ServerApi api, | ||
Map<String, String> queryParams, | ||
DevToolsUsage devToolsStore, | ||
) { | ||
final missingRequiredParams = ServerApi._checkRequiredParameters( | ||
[PreferencesApi.preferenceKeyProperty, apiParameterValueKey], | ||
queryParams: queryParams, | ||
api: api, | ||
requestName: PreferencesApi.setPreferenceValue, | ||
); | ||
if (missingRequiredParams != null) return missingRequiredParams; | ||
|
||
return _StorageHandler.handleSetStorageValue<T>( | ||
api, | ||
devToolsStore, | ||
key: queryParams[PreferencesApi.preferenceKeyProperty]!, | ||
value: queryParams[apiParameterValueKey]! as T, | ||
); | ||
} | ||
} |
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