-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jiale
committed
Apr 17, 2019
1 parent
015a46a
commit 01a0729
Showing
14 changed files
with
1,030 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
AutoSwitch.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
AutoSwitch.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// AppDelegate.swift | ||
// AutoSwitch | ||
// | ||
// Created by ens on 2019/4/15. | ||
// Copyright © 2019 jialeens. All rights reserved. | ||
// | ||
|
||
import Cocoa | ||
|
||
@NSApplicationMain | ||
class AppDelegate: NSObject, NSApplicationDelegate { | ||
|
||
|
||
@IBOutlet weak var statusMenu: NSMenu! | ||
|
||
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) | ||
@IBAction func openPreference(_ sender: Any) { | ||
|
||
} | ||
@IBAction func appClose(_ sender: Any) { | ||
NSApplication.shared.terminate(self); | ||
} | ||
|
||
func applicationDidFinishLaunching(_ aNotification: Notification) { | ||
statusItem.button?.title = "🌞"; | ||
statusItem.menu = statusMenu; | ||
self.addNotifications(); | ||
} | ||
|
||
/// <#Description#> 增加监听器 | ||
func addNotifications() { | ||
NSLog("fileNotifications", NSNull()) | ||
NSWorkspace.shared.notificationCenter.addObserver( | ||
self, selector: #selector(onWakeNote(note:)), | ||
name: NSWorkspace.didWakeNotification, object: nil) | ||
|
||
NSWorkspace.shared.notificationCenter.addObserver( | ||
self, selector: #selector(onSleepNote(note:)), | ||
name: NSWorkspace.willSleepNotification, object: nil) | ||
} | ||
|
||
/// <#Description#> 唤醒时方法 | ||
/// | ||
/// - Parameter note: <#note description#> | ||
@objc func onWakeNote(note: NSNotification) { | ||
commandLineTask("/bin/sh",["-c","networksetup -setairportpower 'Wi-Fi' on"]) | ||
commandLineTask("/usr/local/bin/blueutil",["--power","1"]) | ||
} | ||
|
||
/// <#Description#> 休眠时方法 | ||
/// | ||
/// - Parameter note: <#note description#> | ||
@objc func onSleepNote(note: NSNotification) { | ||
commandLineTask("/bin/sh",["-c","networksetup -setairportpower 'Wi-Fi' off"]) | ||
commandLineTask("/usr/local/bin/blueutil",["--power","0"]) | ||
} | ||
func applicationWillTerminate(_ aNotification: Notification) { | ||
NSLog("app exit!", NSNull()) | ||
} | ||
|
||
/// <#Description#> 执行通用命令方法 | ||
/// | ||
/// - Parameters: | ||
/// - launchpath: <#launchpath description#> | ||
/// - command: <#command description#> | ||
func commandLineTask(_ launchpath : String,_ command: [String]) { | ||
let process = Process() | ||
process.launchPath = launchpath | ||
let arguments = command | ||
print(arguments) | ||
process.arguments = arguments | ||
|
||
let pipe = Pipe() | ||
process.standardOutput = pipe | ||
let file = pipe.fileHandleForReading | ||
process.launch() | ||
let data = file.readDataToEndOfFile() | ||
let string = String(data: data, encoding: .utf8) | ||
|
||
print("got \n" + (string ?? "")) | ||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
AutoSwitch/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "16x16", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "32x32", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "128x128", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "256x256", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"size" : "512x512", | ||
"scale" : "2x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>com.apple.security.files.user-selected.read-write</key> | ||
<true/> | ||
<key>com.apple.security.network.client</key> | ||
<true/> | ||
<key>com.apple.security.app-sandbox</key> | ||
<true/> | ||
<key>com.apple.security.files.user-selected.read-only</key> | ||
<true/> | ||
<key>com.apple.security.temporary-exception.files.absolute-path.read-write</key> | ||
<array> | ||
<string>/usr/local/bin/blueutil/string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Application--> | ||
<scene sceneID="JPo-4y-FX3"> | ||
<objects> | ||
<application id="hnw-xV-0zn" sceneMemberID="viewController"> | ||
<menu key="mainMenu" title="Main Menu" systemMenu="main" id="AYu-sK-qS6"> | ||
<items> | ||
<menuItem title="AutoMacOS" id="1Xt-HY-uBw"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<menu key="submenu" title="AutoMacOS" systemMenu="apple" id="uQy-DD-JDr"> | ||
<items> | ||
<menuItem title="About AutoMacOS" id="5kV-Vb-QxS"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<connections> | ||
<action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/> | ||
</connections> | ||
</menuItem> | ||
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/> | ||
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"> | ||
<connections> | ||
<action selector="openPreference:" target="Voe-Tx-rLC" id="yGX-lQ-I5D"/> | ||
</connections> | ||
</menuItem> | ||
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/> | ||
<menuItem title="Services" id="NMo-om-nkz"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/> | ||
</menuItem> | ||
<menuItem isSeparatorItem="YES" id="4je-JR-u6R"/> | ||
<menuItem title="Hide AutoMacOS" keyEquivalent="h" id="Olw-nP-bQN"> | ||
<connections> | ||
<action selector="hide:" target="Ady-hI-5gd" id="PnN-Uc-m68"/> | ||
</connections> | ||
</menuItem> | ||
<menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO"> | ||
<modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/> | ||
<connections> | ||
<action selector="hideOtherApplications:" target="Ady-hI-5gd" id="VT4-aY-XCT"/> | ||
</connections> | ||
</menuItem> | ||
<menuItem title="Show All" id="Kd2-mp-pUS"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<connections> | ||
<action selector="unhideAllApplications:" target="Ady-hI-5gd" id="Dhg-Le-xox"/> | ||
</connections> | ||
</menuItem> | ||
<menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/> | ||
<menuItem title="Quit AutoMacOS" keyEquivalent="q" id="4sb-4s-VLi"> | ||
<connections> | ||
<action selector="terminate:" target="Ady-hI-5gd" id="Te7-pn-YzF"/> | ||
</connections> | ||
</menuItem> | ||
</items> | ||
</menu> | ||
</menuItem> | ||
<menuItem title="Window" id="aUF-d1-5bR"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<menu key="submenu" title="Window" systemMenu="window" id="Td7-aD-5lo"> | ||
<items> | ||
<menuItem title="Minimize" keyEquivalent="m" id="OY7-WF-poV"> | ||
<connections> | ||
<action selector="performMiniaturize:" target="Ady-hI-5gd" id="VwT-WD-YPe"/> | ||
</connections> | ||
</menuItem> | ||
<menuItem title="Zoom" id="R4o-n2-Eq4"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<connections> | ||
<action selector="performZoom:" target="Ady-hI-5gd" id="DIl-cC-cCs"/> | ||
</connections> | ||
</menuItem> | ||
<menuItem isSeparatorItem="YES" id="eu3-7i-yIM"/> | ||
<menuItem title="Bring All to Front" id="LE2-aR-0XJ"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<connections> | ||
<action selector="arrangeInFront:" target="Ady-hI-5gd" id="DRN-fu-gQh"/> | ||
</connections> | ||
</menuItem> | ||
</items> | ||
</menu> | ||
</menuItem> | ||
<menuItem title="Help" id="wpr-3q-Mcd"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<menu key="submenu" title="Help" systemMenu="help" id="F2S-fz-NVQ"> | ||
<items> | ||
<menuItem title="AutoMacOS Help" keyEquivalent="?" id="FKE-Sm-Kum"> | ||
<connections> | ||
<action selector="showHelp:" target="Ady-hI-5gd" id="y7X-2Q-9no"/> | ||
</connections> | ||
</menuItem> | ||
</items> | ||
</menu> | ||
</menuItem> | ||
</items> | ||
</menu> | ||
<connections> | ||
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/> | ||
</connections> | ||
</application> | ||
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="AutoMacOS" customModuleProvider="target"> | ||
<connections> | ||
<outlet property="statusMenu" destination="rgy-IU-xXk" id="VNh-oR-yTb"/> | ||
</connections> | ||
</customObject> | ||
<customObject id="YLy-65-1bz" customClass="NSFontManager"/> | ||
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> | ||
<menu id="rgy-IU-xXk"> | ||
<items> | ||
<menuItem title="退出" id="dje-z4-yP9"> | ||
<modifierMask key="keyEquivalentModifierMask"/> | ||
<connections> | ||
<action selector="appClose:" target="Voe-Tx-rLC" id="aNG-qT-U9t"/> | ||
</connections> | ||
</menuItem> | ||
</items> | ||
</menu> | ||
</objects> | ||
<point key="canvasLocation" x="75" y="0.0"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>LSUIElement</key> | ||
<true/> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIconFile</key> | ||
<string></string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleVersion</key> | ||
<string>1</string> | ||
<key>LSMinimumSystemVersion</key> | ||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string> | ||
<key>NSHumanReadableCopyright</key> | ||
<string>Copyright © 2019 jialeens. All rights reserved.</string> | ||
<key>NSMainStoryboardFile</key> | ||
<string>Main</string> | ||
<key>NSPrincipalClass</key> | ||
<string>NSApplication</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// AutoSwitchTests.swift | ||
// AutoSwitchTests | ||
// | ||
// Created by ens on 2019/4/17. | ||
// Copyright © 2019 jialeens. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import AutoSwitch | ||
|
||
class AutoSwitchTests: XCTestCase { | ||
|
||
override func setUp() { | ||
// Put setup code here. This method is called before the invocation of each test method in the class. | ||
} | ||
|
||
override func tearDown() { | ||
// Put teardown code here. This method is called after the invocation of each test method in the class. | ||
} | ||
|
||
func testExample() { | ||
// This is an example of a functional test case. | ||
// Use XCTAssert and related functions to verify your tests produce the correct results. | ||
} | ||
|
||
func testPerformanceExample() { | ||
// This is an example of a performance test case. | ||
self.measure { | ||
// Put the code you want to measure the time of here. | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.