Skip to content

Commit

Permalink
Merge branch 'master' into cupertino_profile
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Mar 27, 2024
2 parents 671b781 + 9f47439 commit fd44043
Show file tree
Hide file tree
Showing 17 changed files with 16,405 additions and 10,804 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/cupertino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,7 @@ jobs:
name: Install dependencies
run: flutter pub get
- name: Check formatting
# Don't lint the generated file native_cupertino_bindings.dart
# This approach is simpler than using `find` and excluding that file
# because `dart format` also excludes other file e.g. ones in
# directories start with '.'.
run: |
mv lib/src/native_cupertino_bindings.dart lib/src/native_cupertino_bindings.tmp
dart format --output=none --set-exit-if-changed .
mv lib/src/native_cupertino_bindings.tmp lib/src/native_cupertino_bindings.dart
run: dart format --output=none --set-exit-if-changed .
if: always() && steps.install.outcome == 'success'
- name: Analyze code
run: flutter analyze --fatal-infos
Expand Down
5 changes: 5 additions & 0 deletions pkgs/cupertino_http/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

* Add integration to the
[DevTools "Network" tab](https://docs.flutter.dev/tools/devtools/network).
* Upgrade to `package:ffigen` 11.0.0.

## 1.4.0

* **Experimental** support for the `package:web_socket` `WebSocket` interface.

## 1.3.0

Expand Down
40 changes: 19 additions & 21 deletions pkgs/cupertino_http/lib/src/cupertino_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ class Error extends _ObjectHolder<ncb.NSError> implements Exception {
linkedLibs, linkedLibs.NSLocalizedDescriptionKey),
);
}
final e = ncb.NSError.alloc(linkedLibs).initWithDomain_code_userInfo_(
domain.toNSString(linkedLibs).pointer, code, d);
final e = ncb.NSError.alloc(linkedLibs)
.initWithDomain_code_userInfo_(domain.toNSString(linkedLibs), code, d);
return Error._(e);
}

Expand All @@ -201,8 +201,7 @@ class Error extends _ObjectHolder<ncb.NSError> implements Exception {
/// The error domain, for example `"NSPOSIXErrorDomain"`.
///
/// See [NSError.domain](https://developer.apple.com/documentation/foundation/nserror/1413924-domain)
String get domain =>
ncb.NSString.castFromPointer(linkedLibs, _nsObject.domain).toString();
String get domain => _nsObject.domain.toString();

/// A description of the error in the current locale e.g.
/// 'A server with the specified hostname could not be found.'
Expand Down Expand Up @@ -244,7 +243,7 @@ class URLCache extends _ObjectHolder<ncb.NSURLCache> {
/// See [NSURLCache.sharedURLCache](https://developer.apple.com/documentation/foundation/nsurlcache/1413377-sharedurlcache)
static URLCache? get sharedURLCache {
final sharedCache = ncb.NSURLCache.getSharedURLCache(linkedLibs);
return sharedCache == null ? null : URLCache._(sharedCache);
return URLCache._(sharedCache);
}

/// Create a new [URLCache] with the given memory and disk cache sizes.
Expand Down Expand Up @@ -292,7 +291,7 @@ class URLSessionConfiguration
URLSessionConfiguration._(
ncb.NSURLSessionConfiguration.castFrom(
ncb.NSURLSessionConfiguration.getDefaultSessionConfiguration(
linkedLibs)!),
linkedLibs)),
isBackground: false);

/// A session configuration that uses no persistent storage for caches,
Expand All @@ -303,7 +302,7 @@ class URLSessionConfiguration
URLSessionConfiguration._(
ncb.NSURLSessionConfiguration.castFrom(
ncb.NSURLSessionConfiguration.getEphemeralSessionConfiguration(
linkedLibs)!),
linkedLibs)),
isBackground: false);

/// Whether connections over a cellular network are allowed.
Expand Down Expand Up @@ -552,7 +551,7 @@ class MutableData extends Data {

/// A new empty [MutableData].
factory MutableData.empty() =>
MutableData._(ncb.NSMutableData.dataWithCapacity_(linkedLibs, 0));
MutableData._(ncb.NSMutableData.dataWithCapacity_(linkedLibs, 0)!);

/// Appends the given data.
///
Expand Down Expand Up @@ -626,8 +625,7 @@ class HTTPURLResponse extends URLResponse {
///
/// See [HTTPURLResponse.allHeaderFields](https://developer.apple.com/documentation/foundation/nshttpurlresponse/1417930-allheaderfields)
Map<String, String> get allHeaderFields {
final headers =
ncb.NSDictionary.castFrom(_httpUrlResponse.allHeaderFields!);
final headers = ncb.NSDictionary.castFrom(_httpUrlResponse.allHeaderFields);
return stringNSDictionaryToMap(headers);
}

Expand Down Expand Up @@ -918,8 +916,8 @@ class URLSessionWebSocketTask extends URLSessionTask {
completionPort.close();
});

helperLibs.CUPHTTPSendMessage(_urlSessionWebSocketTask.pointer,
message._nsObject.pointer, completionPort.sendPort.nativePort);
helperLibs.CUPHTTPSendMessage(_urlSessionWebSocketTask, message._nsObject,
completionPort.sendPort.nativePort);
await completer.future;
}

