Skip to content

Commit

Permalink
consistent brace style
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Melbye committed Nov 13, 2018
1 parent 37d22fa commit e217786
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 34 deletions.
3 changes: 1 addition & 2 deletions app/AboutViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ - (void)viewDidLoad {
[self _updatePreferenceUI];
}

- (void)dealloc
{
- (void)dealloc {
[self _removeObservers];
}

Expand Down
6 changes: 2 additions & 4 deletions app/TerminalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ - (void)viewDidLoad {
}
}

- (void)dealloc
{
- (void)dealloc {
@try {
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
} @catch (NSException * __unused exception) {}
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == [UserPreferences shared]) {
[UIView animateWithDuration:0.1 animations:^{
self.view.backgroundColor = ThemeBackgroundColor([UserPreferences shared].theme);
Expand Down
9 changes: 3 additions & 6 deletions app/ThemeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ - (void)viewDidLoad {
[[UserPreferences shared] addObserver:self forKeyPath:@"theme" options:NSKeyValueObservingOptionNew context:nil];
}

- (void)dealloc
{
- (void)dealloc {
@try {
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
} @catch (NSException * __unused exception) {}
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
[self.tableView reloadData];
}

Expand All @@ -56,8 +54,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return 0;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (section == 1) {
return @"Preview";
}
Expand Down
33 changes: 11 additions & 22 deletions app/UserPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ UIStatusBarStyle ThemeStatusBar(UserPreferenceTheme theme) {
}
}

@implementation UserPreferences
{
@implementation UserPreferences {
NSUserDefaults *_defaults;
}

+ (instancetype)shared
{
+ (instancetype)shared {
static UserPreferences *shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand All @@ -75,47 +73,39 @@ + (instancetype)shared
return shared;
}

- (instancetype)init
{
- (instancetype)init {
self = [super init];
if (self) {
_defaults = [NSUserDefaults standardUserDefaults];
}
return self;
}

- (BOOL)mapCapsLockAsControl
{
- (BOOL)mapCapsLockAsControl {
return [_defaults boolForKey:kPreferenceMapCapsLockAsControlKey] ?: NO;
}

- (void)setMapCapsLockAsControl:(BOOL)mapCapsLockAsControl
{
- (void)setMapCapsLockAsControl:(BOOL)mapCapsLockAsControl {
[_defaults setBool:mapCapsLockAsControl forKey:kPreferenceMapCapsLockAsControlKey];
}

- (NSNumber *)fontSize
{
- (NSNumber *)fontSize {
return [_defaults objectForKey:kPreferenceFontSizeKey] ?: @(12);
}

- (void)setFontSize:(NSNumber *)fontSize
{
- (void)setFontSize:(NSNumber *)fontSize {
[_defaults setObject:fontSize forKey:kPreferenceFontSizeKey];
}

- (UserPreferenceTheme)theme
{
- (UserPreferenceTheme)theme {
return [_defaults integerForKey:kPreferenceThemeKey] ?: UserPreferenceThemeLight;
}

- (void)setTheme:(UserPreferenceTheme)theme
{
- (void)setTheme:(UserPreferenceTheme)theme {
[_defaults setInteger:theme forKey:kPreferenceThemeKey];
}

- (NSString *)JSONDictionary
{
- (NSString *)JSONDictionary {
NSDictionary *dict = @{
@"mapCapsLockAsControl": @(self.mapCapsLockAsControl),
@"fontSize": self.fontSize,
Expand All @@ -125,8 +115,7 @@ - (NSString *)JSONDictionary
return [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:dict options:0 error:nil] encoding:NSUTF8StringEncoding];
}

-(NSString *)_hexFromUIColor:(UIColor *)color
{
-(NSString *)_hexFromUIColor:(UIColor *)color {
const CGFloat *components = CGColorGetComponents(color.CGColor);
size_t count = CGColorGetNumberOfComponents(color.CGColor);

Expand Down

0 comments on commit e217786

Please sign in to comment.