Skip to content

Commit

Permalink
Sync mode improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
alin23 committed Apr 9, 2024
1 parent 31cfaac commit 004aa94
Show file tree
Hide file tree
Showing 17 changed files with 293 additions and 103 deletions.
2 changes: 1 addition & 1 deletion .gitsecret/paths/mapping.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Lunar/Resources/dsa_priv.pem:4724e8ee0055cf3ddc55ca528691955d68879ec8abaafd3200cdfa20298ea1d9
Lunar/Resources/eddsa_priv:d079018c2b1c003c9e239ea8f8cc999b7d98adfd0616911ba0263dd20629e646
Lunar/Modes/SensorMode.swift:148eb77e514b7046174115da097a1d508b0ad028cd6bd6d87bcc84aeb11ff22e
Lunar/Modes/SyncMode.swift:55656cdc5ae9e6c7770ab9d31693b9fa7bbf7ec9cd1522dadf630859604423ae
Lunar/Modes/SyncMode.swift:6bea781b99618a7b9e37e13d134bd94c664d7e192e99ad102802be78b71b4d98
Lunar/Modes/LocationMode.swift:33f47b5788bdf89d343a5b64b64f132972b591195f716eac55091dea289b16ee
Lunar/Data/Pro.swift:67d707cc84f60e6f8aa76f6156a3055c4da2ae746ddbd0dedf3945aa93e21b05
Lunar/Modes/ClockMode.swift:ebda9ca5622a46e1d7435504dc225df496fa824900a1521b71518cf8799922f6
Expand Down
8 changes: 4 additions & 4 deletions Lunar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6.7.5b1;
CURRENT_PROJECT_VERSION = 6.7.5;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
Expand Down Expand Up @@ -1372,7 +1372,7 @@
);
LLVM_LTO = YES_THIN;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 6.7.5b1;
MARKETING_VERSION = 6.7.5;
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CODE_SIGN_FLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = fyi.lunar.Lunar;
Expand Down Expand Up @@ -1405,7 +1405,7 @@
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 6.7.5b1;
CURRENT_PROJECT_VERSION = 6.7.5;
DEVELOPMENT_ASSET_PATHS = "";
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = RDDXV84A73;
Expand Down Expand Up @@ -1436,7 +1436,7 @@
);
LLVM_LTO = YES;
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 6.7.5b1;
MARKETING_VERSION = 6.7.5;
MTL_ENABLE_DEBUG_INFO = NO;
OTHER_CODE_SIGN_FLAGS = "--timestamp";
PRODUCT_BUNDLE_IDENTIFIER = fyi.lunar.Lunar;
Expand Down
6 changes: 3 additions & 3 deletions Lunar.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"repositoryURL": "https://github.com/alin23/FuzzyMatcher",
"state": {
"branch": "main",
"revision": "d9d9a666bcb77b1c78fe119714faddcd788d11d1",
"revision": "6c7628a46a566d64d6b7d79068c95bf80c8a6bd6",
"version": null
}
},
Expand Down Expand Up @@ -123,8 +123,8 @@
"repositoryURL": "https://github.com/getsentry/sentry-cocoa",
"state": {
"branch": null,
"revision": "bf7bdd75e25556d0f97ad54fb804b4287863e106",
"version": "8.22.4"
"revision": "937dce13c2600cc42112c480d04f84899e08e9cc",
"version": "8.23.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,118 @@
uuid = "A71689F0-05ED-400C-9A39-47EC0A36555F"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "F3C88688-5651-42FD-990B-ECD95250D747"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Lunar/Modes/SyncMode.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "898"
endingLineNumber = "898"
landmarkName = "getUserMinNits(mapping:)"
landmarkType = "7">
<Locations>
<Location
uuid = "F3C88688-5651-42FD-990B-ECD95250D747 - f6c5d1ba221c505f"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Lunar.Display.getUserMinNits(mapping: Swift.Optional&lt;Swift.Array&lt;Lunar.AutoLearnMapping&gt;&gt;) -&gt; Swift.Optional&lt;Swift.Double&gt;"
moduleName = "Lunar"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/alin/Projects/LunarPro/Lunar/Modes/SyncMode.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "898"
endingLineNumber = "898"
offsetFromSymbolStart = "204">
</Location>
<Location
uuid = "F3C88688-5651-42FD-990B-ECD95250D747 - f6c5d1ba221c505f"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "Lunar.Display.getUserMinNits(mapping: Swift.Optional&lt;Swift.Array&lt;Lunar.AutoLearnMapping&gt;&gt;) -&gt; Swift.Optional&lt;Swift.Double&gt;"
moduleName = "Lunar"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/alin/Projects/LunarPro/Lunar/Modes/SyncMode.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "898"
endingLineNumber = "898"
offsetFromSymbolStart = "196">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "01254373-620C-428A-B763-B776CB274522"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Lunar/Modes/SyncMode.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "148"
endingLineNumber = "148"
landmarkName = "observeBrightness(_:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "763B523E-3601-4BD9-BC45-6C8D581F8782"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Lunar/Control/AppleNativeControl.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "220"
endingLineNumber = "220"
landmarkName = "updateNits()"
landmarkType = "7">
<Locations>
<Location
uuid = "763B523E-3601-4BD9-BC45-6C8D581F8782 - 72d04a774dff3a45"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 () -&gt; () in Lunar.AppleNativeControl.updateNits() -&gt; ()"
moduleName = "Lunar"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/alin/Projects/LunarPro/Lunar/Control/AppleNativeControl.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "220"
endingLineNumber = "220"
offsetFromSymbolStart = "280">
</Location>
<Location
uuid = "763B523E-3601-4BD9-BC45-6C8D581F8782 - 72d04a774dff3a45"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 () -&gt; () in Lunar.AppleNativeControl.updateNits() -&gt; ()"
moduleName = "Lunar"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/alin/Projects/LunarPro/Lunar/Control/AppleNativeControl.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "220"
endingLineNumber = "220"
offsetFromSymbolStart = "2872">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
12 changes: 10 additions & 2 deletions Lunar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDeleg
let APP_DIR = ((try? p("/Applications")?.realpath()) ?? p("/Applications"))?.components ?? ["Applications"]
let SVAPP_DIR = ((try? p("/System/Volumes/Data/Applications")?.realpath()) ?? p("/System/Volumes/Data/Applications"))?.components ?? ["System", "Volumes", "Data", "Applications"]

@Atomic var showBrightnessMenuBarChanged = true

var sentryCrashExceptionApplicationType: AnyClass?

@Atomic @objc dynamic var cleaningMode = false {
didSet {
log.debug("Cleaning Mode: \(cleaningMode)")
Expand Down Expand Up @@ -1084,7 +1088,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDeleg
mainAsync {
self.statusItemButtonController?.frame = button.frame
}
} else if let button = statusItem.button {
} else if showBrightnessMenuBarChanged, let button = statusItem.button {
showBrightnessMenuBarChanged = false
button.attributedTitle = "".attributedString
button.imagePosition = .imageOnly
mainAsync {
Expand Down Expand Up @@ -1841,6 +1846,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDeleg
.merge(with: showOnlyExternalBrightnessMenuBarPublisher)
.debounce(for: .milliseconds(100), scheduler: RunLoop.main)
.sink { [self] change in
showBrightnessMenuBarChanged = true
if change.newValue {
statusItem.button?.imagePosition = .imageLeading
} else {
Expand Down Expand Up @@ -2290,7 +2296,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDeleg
}

func applicationDidFinishLaunching(_: Notification) {
print(SentryCrashExceptionApplication.self)
if isServer {
sentryCrashExceptionApplicationType = SentryCrashExceptionApplication.self
}

initDDCLogging()
guard !SWIFTUI_PREVIEW else {
Expand Down
27 changes: 18 additions & 9 deletions Lunar/Control/AppleNativeControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ final class AppleNativeControl: Control {

var smoothTransitionTask: DispatchWorkItem?

var nitsUpdateRepeater: Repeater? = nil

var isSoftware: Bool { false }
var isDDC: Bool { true }

Expand Down Expand Up @@ -290,19 +292,20 @@ final class AppleNativeControl: Control {
DisplayServicesBrightnessChanged(id, br)
}

for _ in stride(from: 0, through: 0.5, by: 0.01) {
Thread.sleep(forTimeInterval: 0.01)
guard !display.shouldStopBrightnessTransition else {
log.debug("Stopping smooth transition on brightness=\(brightness) using \(self) for \(display)")
display.lastWrittenBrightness = getBrightness() ?? display.lastWrittenBrightness
return
}
}
// for _ in stride(from: 0, through: 0.5, by: 0.01) {
// Thread.sleep(forTimeInterval: 0.01)
// guard !display.shouldStopBrightnessTransition else {
// log.debug("Stopping smooth transition on brightness=\(brightness) using \(self) for \(display)")
// display.lastWrittenBrightness = getBrightness() ?? display.lastWrittenBrightness
// return
// }
// }
DisplayServicesSetBrightness(id, br.f)
if br == 1.0 {
DisplayServicesSetLinearBrightness(id, br.f)
}
updateNits()
display.lastWrittenBrightness = getBrightness() ?? display.lastWrittenBrightness
updateNitsWithRetry()

if #available(macOS 14.0, *) {
// not needed
Expand Down Expand Up @@ -360,6 +363,12 @@ final class AppleNativeControl: Control {
onChange?(brightness)
return writeBrightness(brightness)
}
func updateNitsWithRetry() {
nitsUpdateRepeater = Repeater(every: 0.05, times: 10) { [weak self] in
guard let self else { return }
updateNits()
}
}

func setContrast(
_ contrast: Contrast,
Expand Down
19 changes: 15 additions & 4 deletions Lunar/Data/Display.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3544,10 +3544,14 @@ let AUDIO_IDENTIFIER_UUID_PATTERN = "([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{4})-[0
}

let id = CGDirectDisplayID(UInt(bitPattern: observer))
guard let display = DC.activeDisplays[id], !display.inSmoothTransition, !display.isBuiltin || !DC.lidClosed else {
let reason = if DC.activeDisplays[id] == nil {
"display not found"
} else if DC.activeDisplays[id]?.inSmoothTransition ?? false {
guard let display = DC.activeDisplays[id] else {
let reason = "display not found"
DS_LOGGER.debug("Ignoring brightness change notification. Reason: \(reason, privacy: .public)")
return
}

guard !display.inSmoothTransition, !display.isBuiltin || !DC.lidClosed else {
let reason = if DC.activeDisplays[id]?.inSmoothTransition ?? false {
"in smooth transition"
} else if DC.activeDisplays[id]?.isBuiltin ?? false {
"lid closed"
Expand Down Expand Up @@ -3934,6 +3938,13 @@ let AUDIO_IDENTIFIER_UUID_PATTERN = "([0-9a-f]{2})([0-9a-f]{2})-([0-9a-f]{4})-[0
}
}

lazy var userMinNits: Double? = getUserMinNits() {
didSet {
debug("\(self.name) Min Nits: \((self.userMinNits ?? self.minNits).str(decimals: 2))")
recomputeNitsMapping()
}
}

@Published @objc var maxNits: Double = 500 {
didSet {
guard initialised else { return }
Expand Down
Loading

0 comments on commit 004aa94

Please sign in to comment.