Visitar URL original
Made the imitation_game start reporting its results in the README.md. by gaaclarke · Pull Request #193 · flutter/packages · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
ran the formatter
  • Loading branch information
gaaclarke committed Aug 18, 2020
commit eb321d099310e79b4395f3c6ebbf895a2179fd73
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ Future<void> _sendResult(double result) async {
body: jsonEncode(<String, dynamic>{
'test': 'smiley',
'platform': 'flutter',
'results': <String, double>{
'startupTime': result
},
'results': <String, double>{'startupTime': result},
}),
);
if (response.statusCode != 200) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

@interface AppDelegate : UIResponder <UIApplicationDelegate>


@end

Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ @interface AppDelegate ()

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}


#pragma mark - UISceneSession lifecycle


- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options {
- (UISceneConfiguration *)application:(UIApplication *)application
configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession
options:(UISceneConnectionOptions *)options {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role];
return [[UISceneConfiguration alloc] initWithName:@"Default Configuration"
sessionRole:connectingSceneSession.role];
}


- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
- (void)application:(UIApplication *)application
didDiscardSceneSessions:(NSSet<UISceneSession *> *)sceneSessions {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
// If any sessions were discarded while the application was not running, this will be called
// shortly after application:didFinishLaunchingWithOptions. Use this method to release any
// resources that were specific to the discarded scenes, as they will not return.
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>

@property (strong, nonatomic) UIWindow * window;
@property(strong, nonatomic) UIWindow* window;

@end

Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,43 @@ @interface SceneDelegate ()

@implementation SceneDelegate


- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
- (void)scene:(UIScene *)scene
willConnectToSession:(UISceneSession *)session
options:(UISceneConnectionOptions *)connectionOptions {
// Use this method to optionally configure and attach the UIWindow `window` to the provided
// UIWindowScene `scene`. If using a storyboard, the `window` property will automatically be
// initialized and attached to the scene. This delegate does not imply the connecting scene or
// session are new (see `application:configurationForConnectingSceneSession` instead).
}


- (void)sceneDidDisconnect:(UIScene *)scene {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead).
// Release any resources associated with this scene that can be re-created the next time the scene
// connects. The scene may re-connect later, as its session was not neccessarily discarded (see
// `application:didDiscardSceneSessions` instead).
}


- (void)sceneDidBecomeActive:(UIScene *)scene {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was
// inactive.
}


- (void)sceneWillResignActive:(UIScene *)scene {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}


- (void)sceneWillEnterForeground:(UIScene *)scene {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}


- (void)sceneDidEnterBackground:(UIScene *)scene {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
// Use this method to save data, release shared resources, and store enough scene-specific state
// information to restore the scene back to its current state.
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
@property(nonatomic, strong) IBOutlet UIImageView* imageView;

@end

Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ static int64_t loadStartupTime(NSError **error) {
struct timeval startTime = proc.kp_proc.p_starttime;
int64_t microsecondsInSecond = 1000000LL;
int64_t microsecondsSinceEpoch =
(int64_t)(startTime.tv_sec * microsecondsInSecond) +
(int64_t)startTime.tv_usec;
(int64_t)(startTime.tv_sec * microsecondsInSecond) + (int64_t)startTime.tv_usec;

return microsecondsSinceEpoch;
}
Expand All @@ -34,16 +33,14 @@ static int64_t loadStartupTime(NSError **error) {
#if TARGET_IPHONE_SIMULATOR
return @"127.0.0.1:4040";
#else
NSString *ipPath = [[NSBundle mainBundle] pathForResource:@"ip"
ofType:@"txt"];
NSString *ipPath = [[NSBundle mainBundle] pathForResource:@"ip" ofType:@"txt"];
NSError *err;
NSString *ipAddress = [NSString stringWithContentsOfFile:ipPath
encoding:NSUTF8StringEncoding
error:&err];
assert(err == nil);
return [ipAddress
stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];
return
[ipAddress stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
#endif
}

Expand All @@ -54,30 +51,27 @@ static void sendResults(NSTimeInterval result) {
NSMutableURLRequest *urlRequest =
[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
NSDictionary *payload = @{
@"test": @"smiley",
@"platform": @"uikit",
@"test" : @"smiley",
@"platform" : @"uikit",
@"results" : @{
@"startupTime" : @(result),
}
};
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:payload
options:0
error:&error];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:payload options:0 error:&error];
assert(error == nil && jsonData);
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:jsonData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session
dataTaskWithRequest:urlRequest
completionHandler:^(NSData *data, NSURLResponse *response,
NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode != 200) {
NSLog(@"Error %@ '%@'", error, url);
}
}];
NSURLSessionDataTask *dataTask =
[session dataTaskWithRequest:urlRequest
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode != 200) {
NSLog(@"Error %@ '%@'", error, url);
}
}];
[dataTask resume];
}

Expand All @@ -95,10 +89,8 @@ - (void)viewDidLoad {

- (void)loadView {
[super loadView];
self.displayLink = [CADisplayLink displayLinkWithTarget:self
selector:@selector(onTick:)];
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop]
forMode:NSRunLoopCommonModes];
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onTick:)];
[self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
self.imageView.image = [UIImage imageNamed:@"smiley"];
_waitingForDraw = YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
int main(int argc, char* argv[]) {
NSString* appDelegateClassName;
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
// Setup code that might create autoreleased objects goes here.
appDelegateClassName = NSStringFromClass([AppDelegate class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}