Skip to content

Commit

Permalink
Code refactoring and added some method in session mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Sep 12, 2023
1 parent 18c6b4d commit 3b62b0a
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 412 deletions.
15 changes: 15 additions & 0 deletions internalsdk/session_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ func (s *SessionModel) InvokeMethod(method string, arguments minisql.Values) (*m
} else {
return minisql.NewValueBool(true), nil
}
case "getBandwidth":
limit, err := getBandwidthLimit(s.baseModel)
if err != nil {
return nil, err
} else {
return minisql.NewValueString(limit), nil
}

case "setDeviceId":
deviceID := arguments.Get(0)
err := setDeviceId(s.baseModel, deviceID.String())
Expand Down Expand Up @@ -292,6 +300,7 @@ func (s *SessionModel) SetStaging(stageing bool) error {
}

func (s *SessionModel) BandwidthUpdate(percent int, remaining int, allowed int, ttlSeconds int) error {
log.Debugf("BandwidthUpdate percent %v remaining %v allowed %v", percent, remaining, allowed)
pathdb.Mutate(s.db, func(tx pathdb.TX) error {
pathdb.Put[int](tx, LATEST_BANDWIDTH, percent, "")
return nil
Expand All @@ -302,6 +311,12 @@ func (s *SessionModel) BandwidthUpdate(percent int, remaining int, allowed int,
return nil
}

func getBandwidthLimit(m *baseModel) (string, error) {
percent, err := m.db.Get(LATEST_BANDWIDTH)
panicIfNecessary(err)
return string(percent), nil
}

func (s *SessionModel) Locale() (string, error) {
// For now just send back english by default
// Once have machisim but to dyanmic
Expand Down
17 changes: 11 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
0308A1302AAEF3AA0086157A /* Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0308A12F2AAEF3AA0086157A /* Event.swift */; };
0308A1312AAEF3B00086157A /* Event.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0308A12F2AAEF3AA0086157A /* Event.swift */; };
0308A1342AAEF5130086157A /* VPNBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03A1AB152AA88BF200FB41B2 /* VPNBase.swift */; };
0308A1382AAEF89C0086157A /* FlashlightManager+AppSide.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0308A1372AAEF89C0086157A /* FlashlightManager+AppSide.swift */; };
0308A1392AAEF8DE0086157A /* FlashlightManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0321C3F82AA9D8DF00D462C1 /* FlashlightManager.swift */; };
0308A13D2AAF39F80086157A /* FlashlightManagerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0308A13C2AAF39F80086157A /* FlashlightManagerExtension.swift */; };
0308A13E2AAF43A10086157A /* UserNotificationsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0308A12B2AAEEE2C0086157A /* UserNotificationsManager.swift */; };
0321C3F72AA9D84700D462C1 /* Process.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0321C3F62AA9D84700D462C1 /* Process.swift */; };
0321C3F92AA9D8DF00D462C1 /* FlashlightManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0321C3F82AA9D8DF00D462C1 /* FlashlightManager.swift */; };
0321C3FB2AA9DC6E00D462C1 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 03A1AB312AA890AB00FB41B2 /* NetworkExtension.framework */; };
Expand Down Expand Up @@ -96,7 +97,7 @@
0308A12B2AAEEE2C0086157A /* UserNotificationsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserNotificationsManager.swift; sourceTree = "<group>"; };
0308A12D2AAEEF410086157A /* Events.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Events.swift; sourceTree = "<group>"; };
0308A12F2AAEF3AA0086157A /* Event.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Event.swift; sourceTree = "<group>"; };
0308A1372AAEF89C0086157A /* FlashlightManager+AppSide.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FlashlightManager+AppSide.swift"; sourceTree = "<group>"; };
0308A13C2AAF39F80086157A /* FlashlightManagerExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlashlightManagerExtension.swift; sourceTree = "<group>"; };
0321C3F62AA9D84700D462C1 /* Process.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Process.swift; sourceTree = "<group>"; };
0321C3F82AA9D8DF00D462C1 /* FlashlightManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FlashlightManager.swift; sourceTree = "<group>"; };
032A43572AA6F8AA00EF442B /* DnsDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DnsDetector.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -175,6 +176,7 @@
033CBDCC2A94D86300DEBCBA /* Db */ = {
isa = PBXGroup;
children = (
03026EA22A77D67A001D5507 /* ValueUtil.swift */,
03026EA02A77D654001D5507 /* Database.swift */,
03802FA22A98C9B000DACDFC /* SubscriberRequest.swift */,
);
Expand All @@ -184,6 +186,7 @@
03A1AB112AA88B8C00FB41B2 /* Core */ = {
isa = PBXGroup;
children = (
032A43562AA6F86A00EF442B /* Network */,
03A1AB402AA892F800FB41B2 /* Extension */,
03A1AB122AA88BB400FB41B2 /* Vpn */,
);
Expand All @@ -193,6 +196,7 @@
03A1AB122AA88BB400FB41B2 /* Vpn */ = {
isa = PBXGroup;
children = (
0308A13C2AAF39F80086157A /* FlashlightManagerExtension.swift */,
0308A1272AAEED7E0086157A /* VpnHelper.swift */,
0321C3F82AA9D8DF00D462C1 /* FlashlightManager.swift */,
03A1AB152AA88BF200FB41B2 /* VPNBase.swift */,
Expand Down Expand Up @@ -233,7 +237,6 @@
isa = PBXGroup;
children = (
03A1AB112AA88B8C00FB41B2 /* Core */,
032A43562AA6F86A00EF442B /* Network */,
033CBDCC2A94D86300DEBCBA /* Db */,
03F2FE322A6949C60082B34C /* Utils */,
03EE344A2A652B3D00E37100 /* Models */,
Expand All @@ -256,14 +259,12 @@
03F2FE322A6949C60082B34C /* Utils */ = {
isa = PBXGroup;
children = (
0308A1372AAEF89C0086157A /* FlashlightManager+AppSide.swift */,
0308A12F2AAEF3AA0086157A /* Event.swift */,
0308A12D2AAEEF410086157A /* Events.swift */,
0308A12B2AAEEE2C0086157A /* UserNotificationsManager.swift */,
0308A1292AAEEDD90086157A /* DataUsageMonitor.swift */,
0321C3F62AA9D84700D462C1 /* Process.swift */,
03F2FE332A6949EF0082B34C /* Logger.swift */,
03026EA22A77D67A001D5507 /* ValueUtil.swift */,
036663D82A9E0C0E00595971 /* JsonUtils.swift */,
03FAF1B12AA1C7940063580C /* RunningEnv.swift */,
03A1AB432AA8946400FB41B2 /* Constants.swift */,
Expand Down Expand Up @@ -552,6 +553,7 @@
buildActionMask = 2147483647;
files = (
03567DBE2AA9F31200A233EA /* Logger.swift in Sources */,
0308A13E2AAF43A10086157A /* UserNotificationsManager.swift in Sources */,
0308A1312AAEF3B00086157A /* Event.swift in Sources */,
03A1AB352AA890AB00FB41B2 /* PacketTunnelProvider.swift in Sources */,
03567DBB2AA9F15100A233EA /* Constants.swift in Sources */,
Expand Down Expand Up @@ -583,7 +585,7 @@
0308A1302AAEF3AA0086157A /* Event.swift in Sources */,
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */,
03A1AB142AA88BDA00FB41B2 /* VPNManager.swift in Sources */,
0308A1382AAEF89C0086157A /* FlashlightManager+AppSide.swift in Sources */,
0308A13D2AAF39F80086157A /* FlashlightManagerExtension.swift in Sources */,
03567DC02AA9F47200A233EA /* FileUtils.swift in Sources */,
03802FA32A98C9B000DACDFC /* SubscriberRequest.swift in Sources */,
0308A12A2AAEEDD90086157A /* DataUsageMonitor.swift in Sources */,
Expand Down Expand Up @@ -805,6 +807,7 @@
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Lantern;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -936,6 +939,7 @@
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Lantern;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -962,6 +966,7 @@
ENABLE_BITCODE = NO;
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Lantern;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
15 changes: 15 additions & 0 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Toast_Swift
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}


private func setupModels(){
logger.log("setupModels method called")
//Init Session Model
Expand All @@ -46,6 +47,20 @@ import Toast_Swift
vpnModel=VpnModel(flutterBinary: flutterbinaryMessenger,vpnBase: VPNManager.appDefault)
}

func startUpSequency() {
askNotificationPermssion()
}

func askNotificationPermssion() {
UserNotificationsManager.shared.requestNotificationPermission { granted in
if granted {
logger.debug("Notification Permssion is granted")
} else {
logger.debug("Notification Permssion is denied")
}
}
}


private func prepareChannel (){
logger.log("prepareChannel method called")
Expand Down
6 changes: 2 additions & 4 deletions ios/Runner/Lantern/Core/Vpn/FlashlightManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Internalsdk
import UIKit


// Any and all interaction with Go will run through FlashlightManager.
// See FlashlightManager+AppSide.swift for app-specific functionality.

class FlashlightManager {
static let `appDefault` = FlashlightManager(constants: .appDefault)
static let `netExDefault` = FlashlightManager(constants: .netExDefault)
Expand All @@ -31,8 +30,7 @@ class FlashlightManager {
var hasCheckedForUpdate = false

// MARK: Go Logging

func configureGoLoggerReturningError() -> Error? {
func configureGoLoggerReturningError() -> Error? {
var error: NSError?
IosConfigureFileLogging(constants.goLogBaseURL.path, constants.targetDirectoryURL.path, &error)
return error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import Foundation
import UIKit
import Internalsdk

// TODO: add interface for mockability
extension FlashlightManager {

extension FlashlightManager {
// MARK: Config

func fetchConfig(userID: Int, proToken: String?, excludedIPsURL: URL? = nil, refreshProxies: Bool, _ completion: ((Result<Bool, Error>) -> Void)? = nil) {
func fetchConfig(userID: Int, proToken: String?, excludedIPsURL: URL? = nil, refreshProxies: Bool, _ completion: ((Result<Bool, Error>) -> Void)? = nil) {
var configError: NSError?
let configDirectory = constants.configDirectoryURL.path
let deviceID = UIDevice.current.identifierForVendor!.uuidString
Expand Down Expand Up @@ -45,5 +43,4 @@ extension FlashlightManager {
// TODO: investigate: does this have to happen on goQueue?
queue.async(execute: workItem)
}

}
Loading

0 comments on commit 3b62b0a

Please sign in to comment.