Carbonite Modules

This page contains documentation on creating new module pages for Carbonite, modules follow a requirement to ensure they work well with each other and this page will show that.

Creating a new module

Modules built for Carbonite need to subclass UIView, each new module is added into an array of the ModulesView which the collection view uses to display those modules.

Modules must use AutoLayout to help them fit multiple screen sizes/window sizes. Using -initWithFrame: may result in issues and support will not be provided.

// MyModuleView.h

@interface MyModuleView : UIView
@end

The @interface in the *.h file is where we can store any variables, properties or functions for use inside or outside the class. Properties and methods can be accessed outside the class while variables (places in curly brackets) cannot be seen and thus not be used by outside classes.

// MyModuleView.m
#import "MyModuleView.h"

@implementation MyModuleView
-(id) initWithFrame:(CGRect)frame {
  if(self = [super initWithFrame:frame]) {
    [self setTranslatesAutoresizingMaskIntoConstraints:NO];
    
    // code starts here
  } return self;
}
@end

The @implementation in the *.m file is where the magic happens, this is where we code the majority of the class, starting with the -initWithFrame: method, if ever using .nib or .xib files (Xcode), you should also use -initWithCoder:

Adding a module to Carbonite

// Tweak.x

@interface ModulesView : UIView
-(void) addModuleWithView:(UIView *)arg1;
@end

@interface SBReachabilityWindow : UIWindow
@property (nonatomic, retain) ModulesView *modulesView;
@end

Carbonite uses the SBReachabilityWindow to add a property of ModulesView which holds all modules, CarboniteView which is the main module is added initially and any further modules are added after.

// Tweak.x

%hook SBReachabilityWindow
-(void) layoutSubviews { // not recommended but Carbonite handles duplication issues
  %orig;
  
  MyModuleView *myModuleView = [[MyModuleView alloc] init];
  [self.modulesView addModuleWithView:myModuleView];
  // ModulesView should handle the array correctly by only adding a new view once
}
%end

-layoutSubviews is never recommended when making tweaks. Carbonite is made in a way that it doesn't duplicate itself when a layout call is made.

Running this code as-is, with Carbonite installed will add it to the modules, this is your blank slate, add to it what you want and start coding an amazing module for use in an innovative tweak!

Suggestions

  • Weather Module

  • Maps Module

  • Calculator Module (suggested by a user on Reddit)

Last updated