Skip to content

Commit

Permalink
Added contact buttons in preference pane
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesperflodin1 committed Aug 19, 2018
1 parent 9d144f6 commit 44acd0b
Show file tree
Hide file tree
Showing 18 changed files with 211 additions and 37 deletions.
2 changes: 1 addition & 1 deletion layout/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: fi.flodin.tonehelper
Name: ToneHelper
Depends: mobilesubstrate, ws.hbang.common (>= 1.12)
Version: 0.2.5
Version: 0.2.7
Architecture: iphoneos-arm
Description: Automatically adds ringtones from Audiko to device
Maintainer: Jesper Flodin <[email protected]>
Expand Down
33 changes: 33 additions & 0 deletions thprefsbundle/JFTHRootListController.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
//libcephei prefs headers we need
#import <CepheiPrefs/HBTintedTableCell.h>
#import <CepheiPrefs/HBRootListController.h>
#import <CepheiPrefs/HBLinkTableCell.h>
#import <CepheiPrefs/HBTwitterCell.h>
#import <CepheiPrefs/HBImageTableCell.h>
#import <CepheiPrefs/HBPackageNameHeaderCell.h>
#import <CepheiPrefs/HBSupportController.h>

#import <SafariServices/SFSafariViewController.h>

#import <Preferences/PSSpecifier.h>

#import <TechSupport/TechSupport.h>

#import "../Log.h"

@class TSIncludeInstruction;

NS_ASSUME_NONNULL_BEGIN


@interface JFTHRootListController : HBRootListController

+ (nullable NSString *)hb_supportEmailAddress;
+ (nullable NSArray <TSIncludeInstruction *> *)hb_supportInstructions;
- (void)hb_sendSupportEmail;

- (void)hb_openURL:(PSSpecifier *)specifier;

@end

NS_ASSUME_NONNULL_END

@interface NSTask : NSObject

- (id)init;
- (void)launch;
- (void)setArguments:(id)arg1;
- (void)setLaunchPath:(id)arg1;
- (void)setStandardOutput:(id)arg1;
- (id)standardOutput;

@end
34 changes: 0 additions & 34 deletions thprefsbundle/JFTHRootListController.m

This file was deleted.

164 changes: 164 additions & 0 deletions thprefsbundle/JFTHRootListController.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
#include "JFTHRootListController.h"
#import <Cephei/HBRespringController.h>
#include <version.h>
#import "../Log.h"

@implementation JFTHRootListController

+ (NSString *)hb_specifierPlist {
return @"Root";
}
+ (NSString *)hb_shareText {
return nil;
}

+ (NSURL *)hb_shareURL {
return nil;
}

- (id)specifiers {
[super specifiers];
NSBundle *prefBundle = [NSBundle bundleWithIdentifier:@"fi.flodin.thprefsbundle"];

PSSpecifier* githubSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Visit Github Page"
target:self
set:NULL
get:NULL
detail:Nil
cell:PSLinkCell
edit:Nil];
githubSpecifier->action = @selector(hb_openURL:);
[githubSpecifier setProperty:NSClassFromString(@"HBLinkTableCell") forKey:@"cellClass"];
[githubSpecifier setProperty:@"Source code and Issues" forKey:@"subtitle"];
[githubSpecifier setProperty:@YES forKey:@"enabled"];
[githubSpecifier setProperty:@"https://github.com/Jesperflodin1/tonehelper" forKey:@"url"];
[githubSpecifier setProperty:[UIImage imageWithContentsOfFile:[prefBundle pathForResource:@"GitHub" ofType:@"png"]] forKey:@"iconImage"];
//[githubSpecifier setProperty:NSStringFromSelector(@selector(hb_openURL:)) forKey:@"action"];

PSSpecifier* redditSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Contact me on Reddit"
target:self
set:NULL
get:NULL
detail:Nil
cell:PSLinkCell
edit:Nil];
redditSpecifier->action = @selector(hb_openURL:);
[redditSpecifier setProperty:NSClassFromString(@"HBLinkTableCell") forKey:@"cellClass"];
[redditSpecifier setProperty:@"Contact me on Reddit" forKey:@"subtitle"];
[redditSpecifier setProperty:@YES forKey:@"enabled"];
[redditSpecifier setProperty:@"https://www.reddit.com/user/jesperflodin1" forKey:@"url"];
[redditSpecifier setProperty:[UIImage imageWithContentsOfFile:[prefBundle pathForResource:@"Reddit" ofType:@"png"]] forKey:@"iconImage"];
//[redditSpecifier setProperty:NSStringFromSelector(@selector(hb_openURL:)) forKey:@"action"];

PSSpecifier* donateSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Donate"
target:self
set:NULL
get:NULL
detail:Nil
cell:PSLinkCell
edit:Nil];
donateSpecifier->action = @selector(hb_openURL:);
[donateSpecifier setProperty:NSClassFromString(@"HBLinkTableCell") forKey:@"cellClass"];
[donateSpecifier setProperty:@"If you like this tweak, please consider a donation." forKey:@"subtitle"];
[donateSpecifier setProperty:@YES forKey:@"enabled"];
[donateSpecifier setProperty:@"https://www.paypal.me/Jesperflodin" forKey:@"url"];
[donateSpecifier setProperty:[UIImage imageWithContentsOfFile:[prefBundle pathForResource:@"paypal" ofType:@"png"]] forKey:@"iconImage"];
//[donateSpecifier setProperty:NSStringFromSelector(@selector(hb_openURL:)) forKey:@"action"];

