1
0
mirror of https://github.com/Toxblh/MTMR.git synced 2026-01-10 17:08:39 +00:00

+ Added NightShift Widget

+ Updated icons for illumination and added icons for NightShift
This commit is contained in:
Toxblh 2018-08-29 00:08:46 +01:00
parent 10d94d65e2
commit eee4082a1a
16 changed files with 162 additions and 4 deletions

View File

@ -34,6 +34,8 @@
B059D622205E03F5006E6B86 /* TouchBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D621205E03F5006E6B86 /* TouchBarController.swift */; };
B059D624205E04F3006E6B86 /* CustomButtonTouchBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B059D623205E04F3006E6B86 /* CustomButtonTouchBarItem.swift */; };
B059D62D205F11E8006E6B86 /* DFRFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B059D62C205F11E8006E6B86 /* DFRFoundation.framework */; };
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = B08173262135F02B005D4908 /* NightShiftBarItem.swift */; };
B081732A2135F354005D4908 /* CoreBrightness.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B08173292135F354005D4908 /* CoreBrightness.framework */; };
B082B253205C7D8000BC04DC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = B082B252205C7D8000BC04DC /* AppDelegate.swift */; };
B082B257205C7D8000BC04DC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B082B256205C7D8000BC04DC /* Assets.xcassets */; };
B082B25A205C7D8000BC04DC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B082B258205C7D8000BC04DC /* Main.storyboard */; };
@ -87,6 +89,9 @@
B059D629205E13E5006E6B86 /* TouchBarPrivateApi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchBarPrivateApi.h; sourceTree = "<group>"; };
B059D62A205F0E7D006E6B86 /* TouchBarPrivateApi-Bridging.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "TouchBarPrivateApi-Bridging.h"; sourceTree = "<group>"; };
B059D62C205F11E8006E6B86 /* DFRFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DFRFoundation.framework; path = ../../../../../System/Library/PrivateFrameworks/DFRFoundation.framework; sourceTree = "<group>"; };
B08173262135F02B005D4908 /* NightShiftBarItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightShiftBarItem.swift; sourceTree = "<group>"; };
B08173282135F128005D4908 /* CBBlueLightClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CBBlueLightClient.h; sourceTree = "<group>"; };
B08173292135F354005D4908 /* CoreBrightness.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBrightness.framework; path = ../../../../../System/Library/PrivateFrameworks/CoreBrightness.framework; sourceTree = "<group>"; };
B082B24F205C7D8000BC04DC /* MTMR.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MTMR.app; sourceTree = BUILT_PRODUCTS_DIR; };
B082B252205C7D8000BC04DC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
B082B256205C7D8000BC04DC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@ -118,6 +123,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
B081732A2135F354005D4908 /* CoreBrightness.framework in Frameworks */,
B059D62D205F11E8006E6B86 /* DFRFoundation.framework in Frameworks */,
B09EB1E6207C0F8E00D5C1E0 /* MultitouchSupport.framework in Frameworks */,
);
@ -136,6 +142,7 @@
B059D62B205F11E8006E6B86 /* Frameworks */ = {
isa = PBXGroup;
children = (
B08173292135F354005D4908 /* CoreBrightness.framework */,
B09EB1E5207C0F8E00D5C1E0 /* MultitouchSupport.framework */,
B059D62C205F11E8006E6B86 /* DFRFoundation.framework */,
);
@ -230,6 +237,7 @@
6042B6A92083E27000C525C8 /* DeprecatedCarbonAPI.c */,
60173D3C20C0031B002C305F /* LaunchAtLoginController.h */,
60173D3D20C0031B002C305F /* LaunchAtLoginController.m */,
B08173282135F128005D4908 /* CBBlueLightClient.h */,
);
path = CBridge;
sourceTree = "<group>";
@ -247,6 +255,7 @@
60F7D453208CC31400ABF5D2 /* InputSourceBarItem.swift */,
60C44AFC20A373A100C0EC91 /* MusicBarItem.swift */,
60669B4220AD8FA80074E817 /* GroupBarItem.swift */,
B08173262135F02B005D4908 /* NightShiftBarItem.swift */,
);
path = Widgets;
sourceTree = "<group>";
@ -381,6 +390,7 @@
B0F3112520C9E35F0076BB88 /* SupportNSTouchBar.swift in Sources */,
6042B6AA2083E27000C525C8 /* DeprecatedCarbonAPI.c in Sources */,
B09EB1E4207C082000D5C1E0 /* HapticFeedback.swift in Sources */,
B08173272135F02B005D4908 /* NightShiftBarItem.swift in Sources */,
60F7D454208CC31400ABF5D2 /* InputSourceBarItem.swift in Sources */,
36A778BE20A6C27100B38714 /* GeneralExtensions.swift in Sources */,
60669B4320AD8FA80074E817 /* GroupBarItem.swift in Sources */,

