Skip to content

Commit

Permalink
Apple Silicon Support
Browse files Browse the repository at this point in the history
  • Loading branch information
David Wernhart committed Feb 14, 2021
0 parents commit 77119a1
Show file tree
Hide file tree
Showing 30 changed files with 3,178 additions and 0 deletions.
567 changes: 567 additions & 0 deletions AlDente.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "LaunchAtLogin",
"repositoryURL": "https://github.com/sindresorhus/LaunchAtLogin",
"state": {
"branch": null,
"revision": "0f39982b9d6993eef253b81219d3c39ba1e680f3",
"version": "4.0.0"
}
}
]
},
"version": 1
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "0B65810B-47FA-44B5-B39C-4D764B29033A"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "15EAC10E-2093-4C1F-817D-D17853B691FE"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "AlDente/ContentView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "37"
endingLineNumber = "37"
landmarkName = "Settings"
landmarkType = "14">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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>SchemeUserState</key>
<dict>
<key>AlDente Pro.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>AlDente copy.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>AlDente.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Hall.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>Helper.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>com.davidwernhart.Helper.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
133 changes: 133 additions & 0 deletions AlDente/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// AppDelegate.swift
// AlDente
//
// Created by David Wernhart on 09.02.20.
// Copyright © 2020 David Wernhart. All rights reserved.
//

import AppKit
import SwiftUI
import LaunchAtLogin
import Foundation
import IOKit.ps
import IOKit.pwr_mgt

extension ProcessInfo {
/// Returns a `String` representing the machine hardware name or nil if there was an error invoking `uname(_:)` or decoding the response.
///
/// Return value is the equivalent to running `$ uname -m` in shell.
var machineHardwareName: String? {
var sysinfo = utsname()
let result = uname(&sysinfo)
guard result == EXIT_SUCCESS else { return nil }
let data = Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN))
guard let identifier = String(bytes: data, encoding: .ascii) else { return nil }
return identifier.trimmingCharacters(in: .controlCharacters)
}
}

@NSApplicationMain
final class AppDelegate: NSObject, NSApplicationDelegate {

//var window: NSWindow!
var statusBarItem: NSStatusItem!
var popover: NSPopover!

func applicationWillTerminate(_ aNotification: Notification) {
Helper.instance.enableSleep()
Helper.instance.enableCharging()
}

func applicationDidFinishLaunching(_ aNotification: Notification) {

let contentView = ContentView()

// Create the popover
let popover = NSPopover()
popover.contentSize = NSSize(width: 400, height: 600)
popover.behavior = .transient
popover.contentViewController = NSHostingController(rootView: contentView)
self.popover = popover

let statusBar = NSStatusBar.system
statusBarItem = statusBar.statusItem(withLength: NSStatusItem.squareLength)
statusBarItem.button?.image = NSImage(named: "menubaricon")!
statusBarItem.button?.action = #selector(togglePopover(_:))

Helper.instance.setPlatformKey()

Helper.instance.checkHelperVersion{(foundHelper) in
if(foundHelper){
print("helper found!")
}
else{
Helper.instance.installHelper()
}
}

LaunchAtLogin.isEnabled = true
SMCPresenter.shared.loadValue()

Helper.instance.checkCharging()

var actionMsg:String?

Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { timer in
if(Helper.instance.isInitialized){
Helper.instance.getChargingInfo { (Name, Capacity, IsCharging, MaxCapacity) in


if(!PersistanceManager.instance.oldKey){
if(Capacity < SMCPresenter.shared.value){
actionMsg = "NEED TO CHARGE"
if(Helper.instance.chargeInhibited){
Helper.instance.enableCharging()
}
Helper.instance.disableSleep()

}
else{
actionMsg = "IS PERFECT"
if(!Helper.instance.chargeInhibited){
Helper.instance.disableCharging()
}
Helper.instance.enableSleep()

}
print("TARGET: ",SMCPresenter.shared.value,
" CURRENT: ",String(Capacity),
" ISCHARGING: ",String(IsCharging),
" CHARGE INHIBITED: ",String(Helper.instance.chargeInhibited),
" ACTION: ",actionMsg!)
}
else{
print("BCLM MODE ENABLED")
}



}
DispatchQueue.main.async {
Helper.instance.setStatusString()
}

}
}

}

@objc func togglePopover(_ sender: AnyObject?) {
popover.contentViewController?.view.window?.becomeKey()

Helper.instance.setStatusString()
if let button = self.statusBarItem.button {
if popover.isShown {
popover.performClose(sender)
} else {
popover.show(relativeTo: button.bounds, of: button, preferredEdge: .minY)
}
}
}

}
59 changes: 59 additions & 0 deletions AlDente/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"filename" : "spaghetti.png",
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions AlDente/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
54 changes: 54 additions & 0 deletions AlDente/Assets.xcassets/menubaricon.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"images" : [
{
"filename" : "aldentelighticon1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "aldentedarkicon1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "aldentelighticon2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "aldentedarkicon2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 77119a1

Please sign in to comment.