Skip to content

Instantly share code, notes, and snippets.

@ryannair05
Created September 15, 2021 16:21
Embed
What would you like to do?
API for Chromaflow
//
// 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
//
// 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