chore: format

This commit is contained in:
Nathan Walker
2020-07-05 14:57:06 -07:00
parent 8f2900ad0b
commit da3c0b973d
379 changed files with 71587 additions and 54582 deletions

View File

@@ -16,16 +16,18 @@ const vpn = "vpn";
// Get Connection Type
function getConnectivityManager(): android.net.ConnectivityManager {
return getNativeApplication().getApplicationContext().getSystemService(android.content.Context.CONNECTIVITY_SERVICE);
return getNativeApplication()
.getApplicationContext()
.getSystemService(android.content.Context.CONNECTIVITY_SERVICE);
}
function getActiveNetworkInfo(): android.net.NetworkInfo {
let connectivityManager = getConnectivityManager();
if (!connectivityManager) {
return null;
}
let connectivityManager = getConnectivityManager();
if (!connectivityManager) {
return null;
}
return connectivityManager.getActiveNetworkInfo();
return connectivityManager.getActiveNetworkInfo();
}
function getNetworkCapabilities() {

View File

@@ -9,25 +9,25 @@ export function getConnectionType(): number;
* Defines the different connection types.
*/
export enum connectionType {
/**
* Denotes no connection.
*/
none = 0,
/**
* Denotes no connection.
*/
none = 0,
/**
* Denotes a WiFi connection.
*/
wifi = 1,
/**
* Denotes a WiFi connection.
*/
wifi = 1,
/**
* Denotes a mobile connection, i.e. cellular network or WAN.
*/
mobile = 2,
/**
* Denotes a mobile connection, i.e. cellular network or WAN.
*/
mobile = 2,
/**
* Denotes an ethernet connection
*/
ethernet = 3,
/**
* Denotes an ethernet connection
*/
ethernet = 3,
/**
* Denotes a bluetooth connection
@@ -44,7 +44,9 @@ export enum connectionType {
* Starts monitoring the connection type.
* @param connectionTypeChangedCallback A function that will be called when the connection type changes.
*/
export function startMonitoring(connectionTypeChangedCallback: (newConnectionType: number) => void): void;
export function startMonitoring(
connectionTypeChangedCallback: (newConnectionType: number) => void
): void;
/**
* Stops monitoring the connection type.

View File

@@ -10,33 +10,33 @@ export enum connectionType {
// Get Connection Type
declare const sockaddr;
function _createReachability(host?: string): any {
if (host) {
return SCNetworkReachabilityCreateWithName(null, host);
} else {
const zeroAddress = new interop.Reference<sockaddr>(sockaddr, {
sa_len: 16,
sa_family: 2
});
if (host) {
return SCNetworkReachabilityCreateWithName(null, host);
} else {
const zeroAddress = new interop.Reference<sockaddr>(sockaddr, {
sa_len: 16,
sa_family: 2,
});
return SCNetworkReachabilityCreateWithAddress(null, zeroAddress);
}
return SCNetworkReachabilityCreateWithAddress(null, zeroAddress);
}
}
function _getReachabilityFlags(host?: string): number {
const reachability = _createReachability(host);
const flagsRef = new interop.Reference<number>();
const gotFlags = SCNetworkReachabilityGetFlags(reachability, flagsRef);
if (!gotFlags) {
return null;
}
const reachability = _createReachability(host);
const flagsRef = new interop.Reference<number>();
const gotFlags = SCNetworkReachabilityGetFlags(reachability, flagsRef);
if (!gotFlags) {
return null;
}
return flagsRef.value;
return flagsRef.value;
}
function _getConnectionType(host?: string): number {
const flags = _getReachabilityFlags(host);
const flags = _getReachabilityFlags(host);
return _getConnectionTypeFromFlags(flags);
return _getConnectionTypeFromFlags(flags);
}
function _getConnectionTypeFromFlags(flags: number): number {
@@ -121,7 +121,7 @@ function isVPNConnected(keys) {
}
export function getConnectionType(): number {
return _getConnectionType();
return _getConnectionType();
}
// Start/Stop Monitoring
@@ -133,25 +133,43 @@ function _reachabilityCallback(target: any, flags: number, info: any) {
}
const _reachabilityCallbackFunctionRef = new interop.FunctionReference(_reachabilityCallback);
const _reachabilityCallbackFunctionRef = new interop.FunctionReference(
_reachabilityCallback
);
let _monitorReachabilityRef: any;
let _connectionTypeChangedCallback: (newConnectionType: number) => void;
export function startMonitoring(connectionTypeChangedCallback: (newConnectionType: number) => void): void {
if (!_monitorReachabilityRef) {
_monitorReachabilityRef = _createReachability();
_connectionTypeChangedCallback = <any>zonedCallback(connectionTypeChangedCallback);
SCNetworkReachabilitySetCallback(_monitorReachabilityRef, _reachabilityCallbackFunctionRef, null);
SCNetworkReachabilityScheduleWithRunLoop(_monitorReachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
_connectionTypeChangedCallback(_getConnectionType());
}
export function startMonitoring(
connectionTypeChangedCallback: (newConnectionType: number) => void
): void {
if (!_monitorReachabilityRef) {
_monitorReachabilityRef = _createReachability();
_connectionTypeChangedCallback = <any>(
zonedCallback(connectionTypeChangedCallback)
);
SCNetworkReachabilitySetCallback(
_monitorReachabilityRef,
_reachabilityCallbackFunctionRef,
null
);
SCNetworkReachabilityScheduleWithRunLoop(
_monitorReachabilityRef,
CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode
);
_connectionTypeChangedCallback(_getConnectionType());
}
}
export function stopMonitoring(): void {
if (_monitorReachabilityRef) {
SCNetworkReachabilityUnscheduleFromRunLoop(_monitorReachabilityRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
_monitorReachabilityRef = undefined;
_connectionTypeChangedCallback = undefined;
}
if (_monitorReachabilityRef) {
SCNetworkReachabilityUnscheduleFromRunLoop(
_monitorReachabilityRef,
CFRunLoopGetCurrent(),
kCFRunLoopDefaultMode
);
_monitorReachabilityRef = undefined;
_connectionTypeChangedCallback = undefined;
}
}