View File

@ -6,7 +6,7 @@
},
{
"idiom" : "universal",
"filename" : "ill_down.png",
"filename" : "KeyboardBrightDown.png",
"scale" : "2x"
},
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -6,7 +6,7 @@
},
{
"idiom" : "universal",
"filename" : "ill_up.png",
"filename" : "KeyboardBrightUp.png",
"scale" : "2x"
},
{

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "NightShift.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "NightShiftEnabled.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -0,0 +1,34 @@
//
// CBBlueLightClient.h
// MTMR
//
// Created by Anton Palgunov on 28/08/2018.
// Copyright © 2018 Anton Palgunov. All rights reserved.
//
#import <Foundation/Foundation.h>
typedef struct {
int hour;
int minute;
} Time;
typedef struct {
Time fromTime;
Time toTime;
} Schedule;
typedef struct {
BOOL active;
BOOL enabled;
BOOL sunSchedulePermitted;
int mode;
Schedule schedule;
unsigned long long disableFlags;
} Status;
@interface CBBlueLightClient: NSObject
- (BOOL) setEnabled:(BOOL)enabled;
- (BOOL) setMode:(int)mode;
- (void) getBlueLightStatus: (Status *)status;
@end

View File

@ -9,7 +9,8 @@
#import "TouchBarPrivateApi.h"
#import "TouchBarSupport.h"
#import "DeprecatedCarbonAPI.h"
#include "LaunchAtLoginController.h"
#import "CBBlueLightClient.h"
#import "LaunchAtLoginController.h"
NS_ASSUME_NONNULL_BEGIN

View File

@ -177,7 +177,16 @@ class SupportedTypesHolder {
parameters: [:]
)
},
]
"nightShift": {_ in
return (
item: .nightShift(),
action: .none,
longAction: .none,
parameters: [:]
)
}
]
static let sharedInstance = SupportedTypesHolder()
@ -211,6 +220,7 @@ enum ItemType: Decodable {
case inputsource()
case music(interval: Double)
case groupBar(items: [BarItemDefinition])
case nightShift()
private enum CodingKeys: String, CodingKey {
case type
@ -242,6 +252,7 @@ enum ItemType: Decodable {
case inputsource
case music
case groupBar
case nightShift
}
init(from decoder: Decoder) throws {
@ -298,6 +309,9 @@ enum ItemType: Decodable {
case .groupBar:
let items = try container.decode([BarItemDefinition].self, forKey: .items)
self = .groupBar(items: items)
case .nightShift:
self = .nightShift()
}
}
}

View File

@ -44,6 +44,8 @@ extension ItemType {
return "com.toxblh.mtmr.music."
case .groupBar(items: _):
return "com.toxblh.mtmr.groupBar."
case .nightShift(items: _):
return "com.toxblh.mtmr.nightShift."
}
}
@ -279,6 +281,8 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
barItem = MusicBarItem(identifier: identifier, interval: interval)
case .groupBar(items: let items):
barItem = GroupBarItem(identifier: identifier, items: items)
case .nightShift():
barItem = NightShiftBarItem(identifier: identifier)
}
if let action = self.action(forItem: item), let item = barItem as? CustomButtonTouchBarItem {

View File

@ -0,0 +1,50 @@
//
// nightShift.swift
// MTMR
//
// Created by Anton Palgunov on 28/08/2018.
// Copyright © 2018 Anton Palgunov. All rights reserved.
//
import Foundation
class NightShiftBarItem: CustomButtonTouchBarItem {
private let nsclient = CBBlueLightClient()
private var blueLightStatus: Status {
var status: Status = Status()
nsclient.getBlueLightStatus(&status)
return status
}
private var isNightShiftEnabled: Bool {
return self.blueLightStatus.enabled.boolValue
}
private func setNightShift(state: Bool) {
self.nsclient.setEnabled(state)
}
init(identifier: NSTouchBarItem.Identifier) {
super.init(identifier: identifier, title: "")
self.isBordered = false
self.setWidth(value: 28)
self.tapClosure = { [weak self] in self?.nightShiftAction() }
self.refresh()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func nightShiftAction() {
self.setNightShift(state: !self.isNightShiftEnabled)
self.refresh()
}
func refresh() {
self.image = isNightShiftEnabled ? #imageLiteral(resourceName: "nightShiftOn") : #imageLiteral(resourceName: "nightShiftOff")
}
}