|
|
|
@ -37,6 +37,7 @@
|
|
|
|
|
-(void)setMinificationFilter:(NSString*)filter;
|
|
|
|
|
-(void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(NSUInteger)controlEvents;
|
|
|
|
|
-(void)setIdleTimerDisabled:(BOOL)disabled;
|
|
|
|
|
-(BOOL)prefersStatusBarHidden;
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@interface InterfaceController () <WKExtendedRuntimeSessionDelegate>
|
|
|
|
@ -48,6 +49,7 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|
|
|
|
@implementation InterfaceController
|
|
|
|
|
{
|
|
|
|
|
WKExtendedRuntimeSession *runtimeSession;
|
|
|
|
|
BOOL hasStartedEmulator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (void)load {
|
|
|
|
@ -57,6 +59,12 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|
|
|
|
Method m = class_getInstanceMethod(CLKTimeFormatter, @selector(timeText));
|
|
|
|
|
method_setImplementation(m, imp_implementationWithBlock(^NSString*(id self, SEL _cmd) { return @" "; }));
|
|
|
|
|
}
|
|
|
|
|
/* hide status bar on watchOS 10 */
|
|
|
|
|
Class clsUIViewController = NSClassFromString(@"UIViewController");
|
|
|
|
|
if ([clsUIViewController instancesRespondToSelector:@selector(prefersStatusBarHidden)]) {
|
|
|
|
|
Method m = class_getInstanceMethod(clsUIViewController, @selector(prefersStatusBarHidden));
|
|
|
|
|
method_setImplementation(m, imp_implementationWithBlock(^BOOL(id self, SEL _cmd) { return YES; }));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (id<Emulator>)sharedEmulator {
|
|
|
|
@ -114,13 +122,14 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|
|
|
|
|
|
|
|
|
- (void)willActivate {
|
|
|
|
|
if ([WKExtension sharedExtension].applicationState == WKApplicationStateActive) {
|
|
|
|
|
sharedEmulator.running = YES;
|
|
|
|
|
[self startRuntimeSession];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didDeactivate {
|
|
|
|
|
// This method is called when watch view controller is no longer visible
|
|
|
|
|
[super didDeactivate];
|
|
|
|
|
[runtimeSession invalidate];
|
|
|
|
|
sharedEmulator.running = NO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -128,6 +137,21 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|
|
|
|
//uint32_t connected = session.activationState == WCSessionActivationStateActivated && session.reachable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)startRuntimeSession {
|
|
|
|
|
runtimeSession = [WKExtendedRuntimeSession new];
|
|
|
|
|
runtimeSession.delegate = self;
|
|
|
|
|
[runtimeSession start];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)startOrResumeEmulator {
|
|
|
|
|
if (!hasStartedEmulator) {
|
|
|
|
|
hasStartedEmulator = YES;
|
|
|
|
|
[sharedEmulator performSelectorOnMainThread:@selector(run) withObject:nil waitUntilDone:NO];
|
|
|
|
|
} else {
|
|
|
|
|
sharedEmulator.running = YES;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)loadAndStartEmulator {
|
|
|
|
|
#ifdef LTOVRTCP_SERVER
|
|
|
|
|
setenv("LTOVRTCP_SERVER", LTOVRTCP_SERVER, 1);
|
|
|
|
@ -155,18 +179,36 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|
|
|
|
sharedEmulator.screenLayer = fullScreenView.layer;
|
|
|
|
|
sharedEmulator.speed = sharedEmulator.initialSpeed;
|
|
|
|
|
[sharedEmulator.screenLayer setContentsGravity:@"CAGravityResizeAspectFill"];
|
|
|
|
|
[sharedEmulator.screenLayer setAffineTransform:CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI_2), 0.375, 0.375)];
|
|
|
|
|
CGFloat scale = [self bestScaleForScreen];
|
|
|
|
|
[sharedEmulator.screenLayer setAffineTransform:CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI_2), scale, scale)];
|
|
|
|
|
[sharedEmulator.screenLayer setMinificationFilter:@"CAFilterTrilinear"];
|
|
|
|
|
#if TARGET_OS_SIMULATOR
|
|
|
|
|
[sharedEmulator performSelector:@selector(run) withObject:nil afterDelay:0.1];
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
TrackPad *trackpad = [[TrackPad alloc] initWithFrame:fullScreenView.bounds];
|
|
|
|
|
[fullScreenView addSubview:trackpad];
|
|
|
|
|
|
|
|
|
|
runtimeSession = [WKExtendedRuntimeSession new];
|
|
|
|
|
runtimeSession.delegate = self;
|
|
|
|
|
[runtimeSession start];
|
|
|
|
|
[self startRuntimeSession];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGFloat)bestScaleForScreen {
|
|
|
|
|
CGSize screenSize = [UIScreen mainScreen].bounds.size;
|
|
|
|
|
NSInteger screenWidthAndHeight = (NSInteger)(screenSize.width) * 1000 + (NSInteger)(screenSize.height);
|
|
|
|
|
// manually selected scales to account for non-square screens
|
|
|
|
|
switch (screenWidthAndHeight) {
|
|
|
|
|
// 38 40 41 42 44 45 49
|
|
|
|
|
case 136170: // 38mm
|
|
|
|
|
return 0.33;
|
|
|
|
|
case 176215: // 41mm
|
|
|
|
|
return 0.40;
|
|
|
|
|
case 184224: // 44mm
|
|
|
|
|
return 0.42;
|
|
|
|
|
case 198242: // 45mm
|
|
|
|
|
case 205251: // 49mm
|
|
|
|
|
return 0.455;
|
|
|
|
|
case 162197: // 40mm
|
|
|
|
|
case 156195: // 42mm
|
|
|
|
|
default:
|
|
|
|
|
return 0.375;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)extendedRuntimeSessionDidStart:(WKExtendedRuntimeSession *)extendedRuntimeSession {
|
|
|
|
@ -178,8 +220,10 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|
|
|
|
error:NULL];
|
|
|
|
|
[[AVAudioSession sharedInstance] activateWithOptions:0 completionHandler:^(BOOL activated, NSError * _Nullable error) {
|
|
|
|
|
// network only works on watchOS when there's an active audio session
|
|
|
|
|
[sharedEmulator performSelectorOnMainThread:@selector(run) withObject:nil waitUntilDone:NO];
|
|
|
|
|
[self startOrResumeEmulator];
|
|
|
|
|
}];
|
|
|
|
|
#else
|
|
|
|
|
[self startOrResumeEmulator];
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|