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

Commit

Permalink
Improvements (#22)
Browse files Browse the repository at this point in the history
* Remember last Location on Map

* Use app upload button for uploads

* better logging
  • Loading branch information
ExTBH authored Jan 6, 2023
1 parent 77f36e0 commit 086c6dd
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 116 deletions.
79 changes: 54 additions & 25 deletions Theos/Classes/JDELogsVC.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import <Foundation/Foundation.h>
#import "JDELogsVC.h"
#import "JDESettingsManager.h"

#import "../Utils/Logging/JELog.h"

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

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithImage:[UIImage systemImageNamed:@"ellipsis"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(didTapMore:)];
initWithImage:[UIImage systemImageNamed:@"ellipsis"]
style:UIBarButtonItemStylePlain
target:self
action:@selector(didTapMore:)];

[self configureLogView];
[self loadLogs];
Expand All @@ -39,13 +40,58 @@ - (void)configureLogView{
]];
}
- (void)loadLogs{
if([[NSFileManager defaultManager] fileExistsAtPath:self.manager.logFile]){
self.logView.text = [NSString stringWithContentsOfFile:self.manager.logFile encoding:NSUTF8StringEncoding error:nil];
if([[NSFileManager defaultManager] fileExistsAtPath:logFilePath()]){
NSError *err;

NSDictionary *logsDict = [NSDictionary
dictionaryWithContentsOfURL:[NSURL fileURLWithPath:logFilePath()]
error:&err];

if (err.code == NSFileReadCorruptFileError){
[self clearLogs];
}
else if (err != nil){
self.logView.text = err.debugDescription;
return;
}
NSMutableArray<NSAttributedString*> *logs = [NSMutableArray new];
for(NSData *log in logsDict[@"logs"]){
[logs addObject:[[NSAttributedString alloc] initWithData:log
options:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType}
documentAttributes:nil
error:nil]];
}
NSMutableAttributedString *finalLog = [NSMutableAttributedString new];
static NSString * const newLineRaw = @"\n";
NSAttributedString * const newLineAttr = [[NSAttributedString alloc] initWithString:newLineRaw];
for (NSAttributedString *log in logs){
[finalLog appendAttributedString:log];
[finalLog appendAttributedString:newLineAttr];
}
self.logView.attributedText = finalLog;
}
else{
self.logView.text = @"No Log File Found";
}
}

- (void)clearLogs{
NSError *err;
[[NSFileManager defaultManager] removeItemAtPath:logFilePath() error:&err];
if(err){
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"An error happened while deleting log file"
message:err.description
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action = [UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
}
else{
[self loadLogs];
}
}
- (void)didTapMore:(id)sender{
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
message:nil
Expand All @@ -64,24 +110,7 @@ - (void)didTapMore:(id)sender{
UIAlertAction* clearAction = [UIAlertAction actionWithTitle:@"Clear Logs"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
dispatch_async(dispatch_get_main_queue(), ^{
if(self.manager.logFileExists){
NSError *err;
[[NSFileManager defaultManager] removeItemAtPath:self.manager.logFile error:&err];
if(err){
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"An error happened while deleting log file"
message:err.description
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* action = [UIAlertAction actionWithTitle:@"Dismiss"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alert addAction:action];
[self presentViewController:alert animated:YES completion:nil];
}
else{
[self loadLogs];
}
}});
dispatch_async(dispatch_get_main_queue(), ^{ [self clearLogs]; });
}
];

Expand Down
2 changes: 1 addition & 1 deletion Theos/Classes/JDEMapView.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Natheer on 08/07/2022.
//

#import <objc/objc-runtime.h>
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CLLocationManager.h>
Expand Down
12 changes: 11 additions & 1 deletion Theos/Classes/JDEMapView.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ - (void)viewDidLoad {
lpgr.minimumPressDuration = .5;
[_mapView addGestureRecognizer:lpgr];
//add pin at 0, 0
_pin = [MKPointAnnotation new];
NSString *lastCoords = [JDESettingsManager.sharedInstance spoofedLocation];
if(lastCoords != nil){
NSArray *coordsArray = [lastCoords componentsSeparatedByString:@";"];
CLLocationCoordinate2D coords = {
[coordsArray[0] doubleValue],
[coordsArray[1] doubleValue]};

self.pin = [[MKPointAnnotation alloc] initWithCoordinate:coords];
} else {
_pin = [MKPointAnnotation new];
}
[_mapView addAnnotation:_pin];

//Overlay Button
Expand Down
5 changes: 1 addition & 4 deletions Theos/Classes/JDESettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
#import <CoreLocation/CLLocationManager.h>
#import <UIKit/UIKit.h>
#import "../Headers/AppHaptic.h"
#import <objc/runtime.h>

@interface JDESettingsManager : NSObject
@property (strong, nonatomic) NSUserDefaults *tweakSettings;
@property (strong, nonatomic, readonly) NSString *logFile;
@property (nonatomic, readonly) BOOL logFileExists;


+ (JDESettingsManager *)sharedInstance;
- (NSDictionary*)cellInfoForPath:(NSIndexPath*)indexPath;
Expand All @@ -16,6 +14,5 @@
- (BOOL)featureStateForTag:(NSUInteger)row;
- (void)featureStateChangedTo:(BOOL)newState forTag:(NSUInteger)tag;
- (NSString*)localizedStringForKey:(NSString*)key;
- (void)logString:(NSString*)string;
@end

19 changes: 1 addition & 18 deletions Theos/Classes/JDESettingsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

@interface JDESettingsManager()
@property (strong, nonatomic) NSBundle *bundle;
@property (strong, nonatomic, readwrite) NSString *logFile;
@property (nonatomic, readwrite) BOOL logFileExists;
@end

@implementation JDESettingsManager
Expand All @@ -25,9 +23,7 @@ - (id) init{
_bundle = [NSBundle bundleWithPath:@"Library/Application Support/Jodel EMPROVED.bundle"];
}
//logFile stuff
NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
self.logFile = [docsDir stringByAppendingPathComponent:@"JDELogs.log"];
self.logFileExists = [[NSFileManager defaultManager] fileExistsAtPath:self.logFile];

}
return self;
}
Expand Down Expand Up @@ -136,18 +132,5 @@ - (NSString*)localizedStringForKey:(NSString*)key{ return [_bundle localizedStri
- (NSString*)pathForImageWithName:(NSString*)name{
return [_bundle pathForResource:name ofType:@"png" inDirectory:@"Icons"];
}
- (void)logString:(NSString*)string{
string = [[NSString stringWithFormat:@"[%@] ", [[NSDate now] description]] stringByAppendingString:string];
string = [string stringByAppendingString:@"\n"];
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:self.logFile];

if(fileHandle){
[fileHandle seekToEndOfFile];
[fileHandle writeData:[string dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandle closeFile];
}
else{
[string writeToFile:self.logFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
}
@end
10 changes: 0 additions & 10 deletions Theos/Classes/ThemingViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
@end


#define main "mainColor"
#define secondary "customLightGrayColor"
#define user "meColor"
#define userDot "channelNotification"
#define channel "channelColor"
#define channelDot "declineColor" // channel and notification Dots
#define notification "notificationColor"
#define pollCell "pollBgColor"


typedef NS_ENUM(NSUInteger, ThemeOption){
ThemeOptionMainColor,
ThemeOptionSecondaryColor,
Expand Down
1 change: 1 addition & 0 deletions Theos/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include $(THEOS)/makefiles/common.mk

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


Expand Down
Loading

1 comment on commit 086c6dd

@Abkdtrr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theos/Classes/JDEMapView.m

Please sign in to comment.