mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-06-19 22:29:28 +00:00
Compare commits
No commits in common. "20ba0d8d521b6112e651521b374c4ccb36bde6bb" and "4684df5fc6f7c98bfe45857f34285aeaf9b31794" have entirely different histories.
20ba0d8d52
...
4684df5fc6
|
@ -37,7 +37,6 @@
|
|||
-(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>
|
||||
|
@ -49,7 +48,6 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||
@implementation InterfaceController
|
||||
{
|
||||
WKExtendedRuntimeSession *runtimeSession;
|
||||
BOOL hasStartedEmulator;
|
||||
}
|
||||
|
||||
+ (void)load {
|
||||
|
@ -59,12 +57,6 @@ 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 {
|
||||
|
@ -122,14 +114,13 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||
|
||||
- (void)willActivate {
|
||||
if ([WKExtension sharedExtension].applicationState == WKApplicationStateActive) {
|
||||
[self startRuntimeSession];
|
||||
sharedEmulator.running = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didDeactivate {
|
||||
// This method is called when watch view controller is no longer visible
|
||||
[super didDeactivate];
|
||||
[runtimeSession invalidate];
|
||||
sharedEmulator.running = NO;
|
||||
}
|
||||
|
||||
|
@ -137,21 +128,6 @@ 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);
|
||||
|
@ -179,36 +155,18 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||
sharedEmulator.screenLayer = fullScreenView.layer;
|
||||
sharedEmulator.speed = sharedEmulator.initialSpeed;
|
||||
[sharedEmulator.screenLayer setContentsGravity:@"CAGravityResizeAspectFill"];
|
||||
CGFloat scale = [self bestScaleForScreen];
|
||||
[sharedEmulator.screenLayer setAffineTransform:CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI_2), scale, scale)];
|
||||
[sharedEmulator.screenLayer setAffineTransform:CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI_2), 0.375, 0.375)];
|
||||
[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];
|
||||
|
||||
[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;
|
||||
}
|
||||
runtimeSession = [WKExtendedRuntimeSession new];
|
||||
runtimeSession.delegate = self;
|
||||
[runtimeSession start];
|
||||
}
|
||||
|
||||
- (void)extendedRuntimeSessionDidStart:(WKExtendedRuntimeSession *)extendedRuntimeSession {
|
||||
|
@ -220,10 +178,8 @@ 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
|
||||
[self startOrResumeEmulator];
|
||||
[sharedEmulator performSelectorOnMainThread:@selector(run) withObject:nil waitUntilDone:NO];
|
||||
}];
|
||||
#else
|
||||
[self startOrResumeEmulator];
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -41,14 +41,6 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@end
|
||||
|
||||
@interface UIScreen : NSObject
|
||||
|
||||
@property(nonatomic, readonly) CGRect bounds;
|
||||
|
||||
+ (instancetype)mainScreen;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif /* UIKit_h */
|
||||
|
|
Loading…
Reference in New Issue
Block a user