Skip to content

Commit

Permalink
Add a service for toggling WiFi
Browse files Browse the repository at this point in the history
  • Loading branch information
Goshin committed Aug 16, 2020
1 parent ed40019 commit fa800fe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions HeliPort/Appearance/StatusMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
currentRunLoop.add(self.statusUpdateTimer!, forMode: .common)
currentRunLoop.run()
}

NSApp.servicesProvider = self
}

required init(coder: NSCoder) {
Expand Down Expand Up @@ -576,6 +578,13 @@ final class StatusMenu: NSMenu, NSMenuDelegate {
Log.debug("Disconnected from \(ssid)")
}
}

@objc func toggleWiFiServiceHandler(_ pboard: NSPasteboard, userData: String, error: NSErrorPointer) {
Log.debug("Handle Toggle WiFi service")
DispatchQueue.main.async {
self.clickMenuItem(self.switchItem)
}
}
}

// MARK: Localized Strings
Expand Down
14 changes: 14 additions & 0 deletions HeliPort/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSServices</key>
<array>
<dict>
<key>NSMenuItem</key>
<dict>
<key>default</key>
<string>HeliPort: Toggle WiFi</string>
</dict>
<key>NSMessage</key>
<string>toggleWiFiServiceHandler</string>
<key>NSRequiredContext</key>
<dict/>
</dict>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down

0 comments on commit fa800fe

Please # to comment.