Skip to content

Commit

Permalink
Smooth charts using Surge
Browse files Browse the repository at this point in the history
  • Loading branch information
alin23 committed Mar 18, 2019
1 parent beb9352 commit 1304603
Show file tree
Hide file tree
Showing 19 changed files with 598 additions and 268 deletions.
3 changes: 2 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ github "soffes/HotKey"
github "danielgindi/Charts"
github "sparkle-project/Sparkle"
github "Clipy/KeyHolder"
github "Clipy/Magnet"
github "Clipy/Magnet"
github "mattt/Surge" ~> 2.0.0
3 changes: 2 additions & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ github "Clipy/Magnet" "v2.3.1"
github "SwiftyBeaver/SwiftyBeaver" "1.6.2"
github "SwiftyJSON/SwiftyJSON" "4.2.0"
github "alin23/Solar" "2.2.0"
github "alin23/WAYWindow" "1.1.0"
github "alin23/WAYWindow" "1.0.0"
github "danielgindi/Charts" "v3.2.2"
github "malcommac/SwiftDate" "5.1.0"
github "mattt/Surge" "2.2.0"
github "nerd0geek1/NSPageControl" "v0.1.2"
github "soffes/HotKey" "v0.1.1"
github "sparkle-project/Sparkle" "1.21.3"
6 changes: 6 additions & 0 deletions Lunar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
C794E1741FEFE31A00549462 /* ScrollableTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = C794E1731FEFE31A00549462 /* ScrollableTextField.swift */; };
C794E1771FF01EF500549462 /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = C794E1751FF01EF500549462 /* Model.xcdatamodeld */; };
C7A2574220EA249B003B3A84 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = C7A2574120EA249B003B3A84 /* dsa_pub.pem */; };
C7A2BDDA223FC8D100C910E3 /* Surge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C7A2BDD9223FC8D100C910E3 /* Surge.framework */; };
C7A2BDDB223FC8D100C910E3 /* Surge.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C7A2BDD9223FC8D100C910E3 /* Surge.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
C7AEC7F91FD0B4350039B562 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7AEC7F81FD0B4350039B562 /* AppDelegate.swift */; };
C7AEC7FB1FD0B4350039B562 /* PageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C7AEC7FA1FD0B4350039B562 /* PageController.swift */; };
C7AEC7FD1FD0B4350039B562 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C7AEC7FC1FD0B4350039B562 /* Assets.xcassets */; };
Expand Down Expand Up @@ -88,6 +90,7 @@
dstSubfolderSpec = 10;
files = (
C75083572222865F0020270E /* HotKey.framework in Embed Frameworks */,
C7A2BDDB223FC8D100C910E3 /* Surge.framework in Embed Frameworks */,
C75083472222865F0020270E /* Solar.framework in Embed Frameworks */,
C75083412222865F0020270E /* WAYWindow.framework in Embed Frameworks */,
C75083552222865F0020270E /* NSPageControl.framework in Embed Frameworks */,
Expand Down Expand Up @@ -168,6 +171,7 @@
C794E1731FEFE31A00549462 /* ScrollableTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollableTextField.swift; sourceTree = "<group>"; };
C794E1761FF01EF500549462 /* Model.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = "<group>"; };
C7A2574120EA249B003B3A84 /* dsa_pub.pem */ = {isa = PBXFileReference; lastKnownFileType = text; name = dsa_pub.pem; path = Lunar/Resources/dsa_pub.pem; sourceTree = "<group>"; };
C7A2BDD9223FC8D100C910E3 /* Surge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Surge.framework; path = Carthage/Build/Mac/Surge.framework; sourceTree = "<group>"; };
C7AEC7F51FD0B4350039B562 /* Lunar.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Lunar.app; sourceTree = BUILT_PRODUCTS_DIR; };
C7AEC7F81FD0B4350039B562 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
C7AEC7FA1FD0B4350039B562 /* PageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,6 +216,7 @@
C75083482222865F0020270E /* Sparkle.framework in Frameworks */,
C75083442222865F0020270E /* Alamofire.framework in Frameworks */,
C75083542222865F0020270E /* NSPageControl.framework in Frameworks */,
C7A2BDDA223FC8D100C910E3 /* Surge.framework in Frameworks */,
C75083462222865F0020270E /* Solar.framework in Frameworks */,
C75083402222865F0020270E /* WAYWindow.framework in Frameworks */,
);
Expand Down Expand Up @@ -294,6 +299,7 @@
C7AEC7EC1FD0B4350039B562 = {
isa = PBXGroup;
children = (
C7A2BDD9223FC8D100C910E3 /* Surge.framework */,
C75083362222865D0020270E /* Alamofire.framework */,
C75083352222865D0020270E /* Charts.framework */,
C750833F2222865F0020270E /* HotKey.framework */,
Expand Down
9 changes: 8 additions & 1 deletion Lunar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ import Magnet
import ServiceManagement
import WAYWindow

extension Collection where Index: Comparable {
subscript(back i: Int) -> Iterator.Element {
let backBy = i + 1
return self[self.index(self.endIndex, offsetBy: -backBy)]
}
}

let TEST_MODE = false

var lunarDisplayNames = [
Expand Down Expand Up @@ -366,7 +373,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate, N
brightnessAdapter.listenForRunningApps()

addObservers()
if thisIsFirstRun {
if thisIsFirstRun || TEST_MODE {
showWindow()
}

Expand Down
56 changes: 52 additions & 4 deletions Lunar/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,50 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="N8o-BV-pMP">
<rect key="frame" x="27" y="157" width="200" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="Curve factor" id="AWI-Wn-fEe">
<font key="font" size="18" name="Menlo-Bold"/>
<color key="textColor" red="0.19215686269999999" green="0.1647058824" blue="0.29803921570000003" alpha="0.5" colorSpace="calibratedRGB"/>
<color key="backgroundColor" red="0.19215686269999999" green="0.1647058824" blue="0.29803921570000003" alpha="0.0" colorSpace="calibratedRGB"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="m80-Et-ppU" customClass="ScrollableTextField" customModule="Lunar" customModuleProvider="target">
<rect key="frame" x="257" y="169" width="100" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" allowsUndo="NO" sendsActionOnEndEditing="YES" alignment="center" title="100" usesSingleLineMode="YES" id="VPq-3u-yvo">
<font key="font" metaFont="systemHeavy" size="32"/>
<color key="textColor" white="1" alpha="0.70059419010000001" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="textFieldColor">
<color key="value" white="1" alpha="0.69921875" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="textFieldColorHover">
<color key="value" white="1" alpha="0.89981294020000002" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="textFieldColorLight">
<color key="value" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="lowerLimit">
<integer key="value" value="0"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="upperLimit">
<integer key="value" value="600"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ugZ-qJ-vyb" customClass="ScrollableTextFieldCaption" customModule="Lunar" customModuleProvider="target">
<rect key="frame" x="257" y="157" width="100" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="EXP" id="SDL-Nm-V8a">
<font key="font" size="10" name="Menlo-Bold"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CUN-Fw-jrZ">
<rect key="frame" x="-2" y="12" width="182" height="38"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -730,7 +774,7 @@
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" textCompletion="NO" translatesAutoresizingMaskIntoConstraints="NO" id="osm-bT-7sA">
<rect key="frame" x="27" y="157" width="200" height="30"/>
<rect key="frame" x="27" y="68" width="200" height="30"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" alignment="left" title="Smooth transition" id="zxx-4L-t4t">
<font key="font" size="18" name="Menlo-Bold"/>
Expand All @@ -739,12 +783,13 @@
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" alphaValue="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="4tb-kQ-mbr">
<rect key="frame" x="291" y="156" width="32" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="left" state="on" imageScaling="proportionallyUpOrDown" inset="2" id="ueH-KN-tis">
<rect key="frame" x="291" y="67" width="32" height="32"/>
<autoresizingMask key="autoresizingMask"/>
<buttonCell key="cell" type="check" bezelStyle="regularSquare" imagePosition="only" alignment="center" state="on" imageScaling="proportionallyUpOrDown" inset="2" id="ueH-KN-tis">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<color key="contentTintColor" red="0.19215686269999999" green="0.1647058824" blue="0.29803921570000003" alpha="0.5" colorSpace="calibratedRGB"/>
<connections>
<binding destination="hWD-oU-Uq8" name="value" keyPath="values.smoothTransition" id="mRD-Fw-dz0"/>
</connections>
Expand All @@ -768,6 +813,9 @@
<outlet property="contrastOffsetCaption" destination="rdW-wb-yK8" id="E8G-oY-XaB"/>
<outlet property="contrastOffsetField" destination="Ukf-9t-bWu" id="OOZ-S1-gLl"/>
<outlet property="contrastOffsetLabel" destination="TIh-L1-JfW" id="6Ed-N8-Fvd"/>
<outlet property="curveFactorCaption" destination="ugZ-qJ-vyb" id="mFQ-ZP-uYm"/>
<outlet property="curveFactorField" destination="m80-Et-ppU" id="faJ-iv-kPg"/>
<outlet property="curveFactorLabel" destination="N8o-BV-pMP" id="FLi-rG-7XW"/>
<outlet property="daylightExtensionCaption" destination="7xo-Ez-g9m" id="n58-8w-jt4"/>
<outlet property="daylightExtensionField" destination="H5y-th-bQ1" id="Wq8-z4-DGd"/>
<outlet property="daylightExtensionLabel" destination="gmb-rW-1Qy" id="iwP-Ic-Qjn"/>
Expand Down
48 changes: 43 additions & 5 deletions Lunar/BrightnessAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CoreLocation
import Crashlytics
import Foundation
import Solar
import Surge
import SwiftDate
import SwiftyJSON

Expand Down Expand Up @@ -293,14 +294,13 @@ class BrightnessAdapter {
for display: Display,
hour: Int? = nil,
minute: Int = 0,
factor: Double? = nil,
minBrightness: UInt8? = nil,
maxBrightness: UInt8? = nil,
minContrast: UInt8? = nil,
maxContrast: UInt8? = nil,
daylightExtension: Int? = nil,
noonDuration: Int? = nil,
brightnessOffset: Int? = nil,
contrastOffset: Int? = nil,
appBrightnessOffset: Int = 0,
appContrastOffset: Int = 0
) -> (NSNumber, NSNumber) {
Expand All @@ -312,27 +312,65 @@ class BrightnessAdapter {
moment: moment,
hour: hour,
minute: minute,
factor: factor,
minBrightness: minBrightness,
maxBrightness: maxBrightness,
minContrast: minContrast,
maxContrast: maxContrast,
daylightExtension: daylightExtension,
noonDuration: noonDuration,
appBrightnessOffset: appBrightnessOffset,
appContrastOffset: appContrastOffset
)
}

func getBrightnessContrastBatch(
for display: Display,
count: Int,
minutesBetween: Int,
factor: Double? = nil,
minBrightness: UInt8? = nil,
maxBrightness: UInt8? = nil,
minContrast: UInt8? = nil,
maxContrast: UInt8? = nil,
daylightExtension: Int? = nil,
noonDuration: Int? = nil,
appBrightnessOffset: Int = 0,
appContrastOffset: Int = 0
) -> [(NSNumber, NSNumber)] {
if moment == nil {
log.warning("Day moments aren't fetched yet")
return [(NSNumber, NSNumber)](repeating: (0, 0), count: count * minutesBetween)
}
return display.getBrightnessContrastBatch(
moment: moment,
minutesBetween: minutesBetween,
factor: factor,
minBrightness: minBrightness,
maxBrightness: maxBrightness,
minContrast: minContrast,
maxContrast: maxContrast,
daylightExtension: daylightExtension,
noonDuration: noonDuration,
brightnessOffset: brightnessOffset,
contrastOffset: contrastOffset,
appBrightnessOffset: appBrightnessOffset,
appContrastOffset: appContrastOffset
)
}

func computeManualValueFromPercent(percent: Int8, key: String, minVal: Int? = nil, maxVal: Int? = nil) -> NSNumber {
let percent = Double(min(max(percent, 0), 100)) / 100.0
let percent = Double(cap(percent, minVal: 0, maxVal: 100)) / 100.0
let minVal = minVal ?? datastore.defaults.integer(forKey: "\(key)LimitMin")
let maxVal = maxVal ?? datastore.defaults.integer(forKey: "\(key)LimitMax")
let value = Int(round(percent * Double(maxVal - minVal))) + minVal
return NSNumber(value: cap(value, minVal: minVal, maxVal: maxVal))
}

func computeSIMDManualValueFromPercent(from percent: [Double], key: String, minVal: Int? = nil, maxVal: Int? = nil) -> [Double] {
let minVal = minVal ?? datastore.defaults.integer(forKey: "\(key)LimitMin")
let maxVal = maxVal ?? datastore.defaults.integer(forKey: "\(key)LimitMax")
return percent * Double(maxVal - minVal) + Double(minVal)
}

func setBrightnessPercent(value: Int8, for displays: [Display]? = nil) {
let brightness = computeManualValueFromPercent(percent: value, key: "brightness")
if let displays = displays {
Expand Down
Loading

0 comments on commit 1304603

Please sign in to comment.