PSSpecifier* emailSpecifier = [PSSpecifier preferenceSpecifierNamed:@"Email me"
target:self
set:NULL
get:NULL
detail:Nil
cell:PSLinkCell
edit:Nil];
emailSpecifier->action = @selector(hb_sendSupportEmail:);
[emailSpecifier setProperty:NSClassFromString(@"HBLinkTableCell") forKey:@"cellClass"];
[emailSpecifier setProperty:@"Send an email to me" forKey:@"subtitle"];
[emailSpecifier setProperty:@YES forKey:@"enabled"];
[emailSpecifier setProperty:@"fi.flodin.tonehelper" forKey:@"defaults"];
//[emailSpecifier setProperty:NSStringFromSelector(@selector(hb_sendSupportEmail:)) forKey:@"action"];
[emailSpecifier setProperty:[UIImage imageWithContentsOfFile:[prefBundle pathForResource:@"email" ofType:@"png"]] forKey:@"iconImage"];

[_specifiers addObject:githubSpecifier];
[_specifiers addObject:redditSpecifier];
[_specifiers addObject:emailSpecifier];
[_specifiers addObject:donateSpecifier];
return _specifiers;
}

- (void)respring:(PSSpecifier *)specifier {
PSTableCell *cell = [self cachedCellForSpecifier:specifier];

// disable the cell, in case it takes a moment
cell.cellEnabled = NO;
/*
// ask for the url to be generated
[(PreferencesAppController *)[UIApplication sharedApplication] generateURL];
// sadly, this is stored in the preferences…
NSString *position = (__bridge NSString *)CFPreferencesCopyAppValue(CFSTR("kPreferencePositionKey"), kCFPreferencesCurrentApplication);
*/
// call the main method
[HBRespringController respring];
}

- (void)hb_openURL:(PSSpecifier *)specifier {
// get the url from the specifier
NSURL *url = [NSURL URLWithString:specifier.properties[@"url"]];

// if the url is nil, assert
NSAssert(url, @"No URL was provided, or it is invalid.");

// ensure SafariServices is loaded (if it exists)
[[NSBundle bundleWithPath:@"/System/Library/Frameworks/SafariServices.framework"] load];

// we can only use SFSafariViewController if it’s available (iOS 9), and the url scheme is http(s)
if (%c(SFSafariViewController) && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) {
// initialise view controller
SFSafariViewController *viewController = [[%c(SFSafariViewController) alloc] initWithURL:url];

// use the same tint color as the presenting view controller
viewController.view.tintColor = self.view.tintColor;

// present it
[self.realNavigationController presentViewController:viewController animated:YES completion:nil];
} else {
// just do a usual boring openURL:
[[UIApplication sharedApplication] openURL:url];
}
}

+ (nullable NSString *)hb_supportEmailAddress {
return @"[email protected]";
}

+ (nullable TSLinkInstruction *)hb_linkInstruction {
if ([self hb_supportEmailAddress]) {
return [HBSupportController linkInstructionForEmailAddress:[self hb_supportEmailAddress]];
}

return nil;
}

+ (nullable NSArray <TSIncludeInstruction *> *)hb_supportInstructions {
return nil;
}

- (void)hb_sendSupportEmail {
DLog(@"sendsupportemail called");
[self hb_sendSupportEmail:nil];
}

- (void)hb_sendSupportEmail:(nullable PSSpecifier *)specifier {
DLog(@"sendsupportemail:specifier called");
TSContactViewController *viewController = [HBSupportController supportViewControllerForBundle:[NSBundle bundleForClass:self.class] preferencesIdentifier:specifier.properties[@"defaults"] linkInstruction:[self.class hb_linkInstruction] supportInstructions:[self.class hb_supportInstructions]];

if ([viewController respondsToSelector:@selector(tintColor)]) {
viewController.view.tintColor = self.view.tintColor;
}

[self.realNavigationController pushViewController:viewController animated:YES];
}

@end
5 changes: 3 additions & 2 deletions thprefsbundle/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ export TARGET = iphone:clang:11.2:8.0
ARCHS = arm64

BUNDLE_NAME = THPrefsBundle
THPrefsBundle_FILES = $(wildcard *.m) ../JFTHRingtoneDataController.m ../UIAlertController+Window.m
THPrefsBundle_FILES = $(wildcard *.m) $(wildcard *.x) ../JFTHRingtoneDataController.m ../UIAlertController+Window.m
THPrefsBundle_INSTALL_PATH = /Library/PreferenceBundles
THPrefsBundle_FRAMEWORKS = UIKit
THPrefsBundle_FRAMEWORKS = UIKit MessageUI
THPrefsBundle_PRIVATE_FRAMEWORKS = Preferences
THPrefsBundle_EXTRA_FRAMEWORKS += cephei cepheiprefs
THPrefsBundle_LDFLAGS = -lMobileGestalt

THPrefsBundle_CFLAGS = -fobjc-arc

Expand Down
Binary file added thprefsbundle/Resources/GitHub.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/Reddit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions thprefsbundle/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,19 @@ Requires Respring!</string>
<dict>
<key>cell</key>
<string>PSGroupCell</string>
<key>label</key>
<string>Contact info</string>
<key>footerText</key>
<string>© 2018 Jesper Flodin. Source code licensed under the MIT license.</string>
</dict>
<dict>
<key>cellClass</key>
<string>HBTwitterCell</string>
<key>label</key>
<string>Jesper Flodin</string>
<key>user</key>
<string>JesperFlodin</string>
</dict>
</array>
<key>title</key>
<string>ToneHelper</string>
Expand Down
Binary file added thprefsbundle/Resources/email.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/paypal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added thprefsbundle/Resources/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 44acd0b

Please sign in to comment.