mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-09-28 19:55:16 +00:00
Compare commits
3 Commits
4684df5fc6
...
20ba0d8d52
Author | SHA1 | Date | |
---|---|---|---|
|
20ba0d8d52 | ||
|
77b060fc3e | ||
|
3d6e952320 |
@ -37,6 +37,7 @@
|
|||||||
-(void)setMinificationFilter:(NSString*)filter;
|
-(void)setMinificationFilter:(NSString*)filter;
|
||||||
-(void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(NSUInteger)controlEvents;
|
-(void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(NSUInteger)controlEvents;
|
||||||
-(void)setIdleTimerDisabled:(BOOL)disabled;
|
-(void)setIdleTimerDisabled:(BOOL)disabled;
|
||||||
|
-(BOOL)prefersStatusBarHidden;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface InterfaceController () <WKExtendedRuntimeSessionDelegate>
|
@interface InterfaceController () <WKExtendedRuntimeSessionDelegate>
|
||||||
@ -48,6 +49,7 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||||||
@implementation InterfaceController
|
@implementation InterfaceController
|
||||||
{
|
{
|
||||||
WKExtendedRuntimeSession *runtimeSession;
|
WKExtendedRuntimeSession *runtimeSession;
|
||||||
|
BOOL hasStartedEmulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)load {
|
+ (void)load {
|
||||||
@ -57,6 +59,12 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||||||
Method m = class_getInstanceMethod(CLKTimeFormatter, @selector(timeText));
|
Method m = class_getInstanceMethod(CLKTimeFormatter, @selector(timeText));
|
||||||
method_setImplementation(m, imp_implementationWithBlock(^NSString*(id self, SEL _cmd) { return @" "; }));
|
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 {
|
+ (id<Emulator>)sharedEmulator {
|
||||||
@ -114,13 +122,14 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||||||
|
|
||||||
- (void)willActivate {
|
- (void)willActivate {
|
||||||
if ([WKExtension sharedExtension].applicationState == WKApplicationStateActive) {
|
if ([WKExtension sharedExtension].applicationState == WKApplicationStateActive) {
|
||||||
sharedEmulator.running = YES;
|
[self startRuntimeSession];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didDeactivate {
|
- (void)didDeactivate {
|
||||||
// This method is called when watch view controller is no longer visible
|
// This method is called when watch view controller is no longer visible
|
||||||
[super didDeactivate];
|
[super didDeactivate];
|
||||||
|
[runtimeSession invalidate];
|
||||||
sharedEmulator.running = NO;
|
sharedEmulator.running = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +137,21 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||||||
//uint32_t connected = session.activationState == WCSessionActivationStateActivated && session.reachable;
|
//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 {
|
- (void)loadAndStartEmulator {
|
||||||
#ifdef LTOVRTCP_SERVER
|
#ifdef LTOVRTCP_SERVER
|
||||||
setenv("LTOVRTCP_SERVER", LTOVRTCP_SERVER, 1);
|
setenv("LTOVRTCP_SERVER", LTOVRTCP_SERVER, 1);
|
||||||
@ -155,18 +179,36 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||||||
sharedEmulator.screenLayer = fullScreenView.layer;
|
sharedEmulator.screenLayer = fullScreenView.layer;
|
||||||
sharedEmulator.speed = sharedEmulator.initialSpeed;
|
sharedEmulator.speed = sharedEmulator.initialSpeed;
|
||||||
[sharedEmulator.screenLayer setContentsGravity:@"CAGravityResizeAspectFill"];
|
[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"];
|
[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];
|
TrackPad *trackpad = [[TrackPad alloc] initWithFrame:fullScreenView.bounds];
|
||||||
[fullScreenView addSubview:trackpad];
|
[fullScreenView addSubview:trackpad];
|
||||||
|
|
||||||
runtimeSession = [WKExtendedRuntimeSession new];
|
[self startRuntimeSession];
|
||||||
runtimeSession.delegate = self;
|
}
|
||||||
[runtimeSession start];
|
|
||||||
|
- (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 {
|
- (void)extendedRuntimeSessionDidStart:(WKExtendedRuntimeSession *)extendedRuntimeSession {
|
||||||
@ -178,8 +220,10 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
|||||||
error:NULL];
|
error:NULL];
|
||||||
[[AVAudioSession sharedInstance] activateWithOptions:0 completionHandler:^(BOOL activated, NSError * _Nullable error) {
|
[[AVAudioSession sharedInstance] activateWithOptions:0 completionHandler:^(BOOL activated, NSError * _Nullable error) {
|
||||||
// network only works on watchOS when there's an active audio session
|
// 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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,14 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface UIScreen : NSObject
|
||||||
|
|
||||||
|
@property(nonatomic, readonly) CGRect bounds;
|
||||||
|
|
||||||
|
+ (instancetype)mainScreen;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
#endif /* UIKit_h */
|
#endif /* UIKit_h */
|
||||||
|
Loading…
Reference in New Issue
Block a user