mirror of
https://github.com/YuzuZensai/iOS-DiscordPresence.git
synced 2026-01-06 04:33:12 +00:00
Added Preferences
This commit is contained in:
2
Makefile
2
Makefile
@@ -3,7 +3,7 @@ export ARCHS = armv7 arm64 arm64e
|
||||
export SYSROOT = $(THEOS)/sdks/iPhoneOS14.5.sdk
|
||||
|
||||
INSTALL_TARGET_PROCESSES = SpringBoard
|
||||
SUBPROJECTS += Tweak
|
||||
SUBPROJECTS += Tweak Preferences
|
||||
|
||||
include $(THEOS)/makefiles/common.mk
|
||||
include $(THEOS_MAKE_PATH)/aggregate.mk
|
||||
|
||||
13
Preferences/Makefile
Normal file
13
Preferences/Makefile
Normal file
@@ -0,0 +1,13 @@
|
||||
TARGET := iphone:clang:latest:7.0
|
||||
|
||||
include $(THEOS)/makefiles/common.mk
|
||||
|
||||
BUNDLE_NAME = iOSDiscordPresencePreferences
|
||||
|
||||
iOSDiscordPresencePreferences_FILES = iOSDiscordPresenceRootListController.m
|
||||
iOSDiscordPresencePreferences_FRAMEWORKS = UIKit
|
||||
iOSDiscordPresencePreferences_PRIVATE_FRAMEWORKS = Preferences
|
||||
iOSDiscordPresencePreferences_INSTALL_PATH = /Library/PreferenceBundles
|
||||
iOSDiscordPresencePreferences_CFLAGS = -fobjc-arc
|
||||
|
||||
include $(THEOS_MAKE_PATH)/bundle.mk
|
||||
24
Preferences/Resources/Info.plist
Normal file
24
Preferences/Resources/Info.plist
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>iOSDiscordPresencePreferences</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>pink.kirameki.yuzu.iosdiscordpresencepreferences</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>BNDL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>iOSDiscordPresenceRootListController</string>
|
||||
</dict>
|
||||
</plist>
|
||||
69
Preferences/Resources/Root.plist
Normal file
69
Preferences/Resources/Root.plist
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>items</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>cell</key>
|
||||
<string>PSStaticTextCell</string>
|
||||
<key>height</key>
|
||||
<integer>150</integer>
|
||||
<key>label</key>
|
||||
<string></string>
|
||||
<key>icon</key>
|
||||
<string>banner.png</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>cell</key>
|
||||
<string>PSGroupCell</string>
|
||||
<key>label</key>
|
||||
<string>General</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>cell</key>
|
||||
<string>PSSwitchCell</string>
|
||||
<key>default</key>
|
||||
<false/>
|
||||
<key>defaults</key>
|
||||
<string>pink.kirameki.yuzu.iosdiscordpresencepreferences</string>
|
||||
<key>key</key>
|
||||
<string>isEnabled</string>
|
||||
<key>label</key>
|
||||
<string>Enabled</string>
|
||||
<key>PostNotification</key>
|
||||
<string>pink.kirameki.yuzu.iosdiscordpresencepreferences/PreferencesChanged</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>cell</key>
|
||||
<string>PSSecureEditTextCell</string>
|
||||
<key>defaults</key>
|
||||
<string>pink.kirameki.yuzu.iosdiscordpresencepreferences</string>
|
||||
<key>key</key>
|
||||
<string>discordToken</string>
|
||||
<key>label</key>
|
||||
<string>Discord Token</string>
|
||||
<key>placeholder</key>
|
||||
<string>Put your discord token here</string>
|
||||
<key>PostNotification</key>
|
||||
<string>pink.kirameki.yuzu.iosdiscordpresencepreferences/PreferencesChanged</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>cell</key>
|
||||
<string>PSGroupCell</string>
|
||||
<key>label</key>
|
||||
<string>Information</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>cell</key>
|
||||
<string>PSButtonCell</string>
|
||||
<key>label</key>
|
||||
<string>GitHub</string>
|
||||
<key>action</key>
|
||||
<string>openGitHubLink</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>title</key>
|
||||
<string>iOS-DiscordPresence</string>
|
||||
</dict>
|
||||
</plist>
|
||||
BIN
Preferences/Resources/banner.png
Executable file
BIN
Preferences/Resources/banner.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 146 KiB |
BIN
Preferences/Resources/icon.png
Executable file
BIN
Preferences/Resources/icon.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
BIN
Preferences/Resources/icon@2x.png
Executable file
BIN
Preferences/Resources/icon@2x.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
6
Preferences/iOSDiscordPresenceRootListController.h
Normal file
6
Preferences/iOSDiscordPresenceRootListController.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#import <Preferences/PSListController.h>
|
||||
#import <Preferences/PSSpecifier.h>
|
||||
|
||||
@interface iOSDiscordPresenceRootListController : PSListController
|
||||
|
||||
@end
|
||||
36
Preferences/iOSDiscordPresenceRootListController.m
Normal file
36
Preferences/iOSDiscordPresenceRootListController.m
Normal file
@@ -0,0 +1,36 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "iOSDiscordPresenceRootListController.h"
|
||||
|
||||
@implementation iOSDiscordPresenceRootListController
|
||||
|
||||
- (NSArray *)specifiers {
|
||||
if (!_specifiers) {
|
||||
_specifiers = [self loadSpecifiersFromPlistName:@"Root" target:self];
|
||||
}
|
||||
|
||||
return _specifiers;
|
||||
}
|
||||
|
||||
-(id)readPreferenceValue:(PSSpecifier*)specifier {
|
||||
NSDictionary * prefs = [NSDictionary dictionaryWithContentsOfFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", [specifier.properties objectForKey:@"defaults"]]];
|
||||
if (![prefs objectForKey:[specifier.properties objectForKey:@"key"]]) {
|
||||
return [specifier.properties objectForKey:@"default"];
|
||||
}
|
||||
return [prefs objectForKey:[specifier.properties objectForKey:@"key"]];
|
||||
}
|
||||
|
||||
-(void)setPreferenceValue:(id)value specifier:(PSSpecifier*)specifier {
|
||||
NSMutableDictionary * prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", [specifier.properties objectForKey:@"defaults"]]];
|
||||
[prefs setObject:value forKey:[specifier.properties objectForKey:@"key"]];
|
||||
[prefs writeToFile:[NSString stringWithFormat:@"/var/mobile/Library/Preferences/%@.plist", [specifier.properties objectForKey:@"defaults"]] atomically:YES];
|
||||
if([specifier.properties objectForKey:@"PostNotification"]) {
|
||||
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)[specifier.properties objectForKey:@"PostNotification"], NULL, NULL, YES);
|
||||
}
|
||||
[super setPreferenceValue:value specifier:specifier];
|
||||
}
|
||||
|
||||
- (void)openGitHubLink {
|
||||
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://github.com/YuzuZensai/iOS-DiscordPresence"]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>entry</key>
|
||||
<dict>
|
||||
<key>bundle</key>
|
||||
<string>iOSDiscordPresencePreferences</string>
|
||||
<key>cell</key>
|
||||
<string>PSLinkCell</string>
|
||||
<key>detail</key>
|
||||
<string>iOSDiscordPresenceRootListController</string>
|
||||
<key>icon</key>
|
||||
<string>icon.png</string>
|
||||
<key>isController</key>
|
||||
<true/>
|
||||
<key>label</key>
|
||||
<string>iOS-DiscordPresence</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,5 +1,9 @@
|
||||
#import <Tweak.h>
|
||||
|
||||
// Variable to store value from preferences
|
||||
Boolean isEnabled = false;
|
||||
NSString* discordToken = nil;
|
||||
|
||||
SBApplication* focusedApplication = nil;
|
||||
NSString* lastKnownBundleIdentifier = nil;
|
||||
Boolean isDeviceLocked = true;
|
||||
@@ -9,6 +13,7 @@ Boolean isDeviceLocked = true;
|
||||
-(void)frontDisplayDidChange:(id)arg1 {
|
||||
|
||||
%orig;
|
||||
|
||||
// Switched to SpringBoard
|
||||
if(arg1 == nil) {
|
||||
// If switched from SpringBoard to SpringBoard, ignore
|
||||
@@ -72,18 +77,13 @@ Boolean isDeviceLocked = true;
|
||||
-(void)updateDiscordPresence:(id)arg1 withState:(NSString *)state {
|
||||
|
||||
if(![arg1 isKindOfClass:[%c(SBApplication) class]] && arg1 != nil) return;
|
||||
|
||||
if(!isEnabled) return;
|
||||
|
||||
NSString *accessToken = @"";
|
||||
|
||||
// TODO: Make settings preferences or somehow fetch Discord token from the app?
|
||||
// Load discord token from text file at /var/mobile/Documents/DiscordToken.txt
|
||||
NSString* content = [NSString
|
||||
stringWithContentsOfFile: @"/var/mobile/Documents/DiscordToken.txt"
|
||||
encoding:NSUTF8StringEncoding
|
||||
error:NULL
|
||||
];
|
||||
|
||||
if(content != nil)
|
||||
accessToken = content;
|
||||
if(discordToken != nil)
|
||||
accessToken = discordToken;
|
||||
|
||||
// If SBApplication is passed
|
||||
if(arg1 != nil) {
|
||||
@@ -159,6 +159,7 @@ Boolean isDeviceLocked = true;
|
||||
-(void)_authenticationStateChanged:(id)arg1 {
|
||||
|
||||
%orig;
|
||||
|
||||
// Get the state changed notification, and find the SBFUserAuthenticationStateWasAuthenticatedKey value
|
||||
NSConcreteNotification *notification = arg1;
|
||||
int state = [[[notification userInfo] objectForKey: @"SBFUserAuthenticationStateWasAuthenticatedKey"] integerValue];
|
||||
@@ -170,6 +171,7 @@ Boolean isDeviceLocked = true;
|
||||
-(void)_sendUILockStateChangedNotification {
|
||||
|
||||
%orig;
|
||||
|
||||
// The phone is locked or focused application is nil, ignore
|
||||
if(isDeviceLocked || focusedApplication == nil) return;
|
||||
// If the phone is unlocked, then the user is peeking at the notification or didn't swipe up to unlock yet.
|
||||
@@ -184,3 +186,22 @@ Boolean isDeviceLocked = true;
|
||||
}
|
||||
}
|
||||
%end
|
||||
|
||||
static void loadPreferences()
|
||||
{
|
||||
NSString *preferencesPath = @"/var/mobile/Library/Preferences/pink.kirameki.yuzu.iosdiscordpresencepreferences.plist";
|
||||
NSMutableDictionary *preferences = [[NSMutableDictionary alloc] initWithContentsOfFile: preferencesPath];
|
||||
if(preferences)
|
||||
{
|
||||
NSLog(@"Updating preferences");
|
||||
|
||||
isEnabled = ( [preferences objectForKey:@"isEnabled"] ? [[preferences objectForKey:@"isEnabled"] boolValue] : isEnabled );
|
||||
discordToken = ( [preferences objectForKey:@"discordToken"] ? [preferences objectForKey:@"discordToken"] : discordToken );
|
||||
}
|
||||
}
|
||||
|
||||
%ctor
|
||||
{
|
||||
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPreferences, CFSTR("pink.kirameki.yuzu.iosdiscordpresencepreferences/PreferencesChanged"), NULL, CFNotificationSuspensionBehaviorCoalesce);
|
||||
loadPreferences();
|
||||
}
|
||||
Reference in New Issue
Block a user