summaryrefslogtreecommitdiff
path: root/macosx
diff options
context:
space:
mode:
Diffstat (limited to 'macosx')
-rw-r--r--macosx/llmr-app.gyp2
-rw-r--r--macosx/main.mm47
2 files changed, 36 insertions, 13 deletions
diff --git a/macosx/llmr-app.gyp b/macosx/llmr-app.gyp
index 09c2029f60..069f5bb80f 100644
--- a/macosx/llmr-app.gyp
+++ b/macosx/llmr-app.gyp
@@ -41,7 +41,7 @@
'INFOPLIST_FILE': 'Info.plist',
'CLANG_CXX_LIBRARY': 'libc++',
'CLANG_CXX_LANGUAGE_STANDARD':'c++11',
- 'MACOSX_DEPLOYMENT_TARGET':'10.8',
+ 'MACOSX_DEPLOYMENT_TARGET':'10.9',
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
'CLANG_ENABLE_OBJC_ARC': 'YES'
},
diff --git a/macosx/main.mm b/macosx/main.mm
index 3f35b875b6..8e9ec099a2 100644
--- a/macosx/main.mm
+++ b/macosx/main.mm
@@ -3,6 +3,7 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#include <llmr/platform/platform.hpp>
+#include <llmr/map/tile.hpp>
#include "settings.hpp"
#include <cstdio>
@@ -238,29 +239,51 @@ void restart() {
[[NSApplication sharedApplication] postEvent: [NSEvent eventWithCGEvent:event] atStart:NO];
}
-void request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback) {
- NSMutableURLRequest *urlRequest = [NSMutableURLRequest
- requestWithURL:[NSURL
- URLWithString:@(url.c_str())]];
+class Request {
+public:
+ int16_t identifier;
+ std::string original_url;
+};
- [NSURLConnection
- sendAsynchronousRequest:urlRequest
- queue:[NSOperationQueue mainQueue]
- completionHandler: ^(NSURLResponse * response, NSData * data, NSError * error) {
+Request *request_http(std::string url, std::function<void(Response&)> background_function, std::function<void()> foreground_callback)
+{
+ NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@(url.c_str())] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
+ {
Response res;
- if (error == nil) {
- NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
- res.code = [httpResponse statusCode];
+
+ if ( ! error && [response isKindOfClass:[NSHTTPURLResponse class]])
+ {
+ res.code = [(NSHTTPURLResponse *)response statusCode];
res.body = { (const char *)[data bytes], [data length] };
}
background_function(res);
- dispatch_async(dispatch_get_main_queue(), ^(void) {
+
+ dispatch_async(dispatch_get_main_queue(), ^(void)
+ {
foreground_callback();
});
}];
+
+ [task resume];
+
+ Request *req = new Request();
+
+ req->identifier = task.taskIdentifier;
+ req->original_url = url;
+
+ return req;
}
+void cancel_request_http(Request *request)
+{
+ [[NSURLSession sharedSession] getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks)
+ {
+ for (NSURLSessionDownloadTask *task in downloadTasks)
+ if (task.taskIdentifier == request->identifier)
+ return [task cancel];
+ }];
+}
double time() {
return glfwGetTime();