Skip to content
This repository was archived by the owner on Jan 4, 2024. It is now read-only.

Commit 086c6dd

Browse files
authored
Improvements (#22)
* Remember last Location on Map * Use app upload button for uploads * better logging
1 parent 77f36e0 commit 086c6dd

File tree

10 files changed

+199
-116
lines changed

10 files changed

+199
-116
lines changed

Theos/Classes/JDELogsVC.m

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
#import <Foundation/Foundation.h>
12
#import "JDELogsVC.h"
23
#import "JDESettingsManager.h"
3-
4+
#import "../Utils/Logging/JELog.h"
45

56
@interface JDELogsVC()
67
@property (strong, nonatomic) UITextView *logView;
@@ -14,10 +15,10 @@ - (void)viewDidLoad{
1415
self.view.backgroundColor = UIColor.systemBackgroundColor;
1516

1617
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
17-
initWithImage:[UIImage systemImageNamed:@"ellipsis"]
18-
style:UIBarButtonItemStylePlain
19-
target:self
20-
action:@selector(didTapMore:)];
18+
initWithImage:[UIImage systemImageNamed:@"ellipsis"]
19+
style:UIBarButtonItemStylePlain
20+
target:self
21+
action:@selector(didTapMore:)];
2122

2223
[self configureLogView];
2324
[self loadLogs];
@@ -39,13 +40,58 @@ - (void)configureLogView{
3940
]];
4041
}
4142
- (void)loadLogs{
42-
if([[NSFileManager defaultManager] fileExistsAtPath:self.manager.logFile]){
43-
self.logView.text = [NSString stringWithContentsOfFile:self.manager.logFile encoding:NSUTF8StringEncoding error:nil];
43+
if([[NSFileManager defaultManager] fileExistsAtPath:logFilePath()]){
44+
NSError *err;
45+
46+
NSDictionary *logsDict = [NSDictionary
47+
dictionaryWithContentsOfURL:[NSURL fileURLWithPath:logFilePath()]
48+
error:&err];
49+
50+
if (err.code == NSFileReadCorruptFileError){
51+
[self clearLogs];
52+
}
53+
else if (err != nil){
54+
self.logView.text = err.debugDescription;
55+
return;
56+
}
57+
NSMutableArray<NSAttributedString*> *logs = [NSMutableArray new];
58+
for(NSData *log in logsDict[@"logs"]){
59+
[logs addObject:[[NSAttributedString alloc] initWithData:log
60+
options:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}
61+
documentAttributes:nil
62+
error:nil]];
63+
}
64+
NSMutableAttributedString *finalLog = [NSMutableAttributedString new];
65+
static NSString * const newLineRaw = @"\n";
66+
NSAttributedString * const newLineAttr = [[NSAttributedString alloc] initWithString:newLineRaw];
67+
for (NSAttributedString *log in logs){
68+
[finalLog appendAttributedString:log];
69+
[finalLog appendAttributedString:newLineAttr];
70+
}
71+
self.logView.attributedText = finalLog;
4472
}
4573
else{
4674
self.logView.text = @"No Log File Found";
4775
}
4876
}
77+
78+
- (void)clearLogs{
79+
NSError *err;
80+
[[NSFileManager defaultManager] removeItemAtPath:logFilePath() error:&err];
81+
if(err){
82+
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"An error happened while deleting log file"
83+
message:err.description
84+
preferredStyle:UIAlertControllerStyleAlert];
85+
UIAlertAction* action = [UIAlertAction actionWithTitle:@"Dismiss"
86+
style:UIAlertActionStyleDefault
87+
handler:^(UIAlertAction * action) {}];
88+
[alert addAction:action];
89+
[self presentViewController:alert animated:YES completion:nil];
90+
}
91+
else{
92+
[self loadLogs];
93+
}
94+
}
4995
- (void)didTapMore:(id)sender{
5096
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
5197
message:nil
@@ -64,24 +110,7 @@ - (void)didTapMore:(id)sender{
64110
UIAlertAction* clearAction = [UIAlertAction actionWithTitle:@"Clear Logs"
65111
style:UIAlertActionStyleDefault
66112
handler:^(UIAlertAction * action) {
67-
dispatch_async(dispatch_get_main_queue(), ^{
68-
if(self.manager.logFileExists){
69-
NSError *err;
70-
[[NSFileManager defaultManager] removeItemAtPath:self.manager.logFile error:&err];
71-
if(err){
72-
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"An error happened while deleting log file"
73-
message:err.description
74-
preferredStyle:UIAlertControllerStyleAlert];
75-
UIAlertAction* action = [UIAlertAction actionWithTitle:@"Dismiss"
76-
style:UIAlertActionStyleDefault
77-
handler:^(UIAlertAction * action) {}];
78-
[alert addAction:action];
79-
[self presentViewController:alert animated:YES completion:nil];
80-
}
81-
else{
82-
[self loadLogs];
83-
}
84-
}});
113+
dispatch_async(dispatch_get_main_queue(), ^{ [self clearLogs]; });
85114
}
86115
];
87116

Theos/Classes/JDEMapView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Created by Natheer on 08/07/2022.
66
//
7-
7+
#import <objc/objc-runtime.h>
88
#import <UIKit/UIKit.h>
99
#import <MapKit/MapKit.h>
1010
#import <CoreLocation/CLLocationManager.h>

Theos/Classes/JDEMapView.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,17 @@ - (void)viewDidLoad {
3838
lpgr.minimumPressDuration = .5;
3939
[_mapView addGestureRecognizer:lpgr];
4040
//add pin at 0, 0
41-
_pin = [MKPointAnnotation new];
41+
NSString *lastCoords = [JDESettingsManager.sharedInstance spoofedLocation];
42+
if(lastCoords != nil){
43+
NSArray *coordsArray = [lastCoords componentsSeparatedByString:@";"];
44+
CLLocationCoordinate2D coords = {
45+
[coordsArray[0] doubleValue],
46+
[coordsArray[1] doubleValue]};
47+
48+
self.pin = [[MKPointAnnotation alloc] initWithCoordinate:coords];
49+
} else {
50+
_pin = [MKPointAnnotation new];
51+
}
4252
[_mapView addAnnotation:_pin];
4353

4454
//Overlay Button

Theos/Classes/JDESettingsManager.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
#import <CoreLocation/CLLocationManager.h>
33
#import <UIKit/UIKit.h>
44
#import "../Headers/AppHaptic.h"
5-
#import <objc/runtime.h>
65

76
@interface JDESettingsManager : NSObject
87
@property (strong, nonatomic) NSUserDefaults *tweakSettings;
9-
@property (strong, nonatomic, readonly) NSString *logFile;
10-
@property (nonatomic, readonly) BOOL logFileExists;
8+
119

1210
+ (JDESettingsManager *)sharedInstance;
1311
- (NSDictionary*)cellInfoForPath:(NSIndexPath*)indexPath;
@@ -16,6 +14,5 @@
1614
- (BOOL)featureStateForTag:(NSUInteger)row;
1715
- (void)featureStateChangedTo:(BOOL)newState forTag:(NSUInteger)tag;
1816
- (NSString*)localizedStringForKey:(NSString*)key;
19-
- (void)logString:(NSString*)string;
2017
@end
2118

Theos/Classes/JDESettingsManager.m

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
@interface JDESettingsManager()
99
@property (strong, nonatomic) NSBundle *bundle;
10-
@property (strong, nonatomic, readwrite) NSString *logFile;
11-
@property (nonatomic, readwrite) BOOL logFileExists;
1210
@end
1311

1412
@implementation JDESettingsManager
@@ -25,9 +23,7 @@ - (id) init{
2523
_bundle = [NSBundle bundleWithPath:@"Library/Application Support/Jodel EMPROVED.bundle"];
2624
}
2725
//logFile stuff
28-
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
29-
self.logFile = [docsDir stringByAppendingPathComponent:@"JDELogs.log"];
30-
self.logFileExists = [[NSFileManager defaultManager] fileExistsAtPath:self.logFile];
26+
3127
}
3228
return self;
3329
}
@@ -136,18 +132,5 @@ - (NSString*)localizedStringForKey:(NSString*)key{ return [_bundle localizedStri
136132
- (NSString*)pathForImageWithName:(NSString*)name{
137133
return [_bundle pathForResource:name ofType:@"png" inDirectory:@"Icons"];
138134
}
139-
- (void)logString:(NSString*)string{
140-
string = [[NSString stringWithFormat:@"[%@] ", [[NSDate now] description]] stringByAppendingString:string];
141-
string = [string stringByAppendingString:@"\n"];
142-
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:self.logFile];
143135

144-
if(fileHandle){
145-
[fileHandle seekToEndOfFile];
146-
[fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
147-
[fileHandle closeFile];
148-
}
149-
else{
150-
[string writeToFile:self.logFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
151-
}
152-
}
153136
@end

Theos/Classes/ThemingViewController.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
@end
99

1010

11-
#define main "mainColor"
12-
#define secondary "customLightGrayColor"
13-
#define user "meColor"
14-
#define userDot "channelNotification"
15-
#define channel "channelColor"
16-
#define channelDot "declineColor" // channel and notification Dots
17-
#define notification "notificationColor"
18-
#define pollCell "pollBgColor"
19-
20-
2111
typedef NS_ENUM(NSUInteger, ThemeOption){
2212
ThemeOptionMainColor,
2313
ThemeOptionSecondaryColor,

Theos/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include $(THEOS)/makefiles/common.mk
66

77
TWEAK_NAME = JodelEmproved
88
JodelEmproved_FILES = Tweak.x JDEViewController.m $(wildcard Classes/*.m)
9+
JodelEmproved_FILES += Utils/Logging/JELog.m
910
JodelEmproved_CFLAGS = -fobjc-arc -Wno-unguarded-availability-new -DPACKAGE_VERSION='@"$(THEOS_PACKAGE_BASE_VERSION)"'
1011

1112

0 commit comments

Comments
 (0)