Expand Down Expand Up @@ -956,7 +954,7 @@ class URLSessionWebSocketTask extends URLSessionTask {
});

helperLibs.CUPHTTPReceiveMessage(
_urlSessionWebSocketTask.pointer, completionPort.sendPort.nativePort);
_urlSessionWebSocketTask, completionPort.sendPort.nativePort);
return completer.future;
}

Expand Down Expand Up @@ -1066,7 +1064,7 @@ class MutableURLRequest extends URLRequest {
/// See [NSMutableURLRequest.requestWithURL:](https://developer.apple.com/documentation/foundation/nsmutableurlrequest/1414617-allhttpheaderfields)
factory MutableURLRequest.fromUrl(Uri uri) {
final url = ncb.NSURL
.URLWithString_(linkedLibs, uri.toString().toNSString(linkedLibs));
.URLWithString_(linkedLibs, uri.toString().toNSString(linkedLibs))!;
return MutableURLRequest._(
ncb.NSMutableURLRequest.requestWithURL_(linkedLibs, url));
}
Expand Down Expand Up @@ -1160,15 +1158,15 @@ void _setupDelegation(

try {
final request = URLRequest._(
ncb.NSURLRequest.castFrom(forwardedRedirect.request!));
ncb.NSURLRequest.castFrom(forwardedRedirect.request));

if (onRedirect == null) {
redirectRequest = request;
break;
}
try {
final response = HTTPURLResponse._(
ncb.NSHTTPURLResponse.castFrom(forwardedRedirect.response!));
ncb.NSHTTPURLResponse.castFrom(forwardedRedirect.response));
redirectRequest = onRedirect(session, task, response, request);
} catch (e) {
// TODO(https://github.com/dart-lang/ffigen/issues/386): Package
Expand All @@ -1191,7 +1189,7 @@ void _setupDelegation(
break;
}
final response =
URLResponse._exactURLResponseType(forwardedResponse.response!);
URLResponse._exactURLResponseType(forwardedResponse.response);

try {
disposition = onResponse(session, task, response);
Expand All @@ -1213,8 +1211,8 @@ void _setupDelegation(
break;
}
try {
onData(session, task,
Data._(ncb.NSData.castFrom(forwardedData.data!)));
onData(
session, task, Data._(ncb.NSData.castFrom(forwardedData.data)));
} catch (e) {
// TODO(https://github.com/dart-lang/ffigen/issues/386): Package
// this exception as an `Error` and call the completion function
Expand All @@ -1236,7 +1234,7 @@ void _setupDelegation(
session,
task as URLSessionDownloadTask,
Uri.parse(
finishedDownloading.location!.absoluteString!.toString()));
finishedDownloading.location.absoluteString!.toString()));
} catch (e) {
// TODO(https://github.com/dart-lang/ffigen/issues/386): Package
// this exception as an `Error` and call the completion function
Expand Down Expand Up @@ -1474,7 +1472,7 @@ class URLSession extends _ObjectHolder<ncb.NSURLSession> {
///
/// See [NSURLSession.configuration](https://developer.apple.com/documentation/foundation/nsurlsession/1411477-configuration)
URLSessionConfiguration get configuration => URLSessionConfiguration._(
ncb.NSURLSessionConfiguration.castFrom(_nsObject.configuration!),
ncb.NSURLSessionConfiguration.castFrom(_nsObject.configuration),
isBackground: _isBackground);

/// A description of the session that may be useful for debugging.
Expand Down
6 changes: 6 additions & 0 deletions pkgs/cupertino_http/lib/src/cupertino_web_socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class ConnectionException extends WebSocketException {

/// A [WebSocket] implemented using the
/// [NSURLSessionWebSocketTask API](https://developer.apple.com/documentation/foundation/nsurlsessionwebsockettask).
///
/// NOTE: the [WebSocket] interface is currently experimental and may change in
/// the future.
class CupertinoWebSocket implements WebSocket {
/// Create a new WebSocket connection using the
/// [NSURLSessionWebSocketTask API](https://developer.apple.com/documentation/foundation/nsurlsessionwebsockettask).
Expand All @@ -31,6 +34,9 @@ class CupertinoWebSocket implements WebSocket {
/// If provided, the [protocols] argument indicates that subprotocols that
/// the peer is able to select. See
/// [RFC-6455 1.9](https://datatracker.ietf.org/doc/html/rfc6455#section-1.9).
///
/// NOTE: the [WebSocket] interface is currently experimental and may change
/// in the future.
static Future<CupertinoWebSocket> connect(Uri url,
{Iterable<String>? protocols, URLSessionConfiguration? config}) async {
if (!url.isScheme('ws') && !url.isScheme('wss')) {
Expand Down
Loading

0 comments on commit fd44043

Please sign in to comment.