mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-06-08 11:32:36 +00:00
better handling of extended runtime session, maybe
This commit is contained in:
parent
77b060fc3e
commit
20ba0d8d52
|
@ -49,6 +49,7 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
||||||
@implementation InterfaceController
|
@implementation InterfaceController
|
||||||
{
|
{
|
||||||
WKExtendedRuntimeSession *runtimeSession;
|
WKExtendedRuntimeSession *runtimeSession;
|
||||||
|
BOOL hasStartedEmulator;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)load {
|
+ (void)load {
|
||||||
|
@ -121,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,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);
|
||||||
|
@ -165,16 +182,11 @@ static NSObject<Emulator> *sharedEmulator = nil;
|
||||||
CGFloat scale = [self bestScaleForScreen];
|
CGFloat scale = [self bestScaleForScreen];
|
||||||
[sharedEmulator.screenLayer setAffineTransform:CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI_2), scale, scale)];
|
[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 {
|
- (CGFloat)bestScaleForScreen {
|
||||||
|
@ -208,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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user