Skip to content

Commit 5d647b8

Browse files
committed
Initial commit
0 parents  commit 5d647b8

15 files changed

+698
-0
lines changed

.github/workflows/swift.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Swift
2+
on: [push]
3+
jobs:
4+
build:
5+
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
6+
strategy:
7+
matrix:
8+
os: [macos-latest]
9+
swift: ["5.9"]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
- uses: swift-actions/setup-swift@v1.25.0
13+
with:
14+
swift-version: ${{ matrix.swift }}
15+
- uses: actions/checkout@v4
16+
- name: Build
17+
run: swift build

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

.swiftformat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--indent 2

.swiftlint.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
included:
2+
- Package.swift
3+
- Sources/Swift
4+
strict: true
5+
opt_in_rules:
6+
- indentation_width
7+
line_length: 100
8+
indentation_width:
9+
indentation_width: 2
10+
identifier_name:
11+
excluded: # excluded via string array
12+
- id
13+
- to
14+
trailing_comma:
15+
mandatory_comma: true

DOCS.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# DOCS
2+
3+
> 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.
4+
5+
Under "System Settings > Display > Night Shift" you find the UI controls.
6+
7+
It supports three schedules
8+
9+
1. Off
10+
2. Sunset to Sunrise
11+
3. Custom
12+
13+
When "Off" (`mode: 0`), you can turn it on for a single day toggling "Turn on until "tomorrow"
14+
15+
When "Sunset to Sunrise" (`mode: 1`), the schedule is automatic, and you can toggle it active until the next "sunrise"
16+
17+
When "Custom" (`mode: 2`), you can set a daily schedule, and additionally toggle it active until "tomorrow"
18+
19+
In all three modes, you can select a colour temperature, on a sliding scale between "Less Warm" and "More Warm"
20+
21+
## Technical
22+
23+
The status object
24+
25+
```
26+
var status: Status = Status()
27+
client.getBlueLightStatus(&status)
28+
```
29+
30+
```
31+
// seems to control the temporary setting until tomorrow/sunrise
32+
enabled: true|false
33+
available: true|false
34+
35+
// I guesss this has to do with location based information
36+
sunSchedulePermitted: true|false
37+
disableFlags: 0
38+
mode: 0|1|2
39+
schedule(fromTime(hour,minute),toTime(hour,minute))
40+
```

Package.resolved

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"pins" : [
3+
{
4+
"identity" : "swift-argument-parser",
5+
"kind" : "remoteSourceControl",
6+
"location" : "https://github.com/apple/swift-argument-parser",
7+
"state" : {
8+
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
9+
"version" : "1.2.3"
10+
}
11+
}
12+
],
13+
"version" : 2
14+
}

Package.swift

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// swift-tools-version: 5.9
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "nightshift",
8+
dependencies: [
9+
.package(url: "https://github.com/apple/swift-argument-parser", exact: "1.2.3"),
10+
],
11+
targets: [
12+
.target(
13+
name: "DisplayClient",
14+
path: "Sources/ObjC/DisplayClient",
15+
linkerSettings: [
16+
.unsafeFlags(["-F/System/Library/PrivateFrameworks"]),
17+
.linkedFramework("CoreBrightness"),
18+
]
19+
),
20+
.executableTarget(
21+
name: "nightshift",
22+
dependencies: [
23+
.byName(name: "DisplayClient"),
24+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
25+
],
26+
path: "Sources/Swift"
27+
),
28+
]
29+
)

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# README
2+
3+
A macOS tool to read and control the [Night Shift](https://support.apple.com/en-us/102191) feature.
4+
5+
## Usage
6+
7+
Print out current settings
8+
9+
```
10+
nightshift
11+
Schedule: sunrise
12+
Enabled: true
13+
Temperature: 0.49
14+
```
15+
16+
Control modes
17+
18+
```
19+
nightshift schedule
20+
nightshift schedule off
21+
nightshift schedule custom --from 11:00 --to 23:00 -t 0.3
22+
nightshift schedule sunrise --temperature 0.3
23+
```
24+
25+
Control details
26+
27+
```
28+
nightshift enable
29+
nightshift disable
30+
nightshift temperature
31+
nightshift temperature 0.33
32+
```
33+
34+
## Installation
35+
36+
**Via Github**
37+
38+
```https://www.youtube.com/watch?v=kWbALI5Ik0A
39+
git clone git@github.com:oschrenk/nightshift.swift.git
40+
cd nightshift.swift
41+
42+
# installs to $HOME/.local/bin/nightshift
43+
task install
44+
```
45+
46+
## Development
47+
48+
- `task build` **Build**
49+
- `task run` **Run**
50+
- `task lint` **Lint**
51+
52+
## Release
53+
54+
```
55+
task release
56+
# produces artifact in ./.build/release/nightshift
57+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#import <Foundation/Foundation.h>
2+
3+
// Partial header for CBBlueLightClient in private CoreBrightness API
4+
@interface CBBlueLightClient : NSObject
5+
6+
typedef struct {
7+
int hour;
8+
int minute;
9+
} Time;
10+
11+
typedef struct {
12+
Time fromTime;
13+
Time toTime;
14+
} ScheduleObjC;
15+
16+
typedef struct {
17+
BOOL active;
18+
BOOL enabled;
19+
BOOL sunSchedulePermitted;
20+
int mode;
21+
ScheduleObjC schedule;
22+
unsigned long long disableFlags;
23+
BOOL available;
24+
} Status;
25+
26+
- (BOOL)setStrength:(float)strength commit:(BOOL)commit;
27+
- (BOOL)setEnabled:(BOOL)enabled;
28+
- (BOOL)setMode:(int)mode;
29+
- (BOOL)setSchedule:(ScheduleObjC *)schedule;
30+
- (BOOL)getStrength:(float *)strength;
31+
- (BOOL)getBlueLightStatus:(Status *)status;
32+
- (void)setStatusNotificationBlock:(void (^)(void))block;
33+
+ (BOOL)supportsBlueLightReduction;
34+
@end

Sources/Swift/AppError.swift

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Foundation
2+
3+
enum AppError: Error {
4+
case decodingError(String)
5+
}
6+
7+
extension AppError: LocalizedError {
8+
public var errorDescription: String? {
9+
switch self {
10+
case let .decodingError(comment):
11+
return NSLocalizedString("Application Error.", comment: comment)
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)