diff --git a/internalsdk/utils.go b/internalsdk/utils.go index 63a15f356..7032127f5 100644 --- a/internalsdk/utils.go +++ b/internalsdk/utils.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "math" - "reflect" "github.com/getlantern/pathdb" "github.com/getlantern/pathdb/minisql" @@ -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) { diff --git a/ios/.swiftlint.yml b/ios/.swiftlint.yml new file mode 100644 index 000000000..056efef3e --- /dev/null +++ b/ios/.swiftlint.yml @@ -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" diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index b04410ed9..461859323 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -434,6 +434,7 @@ 3F72706DAEB45E756D135F84 /* [CP] Embed Pods Frameworks */, 8CFC94838D10599DD335E9EC /* [CP] Copy Pods Resources */, 03A1AB3F2AA890AB00FB41B2 /* Embed Foundation Extensions */, + 03ACAAB62AC5B7ED00D74DD4 /* ShellScript */, ); buildRules = ( ); @@ -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; @@ -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; diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 8854ce87f..5b04bc70e 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -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() @@ -69,6 +70,8 @@ import Toast_Swift } func askNotificationPermssion() { + + UserNotificationsManager.shared.requestNotificationPermission { granted in if granted { logger.debug("Notification Permssion is granted") @@ -84,6 +87,7 @@ import Toast_Swift private func setupLocal(){ + let langStr = Locale.current.identifier if langStr != nil{ sessionModel.setLocal(lang: langStr) diff --git a/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift b/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift index 7854aa574..22b643b7b 100644 --- a/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift +++ b/ios/Runner/Lantern/Core/Vpn/VpnHelper.swift @@ -35,10 +35,13 @@ 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 } @@ -46,9 +49,14 @@ class VpnHelper: NSObject { } 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() } }