forked from Blendman974/faceclaw
iOS porting: Battery indicators, app icon, add the rest of the apps
This commit is contained in:
1 parent
00a5e38f75
commit
e5ba7abc18
31 files changed
+501
-65
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 1.3 MiB |
@@ -0,0 +1 @@
|
||||
{"images":[{"filename":"AppIcon.png","idiom":"universal","platform":"ios","size":"1024x1024"}],"info":{"author":"xcode","version":1}}
|
||||
@@ -0,0 +1 @@
|
||||
{"info":{"author":"xcode","version":1}}
|
||||
@@ -20,6 +20,8 @@
|
||||
<true/>
|
||||
<key>NSBluetoothAlwaysUsageDescription</key>
|
||||
<string>Faceclaw uses Bluetooth to connect to your glasses and ring, display your apps, and receive gestures.</string>
|
||||
<key>NSLocalNetworkUsageDescription</key>
|
||||
<string>Faceclaw connects to the terminal servers you configure on your local network.</string>
|
||||
<key>UILaunchScreen</key>
|
||||
<dict/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
@@ -30,5 +32,7 @@
|
||||
</array>
|
||||
<key>UIRequiresFullScreen</key>
|
||||
<true/>
|
||||
<key>UIFileSharingEnabled</key><true/>
|
||||
<key>LSSupportsOpeningDocumentsInPlace</key><true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -4,3 +4,5 @@ CODE_SIGN_STYLE = Automatic;
|
||||
|
||||
// Select the local signing team in Xcode or pass --teamId to the iOS scripts.
|
||||
OTHER_LDFLAGS = $(inherited) -framework CoreBluetooth
|
||||
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
@@ -0,0 +1,8 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
/** Thread-safe event queue; each NativeScript worker drains it on its own thread. */
|
||||
@interface FaceclawSocket : NSObject <NSURLSessionWebSocketDelegate>
|
||||
- (instancetype)initWithURL:(NSString *)url;
|
||||
- (NSString *)takeEvents;
|
||||
- (void)sendText:(NSString *)text;
|
||||
- (void)close;
|
||||
@end
|
||||
@@ -0,0 +1,75 @@
|
||||
#import "FaceclawSocket.h"
|
||||
@interface FaceclawSocket ()
|
||||
@property(nonatomic, strong) NSURLSession *session;
|
||||
@property(nonatomic, strong) NSURLSessionWebSocketTask *task;
|
||||
@property(nonatomic, strong) NSMutableArray *events;
|
||||
@property(nonatomic) BOOL ended;
|
||||
@property(nonatomic) NSUInteger queuedBytes;
|
||||
@end
|
||||
@implementation FaceclawSocket
|
||||
- (instancetype)initWithURL:(NSString *)url {
|
||||
if ((self = [super init])) {
|
||||
_events = [NSMutableArray array];
|
||||
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
|
||||
config.timeoutIntervalForRequest = 20;
|
||||
_session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
|
||||
_task = [_session webSocketTaskWithURL:[NSURL URLWithString:url]];
|
||||
_task.maximumMessageSize = 8 * 1024 * 1024;
|
||||
[_task resume];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (void)enqueue:(NSDictionary *)event {
|
||||
@synchronized(self) {
|
||||
if (_ended) return;
|
||||
_queuedBytes += [event[@"text"] lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
if (_events.count >= 256 || _queuedBytes > 16 * 1024 * 1024) {
|
||||
[_events removeAllObjects]; _queuedBytes = 0;
|
||||
[_events addObject:@{@"kind": @"error", @"text": @"Terminal input queue overflow"}];
|
||||
[self close];
|
||||
} else [_events addObject:event];
|
||||
}
|
||||
}
|
||||
- (NSString *)takeEvents {
|
||||
@synchronized(self) {
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:_events options:0 error:nil];
|
||||
[_events removeAllObjects]; _queuedBytes = 0;
|
||||
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] ?: @"[]";
|
||||
}
|
||||
}
|
||||
- (void)receiveNext {
|
||||
__weak FaceclawSocket *weakSelf = self;
|
||||
[_task receiveMessageWithCompletionHandler:^(NSURLSessionWebSocketMessage *message, NSError *error) {
|
||||
FaceclawSocket *owner = weakSelf; if (!owner) return;
|
||||
@synchronized(owner) { if (owner.ended) return; }
|
||||
if (error) { [owner enqueue:@{@"kind": @"error", @"text": error.localizedDescription}]; [owner close]; return; }
|
||||
if (message.type == NSURLSessionWebSocketMessageTypeString)
|
||||
[owner enqueue:@{@"kind": @"text", @"text": message.string}];
|
||||
[owner receiveNext];
|
||||
}];
|
||||
}
|
||||
- (void)URLSession:(NSURLSession *)session webSocketTask:(NSURLSessionWebSocketTask *)task didOpenWithProtocol:(NSString *)protocol {
|
||||
[self enqueue:@{@"kind": @"open"}]; [self receiveNext];
|
||||
}
|
||||
- (void)URLSession:(NSURLSession *)session webSocketTask:(NSURLSessionWebSocketTask *)task didCloseWithCode:(NSURLSessionWebSocketCloseCode)code reason:(NSData *)reason {
|
||||
[self enqueue:@{@"kind": @"closed", @"code": @(code), @"text": reason ? ([[NSString alloc] initWithData:reason encoding:NSUTF8StringEncoding] ?: @"") : @""}];
|
||||
[self close];
|
||||
}
|
||||
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {
|
||||
if (error) [self enqueue:@{@"kind": @"error", @"text": error.localizedDescription}];
|
||||
[self close];
|
||||
}
|
||||
- (void)sendText:(NSString *)text {
|
||||
__weak FaceclawSocket *weakSelf = self;
|
||||
[_task sendMessage:[[NSURLSessionWebSocketMessage alloc] initWithString:text] completionHandler:^(NSError *error) {
|
||||
if (error) { [weakSelf enqueue:@{@"kind": @"error", @"text": error.localizedDescription}]; [weakSelf close]; }
|
||||
}];
|
||||
}
|
||||
- (void)close {
|
||||
@synchronized(self) {
|
||||
if (_ended) return; _ended = YES;
|
||||
[_task cancelWithCloseCode:NSURLSessionWebSocketCloseCodeNormalClosure reason:nil];
|
||||
[_session invalidateAndCancel]; _session = nil;
|
||||
}
|
||||
}
|
||||
@end
|
||||
@@ -1,5 +1,6 @@
|
||||
module FaceclawGraphics {
|
||||
header "FaceclawGraphics.h"
|
||||
header "FaceclawBluetooth.h"
|
||||
header "FaceclawSocket.h"
|
||||
export *
|
||||
}
|
||||
Reference in new issue
Block a user