Created
September 15, 2021 16:21
-
-
Save ryannair05/855992a7e5c93057afd0de8660a240d1 to your computer and use it in GitHub Desktop.
API for Chromaflow
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
// | |
// ChromaflowAPI.h | |
// Chromaflow | |
// | |
// Created by Ryan Nair on 10/15/21. | |
// Copyright © 2021 Ryan Nair. All rights reserved. | |
#import <UIKit/UIKit.h> | |
@interface ChromaFlowColorManager : NSObject | |
@property(nonatomic, strong, readwrite) UIColor *primaryColor; | |
@property(nonatomic, strong, readwrite) UIColor *secondaryColor; | |
@property(nonatomic, strong, readwrite) UIColor *backgroundColor; | |
@property(nonatomic, assign, readwrite) BOOL isPlayingMusic; | |
+ (instancetype)sharedInstance; | |
/*! | |
* Updates the color properties using MRMediaRemoteGetNowPlayingInfo() and posts an NSNotification with the name "imageDidChangeColorflow" | |
* | |
* @param sourceIdentifier caches the colors from the album artwork to be later stored in "/var/mobile/Library/ChromaFlow" if parameter is equal to @"com.apple.Music" | |
*/ | |
- (void)updateColors:(NSString *)sourceIdentifier; | |
@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
// | |
// ChromaflowAPI.x | |
// Chromaflow | |
// | |
// Created by Ryan Nair on 10/15/21. | |
// Copyright © 2021 Ryan Nair. All rights reserved. | |
#import "ChromaflowAPI.h" | |
// Example Usage | |
%group ChromaFlow | |
%hook anyUIView | |
- (id)initWithFrame:(CGRect)frame { // add notification observer | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleColorFlowChange:) name:@"imageDidChangeColorflow" object:nil]; | |
return %orig; | |
} | |
%new | |
- (void)handleColorFlowChange:(NSNotification *)notification { | |
ChromaFlowColorManager *colorManager = [objc_getClass(“ChromaFlowColorManager”) sharedInstance]; | |
if (colorManager.isPlayingMusic) { | |
// use or get Chromaflow's colors | |
UIColor *secondaryColor = colorManager.secondaryColor; | |
[self setBackgroundColor:secondaryColor]; | |
} | |
else { | |
// revert changes you made using Chromaflow's colors | |
[self setBackgroundColor:nil]; | |
} | |
} | |
%end | |
%hook anyUIViewController | |
-(void)loadView { // add notification observer | |
%orig; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleColorFlowChange:) name:@"imageDidChangeColorflow" object:nil]; | |
} | |
%new | |
- (void)handleColorFlowChange:(NSNotification *)notification { | |
ChromaFlowColorManager *colorManager = [objc_getClass(“ChromaFlowColorManager”) sharedInstance]; | |
if (colorManager.isPlayingMusic) { | |
// use or get Chromaflow's colors | |
UIColor *secondaryColor = colorManager.secondaryColor; | |
self.view.backgroundColor = secondaryColor; | |
} | |
else { | |
// revert changes you made using Chromaflow's colors | |
self.view.backgroundColor = nil; | |
} | |
} | |
%end | |
%end | |
static __attribute__((constructor)) void Init() { | |
// Check Chromaflow preferences to see if to use | |
Boolean keyExistsAndHasValidFormat; | |
if (CFPreferencesGetAppBooleanValue(CFSTR("colorLockScreen"), CFSTR("com.ryannair05.chromaflow"), &keyExistsAndHasValidFormat) || !keyExistsAndHasValidFormat) { | |
// Chromaflow coloring is actually enabled | |
%init(ChromaFlow); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment