mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
124 lines
3.9 KiB
Matlab
124 lines
3.9 KiB
Matlab
11 years ago
|
//
|
||
7 years ago
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
11 years ago
|
//
|
||
|
|
||
|
#import "SignalsNavigationController.h"
|
||
6 years ago
|
#import "Session-Swift.h"
|
||
5 years ago
|
#import <SignalUtilitiesKit/UIUtil.h>
|
||
|
#import <SignalUtilitiesKit/NSTimer+OWS.h>
|
||
|
#import <SignalUtilitiesKit/OWSSignalService.h>
|
||
|
#import <SignalUtilitiesKit/TSSocketManager.h>
|
||
8 years ago
|
|
||
|
static double const STALLED_PROGRESS = 0.9;
|
||
11 years ago
|
|
||
11 years ago
|
@interface SignalsNavigationController ()
|
||
|
|
||
8 years ago
|
@property (nonatomic) UIProgressView *socketStatusView;
|
||
|
@property (nonatomic) NSTimer *updateStatusTimer;
|
||
|
|
||
11 years ago
|
@end
|
||
|
|
||
8 years ago
|
#pragma mark -
|
||
11 years ago
|
|
||
8 years ago
|
@implementation SignalsNavigationController
|
||
10 years ago
|
|
||
11 years ago
|
- (void)viewDidLoad {
|
||
|
[super viewDidLoad];
|
||
7 years ago
|
|
||
11 years ago
|
// Do any additional setup after loading the view.
|
||
|
[self initializeObserver];
|
||
8 years ago
|
[self updateSocketStatusView];
|
||
11 years ago
|
}
|
||
|
|
||
10 years ago
|
- (void)initializeSocketStatusBar {
|
||
10 years ago
|
if (!_socketStatusView) {
|
||
10 years ago
|
_socketStatusView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
CGRect bar = self.navigationBar.frame;
|
||
|
_socketStatusView.frame = CGRectMake(0, bar.size.height - 1.0f, self.view.frame.size.width, 1.0f);
|
||
|
_socketStatusView.progress = 0.0f;
|
||
10 years ago
|
_socketStatusView.progressTintColor = [UIColor ows_fadedBlueColor];
|
||
10 years ago
|
|
||
6 years ago
|
/** Loki: Original code
|
||
10 years ago
|
if (![_socketStatusView superview]) {
|
||
|
[self.navigationBar addSubview:_socketStatusView];
|
||
|
}
|
||
6 years ago
|
*/
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
- (void)dealloc
|
||
|
{
|
||
10 years ago
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
#pragma mark - Socket Status Notifications
|
||
|
|
||
10 years ago
|
- (void)initializeObserver {
|
||
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||
7 years ago
|
selector:@selector(OWSWebSocketStateDidChange)
|
||
|
name:kNSNotification_OWSWebSocketStateDidChange
|
||
10 years ago
|
object:nil];
|
||
8 years ago
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||
|
selector:@selector(isCensorshipCircumventionActiveDidChange:)
|
||
|
name:kNSNotificationName_IsCensorshipCircumventionActiveDidChange
|
||
|
object:nil];
|
||
|
}
|
||
|
|
||
|
- (void)isCensorshipCircumventionActiveDidChange:(NSNotification *)notification
|
||
|
{
|
||
7 years ago
|
OWSAssertIsOnMainThread();
|
||
8 years ago
|
|
||
|
[self updateSocketStatusView];
|
||
11 years ago
|
}
|
||
|
|
||
7 years ago
|
- (void)OWSWebSocketStateDidChange
|
||
|
{
|
||
7 years ago
|
OWSAssertIsOnMainThread();
|
||
|
|
||
8 years ago
|
[self updateSocketStatusView];
|
||
11 years ago
|
}
|
||
|
|
||
8 years ago
|
- (void)updateSocketStatusView {
|
||
7 years ago
|
OWSAssertIsOnMainThread();
|
||
8 years ago
|
|
||
|
if ([OWSSignalService sharedInstance].isCensorshipCircumventionActive) {
|
||
|
[_updateStatusTimer invalidate];
|
||
|
[_socketStatusView removeFromSuperview];
|
||
|
_socketStatusView = nil;
|
||
|
return;
|
||
|
}
|
||
|
|
||
7 years ago
|
switch (TSSocketManager.shared.highestSocketState) {
|
||
|
case OWSWebSocketStateClosed:
|
||
8 years ago
|
if (_socketStatusView == nil) {
|
||
|
[self initializeSocketStatusBar];
|
||
8 years ago
|
[_updateStatusTimer invalidate];
|
||
|
_updateStatusTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.5
|
||
|
target:self
|
||
|
selector:@selector(updateProgress)
|
||
|
userInfo:nil
|
||
|
repeats:YES];
|
||
|
|
||
8 years ago
|
} else if (_socketStatusView.progress >= STALLED_PROGRESS) {
|
||
|
[_updateStatusTimer invalidate];
|
||
|
}
|
||
|
break;
|
||
7 years ago
|
case OWSWebSocketStateConnecting:
|
||
8 years ago
|
// Do nothing.
|
||
|
break;
|
||
7 years ago
|
case OWSWebSocketStateOpen:
|
||
9 years ago
|
[_updateStatusTimer invalidate];
|
||
8 years ago
|
[_socketStatusView removeFromSuperview];
|
||
|
_socketStatusView = nil;
|
||
8 years ago
|
break;
|
||
|
}
|
||
10 years ago
|
}
|
||
|
|
||
8 years ago
|
- (void)updateProgress {
|
||
|
double progress = _socketStatusView.progress + 0.05;
|
||
|
_socketStatusView.progress = (float) MIN(progress, STALLED_PROGRESS);
|
||
11 years ago
|
}
|
||
|
|
||
|
@end
|