Skip to content

Commit f74edab

Browse files
add ability to check bluetooth power state
1 parent 5cc049b commit f74edab

File tree

6 files changed

+59
-4
lines changed

6 files changed

+59
-4
lines changed

Bridging_Header.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,9 @@
1313
#import <MASShortcut/Shortcut.h>
1414

1515

16+
#import <IOBluetooth/Bluetooth.h>
17+
18+
void IOBluetoothPreferenceSetControllerPowerState(int);
19+
int IOBluetoothPreferenceGetControllerPowerState();
20+
1621
#endif /* Bridging_Header_h */

Wechsel.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
FD4D6EDD21A57170005DB70B /* Cartfile in Resources */ = {isa = PBXBuildFile; fileRef = FD4D6EDA21A5716F005DB70B /* Cartfile */; };
2121
FD4D6EDE21A57170005DB70B /* Cartfile.resolved in Resources */ = {isa = PBXBuildFile; fileRef = FD4D6EDB21A5716F005DB70B /* Cartfile.resolved */; };
2222
FD4D6EDF21A57170005DB70B /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = FD4D6EDC21A5716F005DB70B /* README.md */; };
23+
FD4D6EE121A586D6005DB70B /* BluetoothTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD4D6EE021A586D6005DB70B /* BluetoothTableView.swift */; };
2324
FDF41902219DD5D500A8E8E1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FDF41901219DD5D500A8E8E1 /* AppDelegate.swift */; };
2425
FDF41904219DD5D700A8E8E1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FDF41903219DD5D700A8E8E1 /* Assets.xcassets */; };
2526
FDF41907219DD5D700A8E8E1 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = FDF41905219DD5D700A8E8E1 /* MainMenu.xib */; };
@@ -67,6 +68,7 @@
6768
FD4D6EDA21A5716F005DB70B /* Cartfile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cartfile; sourceTree = "<group>"; };
6869
FD4D6EDB21A5716F005DB70B /* Cartfile.resolved */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cartfile.resolved; sourceTree = "<group>"; };
6970
FD4D6EDC21A5716F005DB70B /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
71+
FD4D6EE021A586D6005DB70B /* BluetoothTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BluetoothTableView.swift; sourceTree = "<group>"; };
7072
FDF418FE219DD5D500A8E8E1 /* wechsel.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = wechsel.app; sourceTree = BUILT_PRODUCTS_DIR; };
7173
FDF41901219DD5D500A8E8E1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7274
FDF41903219DD5D700A8E8E1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -119,6 +121,7 @@
119121
FDF41920219DD81600A8E8E1 /* MainWindow.xib */,
120122
FDF41923219DD93400A8E8E1 /* ViewController.swift */,
121123
FD4D6ED521A565C1005DB70B /* DeviceTableCellView.swift */,
124+
FD4D6EE021A586D6005DB70B /* BluetoothTableView.swift */,
122125
);
123126
path = Modal;
124127
sourceTree = "<group>";
@@ -328,6 +331,7 @@
328331
FD4D6ED621A565C1005DB70B /* DeviceTableCellView.swift in Sources */,
329332
FD4D6ED921A56AB3005DB70B /* TimeAgo.swift in Sources */,
330333
FD401BDC219F0DC80047F462 /* PreferenceWindowController.swift in Sources */,
334+
FD4D6EE121A586D6005DB70B /* BluetoothTableView.swift in Sources */,
331335
FD4CF5CA219F152400901936 /* Config.swift in Sources */,
332336
FDF41921219DD81600A8E8E1 /* MainWindowController.swift in Sources */,
333337
FDF41924219DD93400A8E8E1 /* ViewController.swift in Sources */,

wechsel/Helpers/Bluetooth.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ class Bluetooth {
5151
}
5252
}
5353

54+
func getBluetoothPowerState() -> Bool {
55+
let powerState = IOBluetoothPreferenceGetControllerPowerState()
56+
return powerState == 0 ? false : true
57+
}
58+
5459
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// BluetoothTableView.swift
3+
// wechsel
4+
//
5+
// Created by Friedrich Weise on 21.11.18.
6+
// Copyright © 2018 Friedrich Weise. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
11+
class BluetoothTableView: NSTableCellView {
12+
13+
override func draw(_ dirtyRect: NSRect) {
14+
super.draw(dirtyRect)
15+
16+
// Drawing code here.
17+
}
18+
19+
}

wechsel/Modal/MainWindow.xib

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<windowStyleMask key="styleMask" titled="YES" nonactivatingPanel="YES"/>
1717
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
1818
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
19-
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
19+
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
2020
<view key="contentView" wantsLayer="YES" id="se5-gp-TjO">
2121
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
2222
<autoresizingMask key="autoresizingMask"/>
@@ -87,6 +87,30 @@
8787
<outlet property="progressIndicator" destination="dfO-JY-pi1" id="gr5-yb-84T"/>
8888
</connections>
8989
</tableCellView>
90+
<tableCellView identifier="bluetoothRow" id="ffo-2V-Vu9" customClass="BluetoothTableView" customModule="wechsel" customModuleProvider="target">
91+
<rect key="frame" x="1" y="43" width="477" height="40"/>
92+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
93+
<subviews>
94+
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rAX-0F-xDj">
95+
<rect key="frame" x="10" y="14" width="12" height="12"/>
96+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
97+
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="statusDisabled" id="QlO-n1-SBt"/>
98+
</imageView>
99+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="S7d-oH-Az9">
100+
<rect key="frame" x="36" y="9" width="290" height="21"/>
101+
<autoresizingMask key="autoresizingMask"/>
102+
<textFieldCell key="cell" lineBreakMode="clipping" title="System Bluetooth" id="0BF-ML-Fzo">
103+
<font key="font" metaFont="systemSemibold" size="16"/>
104+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
105+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
106+
</textFieldCell>
107+
</textField>
108+
<progressIndicator wantsLayer="YES" horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="V24-zb-ToC">
109+
<rect key="frame" x="8" y="12" width="16" height="16"/>
110+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
111+
</progressIndicator>
112+
</subviews>
113+
</tableCellView>
90114
</prototypeCellViews>
91115
</tableColumn>
92116
</tableColumns>

wechsel/Modal/ViewController.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class ViewController: NSViewController {
1818
override func viewDidLoad() {
1919
super.viewDidLoad()
2020

21-
tableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false)
2221
tableView.target = self
2322
tableView.doubleAction = #selector(tableViewDoubleClick(_:))
2423
}
2524
/* modal window gets shown */
2625
override func viewWillAppear() {
2726
super.viewWillAppear()
27+
tableView.selectRowIndexes(IndexSet(integer: 0), byExtendingSelection: false)
2828
reloadTableView()
2929
}
3030

@@ -80,11 +80,9 @@ class ViewController: NSViewController {
8080
}
8181

8282
extension ViewController: NSTableViewDataSource {
83-
8483
func numberOfRows(in tableView: NSTableView) -> Int {
8584
return Config.numberOfDevices
8685
}
87-
8886
}
8987

9088
extension ViewController: NSTableViewDelegate {

0 commit comments

Comments
 (0)