Skip to content

Commit

Permalink
Added Swift-lint, and use NS lock for VPNState, Change in utils metho…
Browse files Browse the repository at this point in the history
…d in internal sdk.
  • Loading branch information
jigar-f committed Sep 28, 2023
1 parent d3a5a05 commit 3f1fe6d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 22 deletions.
27 changes: 11 additions & 16 deletions internalsdk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"math"
"reflect"

"github.com/getlantern/pathdb"
"github.com/getlantern/pathdb/minisql"
Expand Down Expand Up @@ -91,22 +90,18 @@ func putFromJson(jsonString string, db pathdb.DB) error {

// Convered value in type that supprt minisql values
func convertValueToSupportedTypes(rawValue interface{}) interface{} {
var convertedValue interface{}
//Convert all differnt type of single int
if rawValueType := reflect.TypeOf(rawValue); rawValueType.Kind() == reflect.Int64 {
// Convert the raw value to int
convertedValue = int(rawValue.(int64))
} else if rawValueType.Kind() == reflect.Int32 {
convertedValue = int(rawValue.(int32))
} else if rawValueType.Kind() == reflect.Int16 {
convertedValue = int(rawValue.(int16))
} else if rawValueType.Kind() == reflect.Int8 {
convertedValue = int(rawValue.(int8))
} else {
// The raw value is not of type int64, so do not convert it
convertedValue = rawValue
switch v := rawValue.(type) {
case int64:
return int(v)
case int32:
return int(v)
case int16:
return int(v)
case int8:
return int(v)
default:
return rawValue
}
return convertedValue
}

func BytesToFloat64LittleEndian(b []byte) (float64, error) {
Expand Down
40 changes: 40 additions & 0 deletions ios/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
disabled_rules:
- trailing_whitespace
- identifier_name
opt_in_rules:
- empty_count
- empty_string
included: # paths to include during linting. `--path` is ignored if present.
- Source
- Runner
excluded:
- Pods
- SwiftLint/Common/3rdPartyLib
line_length:
warning: 150
error: 200
ignores_function_declarations: true
ignores_comments: true
ignores_urls: true
# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
function_body_length:
warning: 300
error: 500
function_parameter_count:
warning: 6
error: 8
type_body_length:
warning: 300
error: 500
file_length:
warning: 1000
error: 1500
ignore_comment_only_lines: true
cyclomatic_complexity:
warning: 15
error: 25
reporter: "xcode"
20 changes: 19 additions & 1 deletion ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@
3F72706DAEB45E756D135F84 /* [CP] Embed Pods Frameworks */,
8CFC94838D10599DD335E9EC /* [CP] Copy Pods Resources */,
03A1AB3F2AA890AB00FB41B2 /* Embed Foundation Extensions */,
03ACAAB62AC5B7ED00D74DD4 /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -541,6 +542,23 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
03ACAAB62AC5B7ED00D74DD4 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if [[ \"$(uname -m)\" == arm64 ]]; then\n export PATH=\"/opt/homebrew/bin:$PATH\"\nfi\n\nif which swiftlint > /dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
Expand Down Expand Up @@ -665,7 +683,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build\n";
};
BE89F0204C2A5649490D586B /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
10 changes: 7 additions & 3 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ import Toast_Swift

//Flutter related stuff
private func initializeFlutterComponents() {


flutterViewController = window?.rootViewController as! FlutterViewController
flutterbinaryMessenger = flutterViewController.binaryMessenger
}
flutterbinaryMessenger = flutterViewController.binaryMessenger}


//Intlize this GO model and callback
// Intlize this GO model and callback
private func setupAppComponents() {
setupModels()
startUpSequency()
Expand Down Expand Up @@ -69,6 +70,8 @@ import Toast_Swift
}

func askNotificationPermssion() {


UserNotificationsManager.shared.requestNotificationPermission { granted in
if granted {
logger.debug("Notification Permssion is granted")
Expand All @@ -84,6 +87,7 @@ import Toast_Swift


private func setupLocal(){

let langStr = Locale.current.identifier
if langStr != nil{
sessionModel.setLocal(lang: langStr)
Expand Down
12 changes: 10 additions & 2 deletions ios/Runner/Lantern/Core/Vpn/VpnHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,28 @@ class VpnHelper: NSObject {
notificationCenter.post(name: VpnHelper.didUpdateStateNotification, object: nil)
}
}


private let stateLock = NSLock()
private var _state: VPNState
var state: VPNState {
get {
stateLock.lock()
defer { stateLock.unlock() }
if configuring {
return .configuring
}
return _state
}

set(newState) {
guard _state != newState else { return }
stateLock.lock()
guard _state != newState else {
stateLock.unlock()
return
}
_state = newState
notificationCenter.post(name: VpnHelper.didUpdateStateNotification, object: nil)
stateLock.unlock()
}
}

Expand Down

0 comments on commit 3f1fe6d

Please sign in to comment.