diff options
Diffstat (limited to 'Drop Serve')
| -rw-r--r-- | Drop Serve/AppDelegate.m | 7 | ||||
| -rw-r--r-- | Drop Serve/DropZone.m | 9 | ||||
| -rw-r--r-- | Drop Serve/Server.h | 18 | ||||
| -rw-r--r-- | Drop Serve/Server.m | 33 |
4 files changed, 64 insertions, 3 deletions
diff --git a/Drop Serve/AppDelegate.m b/Drop Serve/AppDelegate.m index f92f421..4a72685 100644 --- a/Drop Serve/AppDelegate.m +++ b/Drop Serve/AppDelegate.m @@ -8,6 +8,8 @@ #import "AppDelegate.h" +#import "Server.h" + @implementation AppDelegate - (void)dealloc @@ -19,4 +21,9 @@ { } +- (void)applicationWillTerminate:(NSNotification *)notification +{ + [Server stop]; +} + @end diff --git a/Drop Serve/DropZone.m b/Drop Serve/DropZone.m index 79c1fe6..56efb08 100644 --- a/Drop Serve/DropZone.m +++ b/Drop Serve/DropZone.m @@ -7,6 +7,7 @@ // #import "DropZone.h" +#import "Server.h" @implementation DropZone @@ -61,13 +62,15 @@ return NO; } - NSURL *path = [NSURL fileURLWithPath:file isDirectory:isDirectory]; + NSURL *url = [NSURL fileURLWithPath:file isDirectory:isDirectory]; if (!isDirectory) { - path = [path URLByDeletingLastPathComponent]; + url = [url URLByDeletingLastPathComponent]; } - NSLog(@"%@", path); + NSLog(@"%@", url); + + [Server serveAtPath:[url path]]; } return YES; diff --git a/Drop Serve/Server.h b/Drop Serve/Server.h new file mode 100644 index 0000000..a19908f --- /dev/null +++ b/Drop Serve/Server.h @@ -0,0 +1,18 @@ +// +// Server.h +// Drop Serve +// +// Created by TW on 10/10/20. +// Copyright (c) 2020 TW. All rights reserved. +// + +#import <Foundation/Foundation.h> + +NSTask *_process; + +@interface Server : NSObject + ++ (void)serveAtPath:(NSString *)path; ++ (void)stop; + +@end diff --git a/Drop Serve/Server.m b/Drop Serve/Server.m new file mode 100644 index 0000000..c584f3c --- /dev/null +++ b/Drop Serve/Server.m @@ -0,0 +1,33 @@ +// +// Server.m +// Drop Serve +// +// Created by TW on 10/10/20. +// Copyright (c) 2020 TW. All rights reserved. +// + +#import "Server.h" + +@implementation Server + ++ (void)serveAtPath:(NSString *)path +{ + _process = [[NSTask alloc] init]; + [_process setCurrentDirectoryPath:path]; + [_process setLaunchPath:@"/usr/bin/python"]; + [_process setArguments:[NSArray arrayWithObjects: + @"-m", + @"SimpleHTTPServer", + nil]]; + + NSLog(@"%@", _process); + + [_process launch]; +} + ++ (void)stop +{ + [_process interrupt]; +} + +@end |
