-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e489f78
Showing
15 changed files
with
691 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Swift | ||
on: [push] | ||
jobs: | ||
build: | ||
name: Swift ${{ matrix.swift }} on ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: [macos-latest] | ||
swift: ["5.9"] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: swift-actions/[email protected] | ||
with: | ||
swift-version: ${{ matrix.swift }} | ||
- uses: actions/checkout@v4 | ||
- name: Build | ||
run: swift build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--indent 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
included: | ||
- Package.swift | ||
- Sources/Swift | ||
strict: true | ||
opt_in_rules: | ||
- indentation_width | ||
line_length: 100 | ||
indentation_width: | ||
indentation_width: 2 | ||
identifier_name: | ||
excluded: # excluded via string array | ||
- id | ||
- to | ||
trailing_comma: | ||
mandatory_comma: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# DOCS | ||
|
||
> Night Shift automatically shifts the colours of your display to the warmer end of the colour spectrum after dark. This may help you get a better night's sleep. | ||
Under "System Settings > Display > Night Shift" you find the UI controls. | ||
|
||
It supports three schedules | ||
|
||
1. Off | ||
2. Sunset to Sunrise | ||
3. Custom | ||
|
||
When "Off" (`mode: 0`), you can turn it on for a single day toggling "Turn on until "tomorrow" | ||
|
||
When "Sunset to Sunrise" (`mode: 1`), the schedule is automatic, and you can toggle it active until the next "sunrise" | ||
|
||
When "Custom" (`mode: 2`), you can set a daily schedule, and additionally toggle it active until "tomorrow" | ||
|
||
In all three modes, you can select a colour temperature, on a sliding scale between "Less Warm" and "More Warm" | ||
|
||
## Technical | ||
|
||
The status object | ||
|
||
``` | ||
var status: Status = Status() | ||
client.getBlueLightStatus(&status) | ||
``` | ||
|
||
``` | ||
// seems to control the temporary setting until tomorrow/sunrise | ||
enabled: true|false | ||
available: true|false | ||
// I guesss this has to do with location based information | ||
sunSchedulePermitted: true|false | ||
disableFlags: 0 | ||
mode: 0|1|2 | ||
schedule(fromTime(hour,minute),toTime(hour,minute)) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name = nightshift | ||
prefix ?= $(HOME)/.local | ||
bindir = $(prefix)/bin | ||
|
||
build: | ||
swift build | ||
|
||
run: build | ||
swift run $(name) | ||
|
||
release: | ||
swift build --configuration release --disable-sandbox --arch arm64 | ||
|
||
install: release | ||
install -d "$(bindir)" | ||
install ".build/release/$(name)" "$(bindir)" | ||
|
||
uninstall: | ||
rm -rf "$(bindir)/$(name)" | ||
|
||
# requires `brew install swiftlint` | ||
lint: | ||
swiftlint | ||
|
||
clean: | ||
rm -rf .build | ||
|
||
.PHONY: build install uninstall clean release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-argument-parser", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-argument-parser", | ||
"state" : { | ||
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", | ||
"version" : "1.2.3" | ||
} | ||
} | ||
], | ||
"version" : 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "nightshift", | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-argument-parser", exact: "1.2.3"), | ||
], | ||
targets: [ | ||
.target( | ||
name: "DisplayClient", | ||
path: "Sources/ObjC/DisplayClient", | ||
linkerSettings: [ | ||
.unsafeFlags(["-F/System/Library/PrivateFrameworks"]), | ||
.linkedFramework("CoreBrightness"), | ||
] | ||
), | ||
.executableTarget( | ||
name: "nightshift", | ||
dependencies: [ | ||
.byName(name: "DisplayClient"), | ||
.product(name: "ArgumentParser", package: "swift-argument-parser"), | ||
], | ||
path: "Sources/Swift" | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# README | ||
|
||
A macOS tool to read and control the [Night Shift](https://support.apple.com/en-us/102191) feature. | ||
|
||
## Usage | ||
|
||
Print out current settings | ||
|
||
``` | ||
nightshift | ||
Schedule: sunrise | ||
Enabled: true | ||
Temperature: 0.49 | ||
``` | ||
|
||
Control modes | ||
|
||
``` | ||
nightshift schedule | ||
nightshift schedule off | ||
nightshift schedule custom --from 11:00 --to 23:00 -t 0.3 | ||
nightshift schedule sunrise --temperature 0.3 | ||
``` | ||
|
||
Control details | ||
|
||
``` | ||
nightshift enable | ||
nightshift disable | ||
nightshift temperature | ||
nightshift temperature 0.33 | ||
``` | ||
|
||
## Installation | ||
|
||
**Via Github** | ||
|
||
``` | ||
git clone [email protected]:oschrenk/nightshift.swift.git | ||
cd nightshift.swift | ||
# installs to $(HOME)/.local/bin/nightshift | ||
make install | ||
``` | ||
|
||
## Development | ||
|
||
- **Build** `make build` | ||
- **Run** `make run` | ||
- **Lint** `make lint` | ||
|
||
## Release | ||
|
||
``` | ||
make release | ||
# produces artifact in in ./.build/release/nightshift | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
// Partial header for CBBlueLightClient in private CoreBrightness API | ||
@interface CBBlueLightClient : NSObject | ||
|
||
typedef struct { | ||
int hour; | ||
int minute; | ||
} Time; | ||
|
||
typedef struct { | ||
Time fromTime; | ||
Time toTime; | ||
} ScheduleObjC; | ||
|
||
typedef struct { | ||
BOOL active; | ||
BOOL enabled; | ||
BOOL sunSchedulePermitted; | ||
int mode; | ||
ScheduleObjC schedule; | ||
unsigned long long disableFlags; | ||
BOOL available; | ||
} Status; | ||
|
||
- (BOOL)setStrength:(float)strength commit:(BOOL)commit; | ||
- (BOOL)setEnabled:(BOOL)enabled; | ||
- (BOOL)setMode:(int)mode; | ||
- (BOOL)setSchedule:(ScheduleObjC *)schedule; | ||
- (BOOL)getStrength:(float *)strength; | ||
- (BOOL)getBlueLightStatus:(Status *)status; | ||
- (void)setStatusNotificationBlock:(void (^)(void))block; | ||
+ (BOOL)supportsBlueLightReduction; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Foundation | ||
|
||
enum AppError: Error { | ||
case decodingError(String) | ||
} | ||
|
||
extension AppError: LocalizedError { | ||
public var errorDescription: String? { | ||
switch self { | ||
case let .decodingError(comment): | ||
return NSLocalizedString("Application Error.", comment: comment) | ||
} | ||
} | ||
} |
Oops, something went wrong.