mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
directory on the device. This work is to support a workflow where developers testing on an iOS device will automatically see their app updates as they change their Sky code. Currently this works by using the ios-deploy tool: $ ios-deploy --bundle_id 'org.domokit.sky.game' --upload out/ios_Debug/game_app.app/app.skyx --to Documents/app.skyx Upcoming commits will incorporate this into skytool.
100 lines
2.5 KiB
Objective-C
Executable File
100 lines
2.5 KiB
Objective-C
Executable File
// 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 |