parent
192f36a162
commit
0dbbbeefcd
|
@ -6,14 +6,12 @@
|
|||
// Copyright © 2020 David Wernhart. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import AppKit
|
||||
import SwiftUI
|
||||
import ServiceManagement
|
||||
import Foundation
|
||||
import LaunchAtLogin
|
||||
|
||||
@NSApplicationMain
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
//var window: NSWindow!
|
||||
var statusBarItem: NSStatusItem!
|
||||
|
@ -29,30 +27,25 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
popover.behavior = .transient
|
||||
popover.contentViewController = NSHostingController(rootView: contentView)
|
||||
self.popover = popover
|
||||
|
||||
|
||||
|
||||
let statusBar = NSStatusBar.system
|
||||
statusBarItem = statusBar.statusItem(
|
||||
withLength: NSStatusItem.squareLength)
|
||||
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.squareLength)
|
||||
statusBarItem.button?.image = NSImage(named: "menubaricon")!
|
||||
//statusBarItem.button?.title = "🍝"
|
||||
|
||||
if let button = self.statusBarItem.button {
|
||||
button.action = #selector(togglePopover(_:))
|
||||
}
|
||||
|
||||
statusBarItem.button?.action = #selector(togglePopover(_:))
|
||||
|
||||
Helper.instance.checkHelperVersion()
|
||||
|
||||
|
||||
LaunchAtLogin.isEnabled = true
|
||||
}
|
||||
|
||||
|
||||
@objc func togglePopover(_ sender: AnyObject?) {
|
||||
self.popover.contentViewController?.view.window?.becomeKey()
|
||||
popover.contentViewController?.view.window?.becomeKey()
|
||||
|
||||
if let button = self.statusBarItem.button {
|
||||
if self.popover.isShown {
|
||||
self.popover.performClose(sender)
|
||||
if popover.isShown {
|
||||
popover.performClose(sender)
|
||||
} else {
|
||||
self.popover.show(relativeTo: button.bounds, of: button, preferredEdge: NSRectEdge.minY)
|
||||
popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +53,5 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
func applicationWillTerminate(_ aNotification: Notification) {
|
||||
// Insert code here to tear down your application
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,60 +2,58 @@
|
|||
"images" : [
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "1x"
|
||||
"scale" : "1x",
|
||||
"size" : "16x16"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "16x16",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "16x16"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "1x"
|
||||
"scale" : "1x",
|
||||
"size" : "32x32"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "32x32",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "32x32"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "1x"
|
||||
"scale" : "1x",
|
||||
"size" : "128x128"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "128x128",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "128x128"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "spaghetti-2.png",
|
||||
"scale" : "1x"
|
||||
"scale" : "1x",
|
||||
"size" : "256x256"
|
||||
},
|
||||
{
|
||||
"size" : "256x256",
|
||||
"idiom" : "mac",
|
||||
"filename" : "spaghetti-1.png",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "256x256"
|
||||
},
|
||||
{
|
||||
"size" : "512x512",
|
||||
"idiom" : "mac",
|
||||
"filename" : "spaghetti.png",
|
||||
"scale" : "1x"
|
||||
"idiom" : "mac",
|
||||
"scale" : "1x",
|
||||
"size" : "512x512"
|
||||
},
|
||||
{
|
||||
"idiom" : "mac",
|
||||
"size" : "512x512",
|
||||
"scale" : "2x"
|
||||
"scale" : "2x",
|
||||
"size" : "512x512"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 73 KiB |
Binary file not shown.
Before Width: | Height: | Size: 73 KiB |
|
@ -6,21 +6,19 @@
|
|||
// Copyright © 2020 David Wernhart. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import SwiftUI
|
||||
import ServiceManagement
|
||||
import Foundation
|
||||
import ServiceManagement
|
||||
|
||||
protocol HelperDelegate {
|
||||
func OnMaxBatRead(value: UInt8)
|
||||
}
|
||||
|
||||
class Helper{
|
||||
|
||||
final class Helper {
|
||||
|
||||
static let instance = Helper()
|
||||
|
||||
|
||||
public var delegate: HelperDelegate?
|
||||
|
||||
|
||||
// var receiveMessage = "" {
|
||||
// didSet {
|
||||
// DispatchQueue.main.async {
|
||||
|
@ -33,15 +31,15 @@ class Helper{
|
|||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
lazy var helperToolConnection: NSXPCConnection = {
|
||||
let connection = NSXPCConnection(machServiceName: "com.davidwernhart.Helper.mach", options: .privileged)
|
||||
connection.remoteObjectInterface = NSXPCInterface(with: HelperToolProtocol.self)
|
||||
|
||||
|
||||
connection.resume()
|
||||
return connection
|
||||
}()
|
||||
|
||||
|
||||
@objc func installHelper() {
|
||||
print("trying to install helper!")
|
||||
var status = noErr
|
||||
|
@ -72,57 +70,55 @@ class Helper{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@objc func writeMaxBatteryCharge(setVal: UInt8){
|
||||
@objc func writeMaxBatteryCharge(setVal: UInt8) {
|
||||
SMCWriteByte(key: "BCLM", value: setVal)
|
||||
|
||||
|
||||
}
|
||||
|
||||
@objc func readMaxBatteryCharge(){
|
||||
SMCReadByte(key:"BCLM",withReply: { (value) in
|
||||
|
||||
@objc func readMaxBatteryCharge() {
|
||||
SMCReadByte(key: "BCLM") { value in
|
||||
print(String(value))
|
||||
self.delegate?.OnMaxBatRead(value: value)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@objc func checkHelperVersion() {
|
||||
print("checking helper version")
|
||||
if let helper = helperToolConnection.remoteObjectProxyWithErrorHandler({ (error) in
|
||||
let e = error as NSError
|
||||
let helper = helperToolConnection.remoteObjectProxyWithErrorHandler {
|
||||
let e = $0 as NSError
|
||||
print("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
self.installHelper()
|
||||
//self.receiveMessage.append("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
}) as? HelperToolProtocol {
|
||||
helper.getVersion(withReply: { (version) in
|
||||
print("helperVersion:", helperVersion, " version from helper:",version)
|
||||
if(!helperVersion.elementsEqual(version)){
|
||||
self.installHelper()
|
||||
}
|
||||
//self.receiveMessage.append("Version: \(version)\n")
|
||||
})
|
||||
}
|
||||
}
|
||||
} as? HelperToolProtocol
|
||||
|
||||
@objc func SMCReadByte(key:String, withReply reply: @escaping (UInt8) -> Void){
|
||||
if let helper = helperToolConnection.remoteObjectProxyWithErrorHandler({ (error) in
|
||||
let e = error as NSError
|
||||
print("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
//self.receiveMessage.append("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
}) as? HelperToolProtocol {
|
||||
helper.readSMCByte(key: key) { (value) in
|
||||
reply (value)
|
||||
helper?.getVersion { version in
|
||||
print("helperVersion:", helperVersion, " version from helper:", version)
|
||||
if !helperVersion.elementsEqual(version) {
|
||||
self.installHelper()
|
||||
}
|
||||
//self.receiveMessage.append("Version: \(version)\n")
|
||||
}
|
||||
}
|
||||
|
||||
@objc func SMCWriteByte(key:String,value:UInt8){
|
||||
if let helper = helperToolConnection.remoteObjectProxyWithErrorHandler({ (error) in
|
||||
let e = error as NSError
|
||||
@objc func SMCReadByte(key: String, withReply reply: @escaping (UInt8) -> Void) {
|
||||
let helper = helperToolConnection.remoteObjectProxyWithErrorHandler {
|
||||
let e = $0 as NSError
|
||||
print("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
//self.receiveMessage.append("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
}) as? HelperToolProtocol {
|
||||
helper.setSMCByte(key: key,value: value)
|
||||
} as? HelperToolProtocol
|
||||
|
||||
helper?.readSMCByte(key: key) {
|
||||
reply($0)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func SMCWriteByte(key: String, value: UInt8) {
|
||||
let helper = helperToolConnection.remoteObjectProxyWithErrorHandler {
|
||||
let e = $0 as NSError
|
||||
print("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
//self.receiveMessage.append("Remote proxy error \(e.code): \(e.localizedDescription) \(e.localizedRecoverySuggestion ?? "---")")
|
||||
} as? HelperToolProtocol
|
||||
|
||||
helper?.setSMCByte(key: key, value: value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ let helperVersion: String = "4" //for some reason the integrated version check d
|
|||
@objc(HelperToolProtocol) protocol HelperToolProtocol {
|
||||
//protocol HelperToolProtocol {
|
||||
func getVersion(withReply reply: @escaping (String) -> Void)
|
||||
|
||||
|
||||
//TODO: more functions for other data types, altough this is sufficient for battery max charge level
|
||||
func setSMCByte(key: String, value: UInt8)
|
||||
func readSMCByte(key: String, withReply reply: @escaping (UInt8) -> Void)
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
class HelperTool: NSObject, HelperToolProtocol {
|
||||
final class HelperTool: NSObject, HelperToolProtocol {
|
||||
func getVersion(withReply reply: (String) -> Void) {
|
||||
// let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString" as String) as? String ?? "(unknown version)"
|
||||
// let build = Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String ?? "(unknown build)"
|
||||
|
|
|
@ -528,35 +528,35 @@ public struct TemperatureSensors {
|
|||
public static let THUNDERBOLT_1 = TemperatureSensor(name: "THUNDERBOLT_1",
|
||||
code: FourCharCode(fromStaticString: "TI1P"))
|
||||
|
||||
public static let all = [AMBIENT_AIR_0.code : AMBIENT_AIR_0,
|
||||
AMBIENT_AIR_1.code : AMBIENT_AIR_1,
|
||||
CPU_0_DIE.code : CPU_0_DIE,
|
||||
CPU_0_DIODE.code : CPU_0_DIODE,
|
||||
CPU_0_HEATSINK.code : CPU_0_HEATSINK,
|
||||
CPU_0_PROXIMITY.code : CPU_0_PROXIMITY,
|
||||
ENCLOSURE_BASE_0.code : ENCLOSURE_BASE_0,
|
||||
ENCLOSURE_BASE_1.code : ENCLOSURE_BASE_1,
|
||||
ENCLOSURE_BASE_2.code : ENCLOSURE_BASE_2,
|
||||
ENCLOSURE_BASE_3.code : ENCLOSURE_BASE_3,
|
||||
GPU_0_DIODE.code : GPU_0_DIODE,
|
||||
GPU_0_HEATSINK.code : GPU_0_HEATSINK,
|
||||
GPU_0_PROXIMITY.code : GPU_0_PROXIMITY,
|
||||
HDD_PROXIMITY.code : HDD_PROXIMITY,
|
||||
HEATSINK_0.code : HEATSINK_0,
|
||||
HEATSINK_1.code : HEATSINK_1,
|
||||
HEATSINK_2.code : HEATSINK_2,
|
||||
MEM_SLOT_0.code : MEM_SLOT_0,
|
||||
public static let all = [AMBIENT_AIR_0.code: AMBIENT_AIR_0,
|
||||
AMBIENT_AIR_1.code: AMBIENT_AIR_1,
|
||||
CPU_0_DIE.code: CPU_0_DIE,
|
||||
CPU_0_DIODE.code: CPU_0_DIODE,
|
||||
CPU_0_HEATSINK.code: CPU_0_HEATSINK,
|
||||
CPU_0_PROXIMITY.code: CPU_0_PROXIMITY,
|
||||
ENCLOSURE_BASE_0.code: ENCLOSURE_BASE_0,
|
||||
ENCLOSURE_BASE_1.code: ENCLOSURE_BASE_1,
|
||||
ENCLOSURE_BASE_2.code: ENCLOSURE_BASE_2,
|
||||
ENCLOSURE_BASE_3.code: ENCLOSURE_BASE_3,
|
||||
GPU_0_DIODE.code: GPU_0_DIODE,
|
||||
GPU_0_HEATSINK.code: GPU_0_HEATSINK,
|
||||
GPU_0_PROXIMITY.code: GPU_0_PROXIMITY,
|
||||
HDD_PROXIMITY.code: HDD_PROXIMITY,
|
||||
HEATSINK_0.code: HEATSINK_0,
|
||||
HEATSINK_1.code: HEATSINK_1,
|
||||
HEATSINK_2.code: HEATSINK_2,
|
||||
MEM_SLOT_0.code: MEM_SLOT_0,
|
||||
MEM_SLOTS_PROXIMITY.code: MEM_SLOTS_PROXIMITY,
|
||||
PALM_REST.code : PALM_REST,
|
||||
LCD_PROXIMITY.code : LCD_PROXIMITY,
|
||||
MISC_PROXIMITY.code : MISC_PROXIMITY,
|
||||
NORTHBRIDGE.code : NORTHBRIDGE,
|
||||
NORTHBRIDGE_DIODE.code : NORTHBRIDGE_DIODE,
|
||||
NORTHBRIDGE_PROXIMITY.code : NORTHBRIDGE_PROXIMITY,
|
||||
ODD_PROXIMITY.code : ODD_PROXIMITY,
|
||||
PWR_SUPPLY_PROXIMITY.code : PWR_SUPPLY_PROXIMITY,
|
||||
THUNDERBOLT_0.code : THUNDERBOLT_0,
|
||||
THUNDERBOLT_1.code : THUNDERBOLT_1]
|
||||
PALM_REST.code: PALM_REST,
|
||||
LCD_PROXIMITY.code: LCD_PROXIMITY,
|
||||
MISC_PROXIMITY.code: MISC_PROXIMITY,
|
||||
NORTHBRIDGE.code: NORTHBRIDGE,
|
||||
NORTHBRIDGE_DIODE.code: NORTHBRIDGE_DIODE,
|
||||
NORTHBRIDGE_PROXIMITY.code: NORTHBRIDGE_PROXIMITY,
|
||||
ODD_PROXIMITY.code: ODD_PROXIMITY,
|
||||
PWR_SUPPLY_PROXIMITY.code: PWR_SUPPLY_PROXIMITY,
|
||||
THUNDERBOLT_0.code: THUNDERBOLT_0,
|
||||
THUNDERBOLT_1.code: THUNDERBOLT_1]
|
||||
}
|
||||
|
||||
public struct TemperatureSensor {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
class HelperDelegate: NSObject, NSXPCListenerDelegate {
|
||||
final class HelperDelegate: NSObject, NSXPCListenerDelegate {
|
||||
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
|
||||
newConnection.exportedInterface = NSXPCInterface(with: HelperToolProtocol.self)
|
||||
newConnection.exportedObject = HelperTool()
|
||||
|
@ -22,4 +22,3 @@ let listener = NSXPCListener(machServiceName: "com.davidwernhart.Helper.mach")
|
|||
listener.delegate = delegate
|
||||
listener.resume()
|
||||
RunLoop.current.run()
|
||||
|
||||
|
|
Loading…
Reference in New Issue