Initial the vnc when the first frame is received as well

This commit is contained in:
Sharat M R 2020-03-18 15:35:26 +05:30
parent 3eba16c7fd
commit b3690f72c5
No known key found for this signature in database
GPG Key ID: E450A6E45DAE1B94
1 changed files with 23 additions and 9 deletions

View File

@ -4,6 +4,8 @@
// #include "IOHIDHandle.xm" // #include "IOHIDHandle.xm"
#define kSettingsPath [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Preferences/com.cosmosgenius.screendump.plist"]
static bool CCSisEnabled = true; static bool CCSisEnabled = true;
static rfbScreenInfoPtr screen; static rfbScreenInfoPtr screen;
static bool isVNCRunning; static bool isVNCRunning;
@ -60,6 +62,7 @@ static void VNCSetup() {
screen->kbdAddEvent = &handleVNCKeyboard; screen->kbdAddEvent = &handleVNCKeyboard;
screen->ptrAddEvent = &handleVNCPointer; screen->ptrAddEvent = &handleVNCPointer;
free(arg0); free(arg0);
VNCUpdateRunState(CCSisEnabled);
} }
static void VNCBlack() { static void VNCBlack() {
@ -164,15 +167,28 @@ static void OnFrameUpdate(IOMobileFramebufferRef fb, IOSurfaceRef buffer) {
rfbMarkRectAsModified(screen, 0, 0, width, height); rfbMarkRectAsModified(screen, 0, 0, width, height);
} }
static void loadPrefs() static void loadPrefs(void)
{ {
CFPreferencesAppSynchronize(CFSTR("com.cosmosgenius.screendump")); NSDictionary* prefs = nil;
Boolean valid; CFStringRef appID = CFSTR("com.cosmosgenius.screendump");
bool enabled(CFPreferencesGetAppBooleanValue(CFSTR("CCSisEnabled"), CFSTR("com.cosmosgenius.screendump"), &valid)); CFArrayRef keyList = CFPreferencesCopyKeyList(appID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
CCSisEnabled = enabled; if(keyList) {
@synchronized (lock) { prefs = (NSDictionary *)CFPreferencesCopyMultiple(keyList, appID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
VNCUpdateRunState(CCSisEnabled); if(!prefs) {
prefs = [NSDictionary new];
}
CFRelease(keyList);
} }
if(!prefs) {
prefs = [NSDictionary dictionaryWithContentsOfFile:kSettingsPath];
}
if(prefs) {
CCSisEnabled = [prefs objectForKey:@"CCSisEnabled"] ? [[prefs objectForKey:@"CCSisEnabled"] boolValue] : CCSisEnabled;
[prefs release];
}
VNCUpdateRunState(CCSisEnabled);
} }
%hookf(kern_return_t, IOMobileFramebufferSwapSetLayer, IOMobileFramebufferRef fb, int layer, IOSurfaceRef buffer, CGRect bounds, CGRect frame, int flags) { %hookf(kern_return_t, IOMobileFramebufferSwapSetLayer, IOMobileFramebufferRef fb, int layer, IOSurfaceRef buffer, CGRect bounds, CGRect frame, int flags) {
@ -187,7 +203,6 @@ static void loadPrefs()
NULL, (CFNotificationCallback)loadPrefs, NULL, (CFNotificationCallback)loadPrefs,
CFSTR("com.cosmosgenius.screendump/preferences.changed"), CFSTR("com.cosmosgenius.screendump/preferences.changed"),
NULL, CFNotificationSuspensionBehaviorCoalesce); NULL, CFNotificationSuspensionBehaviorCoalesce);
lock = [[NSLock alloc] init];
loadPrefs(); loadPrefs();
} }
@ -418,6 +433,5 @@ static void handleVNCKeyboard(rfbBool down, rfbKeySym key, rfbClientPtr client)
} }
static void handleVNCPointer(int buttons, int x, int y, rfbClientPtr client) { static void handleVNCPointer(int buttons, int x, int y, rfbClientPtr client) {
NSLog(@"sharat %ld %ld %ld", buttons, x, y);
VNCPointer(buttons, x, y, client); VNCPointer(buttons, x, y, client);
} }