forked from flutter/engine
-
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.
Merge pull request flutter#426 from iansf/ios_refresh
Allow iOS apps to restart by copying the app.skyx to the Documents directory on the device.
- Loading branch information
Showing
4 changed files
with
156 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2015 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. | ||
|
||
#ifndef NDEBUG | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface DocumentWatcher : NSThread | ||
- (instancetype)initWithDocumentPath:(NSString*)path callbackBlock:(void (^)(void))callbackBlock; | ||
- (void)cancel; | ||
@end | ||
|
||
#endif // !NDEBUG |
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,100 @@ | ||
// Copyright 2015 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. | ||
#ifndef NDEBUG | ||
#import "document_watcher.h" | ||
|
||
@interface DocumentWatcher () | ||
|
||
@property(nonatomic, readonly) NSDate* lastModifiedDate; | ||
@property (copy) void (^callbackBlock)(void); | ||
|
||
@end | ||
|
||
@implementation DocumentWatcher { | ||
NSString* _documentPath; | ||
NSTimer* _timer; | ||
CFRunLoopRef _loop; | ||
} | ||
|
||
@synthesize lastModifiedDate = _lastModifiedDate; | ||
|
||
- (instancetype)initWithDocumentPath:(NSString*)path callbackBlock:(void (^)(void))callbackBlock { | ||
self = [super init]; | ||
|
||
if (self) { | ||
_documentPath = path; | ||
self.callbackBlock = callbackBlock; | ||
|
||
[self start]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
- (void)main { | ||
[self onCheck:nil]; | ||
_timer = [[NSTimer scheduledTimerWithTimeInterval:1.0 | ||
target:self | ||
selector:@selector(onCheck:) | ||
userInfo:nil | ||
repeats:YES] retain]; | ||
while (!self.isCancelled) { | ||
_loop = CFRunLoopGetCurrent(); | ||
CFRunLoopRunInMode(kCFRunLoopDefaultMode, | ||
[[NSDate distantFuture] timeIntervalSinceNow], YES); | ||
} | ||
} | ||
|
||
- (void)_setLastModifiedDate:(NSDate*)lastModifiedDate path:(NSString*)path { | ||
if ([_lastModifiedDate isEqualToDate:lastModifiedDate]) { | ||
return; | ||
} | ||
|
||
[_lastModifiedDate release]; | ||
_lastModifiedDate = [lastModifiedDate retain]; | ||
|
||
if (_lastModifiedDate == nil && lastModifiedDate == nil) { | ||
return; | ||
} | ||
|
||
dispatch_async(dispatch_get_main_queue(), self.callbackBlock); | ||
} | ||
|
||
- (void)onCheck:(id)sender { | ||
if (![[NSFileManager defaultManager] fileExistsAtPath:_documentPath]) { | ||
return; | ||
} | ||
|
||
NSError* error = nil; | ||
NSDictionary* attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:_documentPath | ||
error:&error]; | ||
if (error != nil) { | ||
NSLog(@"[DocumentWatcher onCheck]: error reading attributes for path %@: %@", _documentPath, error); | ||
return; | ||
} | ||
|
||
[self _setLastModifiedDate:attributes.fileModificationDate path:_documentPath]; | ||
} | ||
|
||
- (void)cancel { | ||
[_timer invalidate]; | ||
[_timer release]; | ||
_timer = nil; | ||
|
||
if (_loop) { | ||
CFRunLoopWakeUp(_loop); | ||
_loop = NULL; | ||
} | ||
|
||
[super cancel]; | ||
} | ||
|
||
- (void)dealloc { | ||
[_documentPath release]; | ||
[_lastModifiedDate release]; | ||
[super dealloc]; | ||
} | ||
|
||
@end | ||
#endif // !NDEBUG |
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