]> git.saurik.com Git - veency.git/commitdiff
Factor out implementation of condition_ signaling.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 10 Nov 2014 03:59:41 +0000 (19:59 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 10 Nov 2014 03:59:41 +0000 (19:59 -0800)
Tweak.mm

index d313bb4ead542f54e13f51ddab847efad5c5a813..1d0a930acd6802284e29b7b5158adcd0f477d171 100644 (file)
--- a/Tweak.mm
+++ b/Tweak.mm
@@ -276,16 +276,18 @@ static void VNCEnabled();
 
 float (*$GSMainScreenScaleFactor)();
 
-static void OnUserNotification(CFUserNotificationRef notification, CFOptionFlags flags) {
+static void VNCAction(rfbNewClientAction action) {
     [condition_ lock];
+    action_ = action;
+    [condition_ signal];
+    [condition_ unlock];
+}
 
+static void OnUserNotification(CFUserNotificationRef notification, CFOptionFlags flags) {
     if ((flags & 0x3) == 1)
-        action_ = RFB_CLIENT_ACCEPT;
+        VNCAction(RFB_CLIENT_ACCEPT);
     else
-        action_ = RFB_CLIENT_REFUSE;
-
-    [condition_ signal];
-    [condition_ unlock];
+        VNCAction(RFB_CLIENT_REFUSE);
 
     CFRelease(notification);
 }
@@ -321,10 +323,7 @@ static void OnUserNotification(CFUserNotificationRef notification, CFOptionFlags
     }
 
     if (notification == NULL) {
-        [condition_ lock];
-        action_ = RFB_CLIENT_REFUSE;
-        [condition_ signal];
-        [condition_ unlock];
+        VNCAction(RFB_CLIENT_REFUSE);
         return;
     }
 
@@ -374,11 +373,9 @@ static void OnUserNotification(CFUserNotificationRef notification, CFOptionFlags
 @end
 
 MSInstanceMessage2(void, VNCAlertItem, alertSheet,buttonClicked, id, sheet, int, button) {
-    [condition_ lock];
-
     switch (button) {
         case 1:
-            action_ = RFB_CLIENT_ACCEPT;
+            VNCAction(RFB_CLIENT_ACCEPT);
 
             @synchronized (condition_) {
                 [VNCBridge registerClient];
@@ -386,12 +383,10 @@ MSInstanceMessage2(void, VNCAlertItem, alertSheet,buttonClicked, id, sheet, int,
         break;
 
         case 2:
-            action_ = RFB_CLIENT_REFUSE;
+            VNCAction(RFB_CLIENT_REFUSE);
         break;
     }
 
-    [condition_ signal];
-    [condition_ unlock];
     [self dismiss];
 }