Changes implemented
Signed-off-by: Kartikay <kartikay_2101ce32@iitp.ac.in>
This commit is contained in:
parent
2c3e04f1fe
commit
85341b84bc
4 changed files with 41 additions and 26 deletions
|
@ -1,8 +1,8 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ClipboardWatcher : NSObject
|
||||
@interface ClipboardChecker : NSObject
|
||||
|
||||
- (void)startWatching:(UIWindow *)window;
|
||||
- (void)startChecking:(UIWindow *)window;
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#import "UIKitCategories.h"
|
||||
#import <CoreApi/DeepLinkSearchData.h>
|
||||
|
||||
@interface ClipboardWatcher ()
|
||||
@interface ClipboardChecker ()
|
||||
|
||||
@property (nonatomic, strong) NSTimer *timer;
|
||||
@property (nonatomic, copy) NSString *previousClipboardText;
|
||||
|
@ -16,49 +16,57 @@
|
|||
|
||||
@end
|
||||
|
||||
@implementation ClipboardWatcher
|
||||
|
||||
- (void)startWatching:(UIWindow *)window {
|
||||
NSLog(@"clip watching started");
|
||||
@implementation ClipboardChecker
|
||||
|
||||
NSString *privacyProxy = @"https://url-un.kartikay-2101ce32.workers.dev/coordinates?url=%@";
|
||||
NSString *localizedStringOk = NSLocalizedString(@"ok", @"");
|
||||
- (void)startChecking:(UIWindow *)window {
|
||||
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
|
||||
NSString *currentClipboardText = pasteboard.string;
|
||||
NSLog(@"clip clipboard checking for changes %@ and %@",currentClipboardText, self.previousClipboardText);
|
||||
|
||||
[pasteboard setString:@""];
|
||||
|
||||
NSLog(@"Local String%@", localizedStringOk);
|
||||
[self checkClipboardWithText:currentClipboardText window:window];
|
||||
}
|
||||
|
||||
- (void)checkClipboardWithText:(NSString *)copiedText window:(UIWindow *)window {
|
||||
NSLog(@"clip API CALL PROCEEDING %@", copiedText);
|
||||
NSLog(@"PROXY REQUEST PROCEEDING %@", copiedText);
|
||||
|
||||
// Check if the copied text is a URL
|
||||
if ([self isURL:copiedText]) {
|
||||
|
||||
NSURL* url = [NSURL URLWithString:copiedText];
|
||||
NSString* hostName = url.host;
|
||||
if ([self isURL:copiedText] && ( [hostName isEqualToString:@"google"] || [hostName isEqualToString:@"www.google.com"] ||
|
||||
[hostName isEqualToString:@"maps.app.goo.gl"] ||
|
||||
[hostName isEqualToString:@"goo.gl"])) {
|
||||
NSLog(privacyProxy,copiedText);
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Redirecting from copied URL" message:@"Please wait..." preferredStyle:UIAlertControllerStyleAlert];
|
||||
NSString *message = [NSString stringWithFormat:@"Extracting coordinates from %@ using the anonymous proxy...", copiedText];
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Please Wait" message:message preferredStyle:UIAlertControllerStyleAlert];
|
||||
[window.rootViewController presentViewController:alertController animated:YES completion:nil];
|
||||
});
|
||||
|
||||
// Make an API request
|
||||
NSURL *apiURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://url-un.kartikay-2101ce32.workers.dev/search?url=%@", copiedText]];
|
||||
NSURL *apiURL = [NSURL URLWithString:[NSString stringWithFormat:privacyProxy, copiedText]];
|
||||
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:apiURL completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[window.rootViewController dismissViewControllerAnimated:YES completion:nil];
|
||||
});
|
||||
|
||||
if (error) {
|
||||
NSLog(@"API Request Error: %@", error);
|
||||
NSString *errorMessage = @"Kindly make sure that your internet connection in turned on.";
|
||||
NSLog(@"Proxy request error: %@", error);
|
||||
NSString *errorMessage = @"Failed to extract coordinates from %url using an anonymous proxy. Please check your Internet connection";
|
||||
errorMessage = [errorMessage stringByReplacingOccurrencesOfString:@"%url" withString:copiedText];
|
||||
[self displayErrorMessage:errorMessage inWindow:window];
|
||||
} else {
|
||||
NSError *jsonError;
|
||||
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
NSLog(@"API Response: %@", responseString);
|
||||
NSLog(@"Proxy response:%@", responseString);
|
||||
NSDictionary *responseDict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonError];
|
||||
if (jsonError) {
|
||||
NSLog(@"JSON Parsing Error: %@", jsonError);
|
||||
NSString *errorMessage = @"Kindly make sure that your URL points to an address";
|
||||
NSString *errorMessage = @"Can not extract coordinates from %url";
|
||||
errorMessage = [errorMessage stringByReplacingOccurrencesOfString:@"%url" withString:copiedText];
|
||||
[self displayErrorMessage:errorMessage inWindow:window];
|
||||
} else {
|
||||
NSDictionary *urlDict = responseDict[@"url"];
|
||||
|
@ -94,8 +102,9 @@
|
|||
self.isErrorPromptShown = YES;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Redirection Failed" message:errorMessage preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||||
NSString *title = @"Redirection Failed";
|
||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:errorMessage preferredStyle:UIAlertControllerStyleAlert];
|
||||
UIAlertAction *okAction = [UIAlertAction actionWithTitle:localizedStringOk style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
||||
self.isErrorPromptShown = NO;
|
||||
}];
|
||||
[alertController addAction:okAction];
|
||||
|
|
|
@ -69,7 +69,7 @@ using namespace osm_auth_ios;
|
|||
|
||||
@property(nonatomic) NSInteger standbyCounter;
|
||||
@property(nonatomic) MWMBackgroundFetchScheduler *backgroundFetchScheduler;
|
||||
@property (nonatomic, strong) ClipboardWatcher *clipboardWatcher;
|
||||
@property (nonatomic, strong) ClipboardChecker *clipboardChecker;
|
||||
|
||||
@end
|
||||
|
||||
|
@ -226,18 +226,18 @@ using namespace osm_auth_ios;
|
|||
f.OnRecoverSurface(static_cast<int>(objcSize.width), static_cast<int>(objcSize.height),
|
||||
true /* recreateContextDependentResources */);
|
||||
}
|
||||
[self startWatchingClipboard];
|
||||
[self startCheckingClipboard];
|
||||
[MWMLocationManager applicationDidBecomeActive];
|
||||
[MWMSearch addCategoriesToSpotlight];
|
||||
[MWMKeyboard applicationDidBecomeActive];
|
||||
[MWMTextToSpeech applicationDidBecomeActive];
|
||||
LOG(LINFO, ("applicationDidBecomeActive - end"));
|
||||
}
|
||||
- (void)startWatchingClipboard {
|
||||
- (void)startCheckingClipboard {
|
||||
NSLog(@"Watching started");
|
||||
ClipboardWatcher *clipboardWatcher = [[ClipboardWatcher alloc] init];
|
||||
ClipboardChecker *clipboardChecker = [[ClipboardChecker alloc] init];
|
||||
UIWindow *targetWindow = [UIApplication sharedApplication].keyWindow;
|
||||
[clipboardWatcher startWatching:targetWindow];
|
||||
[clipboardChecker startChecking:targetWindow];
|
||||
}
|
||||
|
||||
- (BOOL)application:(UIApplication *)application
|
||||
|
|
|
@ -324,6 +324,7 @@
|
|||
6B15907226623AE500944BBA /* 00_NotoSansThai-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 6B15907026623AE500944BBA /* 00_NotoSansThai-Regular.ttf */; };
|
||||
6B679E89266BFD0A0074AE2A /* 00_NotoNaskhArabic-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 6B679E88266BFD090074AE2A /* 00_NotoNaskhArabic-Regular.ttf */; };
|
||||
6B9978361C89A316003B8AA0 /* editor.config in Resources */ = {isa = PBXBuildFile; fileRef = 6B9978341C89A316003B8AA0 /* editor.config */; };
|
||||
8FE7398F2A4208CC00DC5837 /* ClipboardMonitor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8FE7398E2A4208CC00DC5837 /* ClipboardMonitor.mm */; };
|
||||
99012847243F0D6900C72B10 /* UIViewController+alternative.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99012846243F0D6900C72B10 /* UIViewController+alternative.swift */; };
|
||||
9901284F244732DB00C72B10 /* BottomTabBarPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 99012849244732DB00C72B10 /* BottomTabBarPresenter.swift */; };
|
||||
99012851244732DB00C72B10 /* BottomTabBarViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9901284B244732DB00C72B10 /* BottomTabBarViewController.swift */; };
|
||||
|
@ -764,7 +765,6 @@
|
|||
3444DFCF1F17620C00E73099 /* MWMMapWidgetsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMapWidgetsHelper.h; sourceTree = "<group>"; };
|
||||
3444DFD01F17620C00E73099 /* MWMMapWidgetsHelper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMapWidgetsHelper.mm; sourceTree = "<group>"; };
|
||||
3444DFDC1F18A5AF00E73099 /* SideButtonsArea.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SideButtonsArea.swift; sourceTree = "<group>"; };
|
||||
345050211E028B8000A8DC59 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
3454D79B1E07F045004AF2AD /* CLLocation+Mercator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "CLLocation+Mercator.h"; sourceTree = "<group>"; };
|
||||
3454D79C1E07F045004AF2AD /* CLLocation+Mercator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "CLLocation+Mercator.mm"; sourceTree = "<group>"; };
|
||||
3454D79D1E07F045004AF2AD /* DateComponentsFormatter+ETA.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DateComponentsFormatter+ETA.swift"; sourceTree = "<group>"; };
|
||||
|
@ -1135,6 +1135,9 @@
|
|||
6B679E88266BFD090074AE2A /* 00_NotoNaskhArabic-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "00_NotoNaskhArabic-Regular.ttf"; path = "../../data/00_NotoNaskhArabic-Regular.ttf"; sourceTree = "<group>"; };
|
||||
6B9978341C89A316003B8AA0 /* editor.config */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = editor.config; path = ../../data/editor.config; sourceTree = "<group>"; };
|
||||
8D1107310486CEB800E47090 /* OMaps.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = OMaps.plist; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
|
||||
8F71F2442A46035800089B33 /* Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Bridging-Header.h"; path = "../../../../../.Trash/Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
8FE7398D2A4208A100DC5837 /* ClipboardMonitor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ClipboardMonitor.h; sourceTree = "<group>"; };
|
||||
8FE7398E2A4208CC00DC5837 /* ClipboardMonitor.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ClipboardMonitor.mm; sourceTree = "<group>"; };
|
||||
978D4A30199A11E600D72CA7 /* faq.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = faq.html; path = ../../data/faq.html; sourceTree = "<group>"; };
|
||||
97A5967E19B9CD47007A963F /* copyright.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = copyright.html; path = ../../data/copyright.html; sourceTree = "<group>"; };
|
||||
99012846243F0D6900C72B10 /* UIViewController+alternative.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+alternative.swift"; sourceTree = "<group>"; };
|
||||
|
@ -1703,6 +1706,8 @@
|
|||
34FE4C421BCC013500066718 /* Widgets */,
|
||||
FA8E808825F412E2002A1434 /* FirstSession.mm */,
|
||||
FA8E808A25F41337002A1434 /* FirstSession.h */,
|
||||
8FE7398D2A4208A100DC5837 /* ClipboardMonitor.h */,
|
||||
8FE7398E2A4208CC00DC5837 /* ClipboardMonitor.mm */,
|
||||
);
|
||||
path = Classes;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1724,6 +1729,7 @@
|
|||
080E96DDFE201D6D7F000001 /* Classes */,
|
||||
340475141E081A4600C92850 /* Common */,
|
||||
347526FA1DC0B00F00918CF5 /* common-debug.xcconfig */,
|
||||
8F71F2442A46035800089B33 /* Bridging-Header.h */,
|
||||
347526FB1DC0B00F00918CF5 /* common-release.xcconfig */,
|
||||
340475281E081A4600C92850 /* Core */,
|
||||
FA065FC61286143F00FEA989 /* External Resources */,
|
||||
|
@ -1744,7 +1750,6 @@
|
|||
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
345050211E028B8000A8DC59 /* Bridging-Header.h */,
|
||||
29B97316FDCFA39411CA2CEA /* main.mm */,
|
||||
28A0AB4B0D9B1048005BE974 /* Maps_Prefix.pch */,
|
||||
);
|
||||
|
@ -3876,6 +3881,7 @@
|
|||
34AB666E1FC5AA330078E451 /* TransportTransitStepsCollectionView.swift in Sources */,
|
||||
993DF11E23F6BDB100AC231A /* UITextViewRenderer.swift in Sources */,
|
||||
F6E2FF5A1E097BA00083EBEC /* MWMNightModeController.m in Sources */,
|
||||
8FE7398F2A4208CC00DC5837 /* ClipboardMonitor.mm in Sources */,
|
||||
471A7BB8247FE3C300A0D4C1 /* URL+Query.swift in Sources */,
|
||||
47F86D0120C93D8D00FEE291 /* TabViewController.swift in Sources */,
|
||||
99536113235DB86C008B218F /* InsetsLabel.swift in Sources */,
|
||||
|
|
Reference in a new issue