Browse Source

wire up control to launch at startup in preferences

Grant Limberg 9 years ago
parent
commit
decb4261d4

+ 23 - 0
ZeroTier One/PreferencesViewController.swift

@@ -10,9 +10,32 @@ import Cocoa
 
 class PreferencesViewController: NSViewController {
 
+    @IBOutlet var startupCheckBox: NSButton!
+
+    let launchController = LaunchAtLoginController()
+
     override func viewDidLoad() {
         super.viewDidLoad()
         // Do view setup here.
+
+        if launchController.launchAtLogin {
+            startupCheckBox.state = NSOnState
+        }
+        else {
+            startupCheckBox.state = NSOffState
+        }
+    }
+
+    @IBAction func onStartupCheckBoxChanged(sender: NSButton) {
+        let bundle = NSBundle.mainBundle()
+        let bundleURL = bundle.bundleURL
+
+        if sender.state == NSOnState {
+            launchController.setLaunchAtLogin(true, forURL: bundleURL)
+        }
+        else {
+            launchController.setLaunchAtLogin(false, forURL: bundleURL)
+        }
     }
     
 }

+ 18 - 4
ZeroTier One/PreferencesViewController.xib

@@ -1,19 +1,33 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10101" systemVersion="15E32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10101"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="PreferencesViewController" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="PreferencesViewController" customModule="ZeroTier_One" customModuleProvider="target">
             <connections>
+                <outlet property="startupCheckBox" destination="XSk-jN-ner" id="nvL-b1-gza"/>
                 <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
             </connections>
         </customObject>
         <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
         <customObject id="-3" userLabel="Application" customClass="NSObject"/>
         <customView id="Hz6-mo-xeY">
-            <rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
+            <rect key="frame" x="0.0" y="0.0" width="284" height="54"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+            <subviews>
+                <button fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="XSk-jN-ner">
+                    <rect key="frame" x="18" y="18" width="248" height="18"/>
+                    <buttonCell key="cell" type="check" title="Start ZeroTier One on system startup" bezelStyle="regularSquare" imagePosition="left" state="on" inset="2" id="VkJ-h4-tHf">
+                        <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
+                        <font key="font" metaFont="system"/>
+                    </buttonCell>
+                    <connections>
+                        <action selector="onStartupCheckBoxChanged:" target="-2" id="zAQ-DJ-c3w"/>
+                    </connections>
+                </button>
+            </subviews>
+            <point key="canvasLocation" x="365" y="208"/>
         </customView>
     </objects>
 </document>