Skip to content

Commit

Permalink
Moved some operation on BG thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jigar-f committed Nov 9, 2023
1 parent 5b44a04 commit 22d73a1
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 55 deletions.
21 changes: 16 additions & 5 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import UIKit
// Model Properties
var sessionModel: SessionModel!
var lanternModel: LanternModel!
var navigationModel: NavigationModel!
// var navigationModel: NavigationModel!
var vpnModel: VpnModel!
var messagingModel: MessagingModel!
// IOS
Expand Down Expand Up @@ -45,9 +45,20 @@ import UIKit

// Intlize this GO model and callback
private func setupAppComponents() throws {
try setupModels()
startUpSequency()
setupLoadingBar()
DispatchQueue.global(qos: .userInitiated).async {
do {
try self.setupModels()
DispatchQueue.main.async {
self.startUpSequency()
self.setupLoadingBar()
}
} catch {
DispatchQueue.main.async {
logger.error("Unexpected error setting up models: \(error)")
}
}
}

}

// Init all the models
Expand All @@ -56,7 +67,7 @@ import UIKit
sessionModel = try SessionModel(flutterBinary: flutterbinaryMessenger)
lanternModel = LanternModel(flutterBinary: flutterbinaryMessenger)
vpnModel = try VpnModel(flutterBinary: flutterbinaryMessenger, vpnBase: VPNManager.appDefault)
navigationModel = NavigationModel(flutterBinary: flutterbinaryMessenger)
// navigationModel = NavigationModel(flutterBinary: flutterbinaryMessenger)
messagingModel = try MessagingModel(flutterBinary: flutterbinaryMessenger)
}

Expand Down
5 changes: 4 additions & 1 deletion ios/Runner/Lantern/Models/BaseModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ open class BaseModel<M: InternalsdkModelProtocol>: NSObject, FlutterStreamHandle
self.model = model
self.binaryMessenger = flutterBinary
super.init()
setupFlutterChannels()
DispatchQueue.main.async {
self.setupFlutterChannels()
}

}

internal static func getDB() throws -> MinisqlDBProtocol {
Expand Down
18 changes: 11 additions & 7 deletions ios/Runner/Lantern/Models/LanternModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ class LanternModel: NSObject, FlutterStreamHandler {
init(flutterBinary: FlutterBinaryMessenger) {
self.flutterbinaryMessenger = flutterBinary
super.init()
lanternMethodChannel = FlutterMethodChannel(
name: LANTERN_METHOED_CHANNEL, binaryMessenger: flutterBinary)
lanternMethodChannel.setMethodCallHandler(handleMethodCall)
lanternEventChannel = FlutterEventChannel(
name: LANTERN_EVENT_CHANNEL, binaryMessenger: flutterBinary)
lanternEventChannel.setStreamHandler(self)


DispatchQueue.main.async{
self.lanternMethodChannel = FlutterMethodChannel(
name: self.LANTERN_METHOED_CHANNEL, binaryMessenger: flutterBinary)
self.lanternMethodChannel.setMethodCallHandler(self.handleMethodCall)
self.lanternEventChannel = FlutterEventChannel(
name: self.LANTERN_EVENT_CHANNEL, binaryMessenger: flutterBinary)
self.lanternEventChannel.setStreamHandler(self)
}


}

func handleMethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
Expand Down
82 changes: 41 additions & 41 deletions ios/Runner/Lantern/Models/NavigationModel.swift
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
////
//// NavigationModel.swift
//// Runner
////
//// Created by jigar fumakiya on 12/09/23.
////
//
// NavigationModel.swift
// Runner
//
// Created by jigar fumakiya on 12/09/23.
//

import Flutter
import Foundation

class NavigationModel {
let navigationMethodChannel = "lantern_method_channel"

var flutterbinaryMessenger: FlutterBinaryMessenger

init(flutterBinary: FlutterBinaryMessenger) {
self.flutterbinaryMessenger = flutterBinary
prepareNavigationChannel()
}

private func prepareNavigationChannel() {

// Navigation Channel
let navigationChannel = FlutterMethodChannel(
name: navigationMethodChannel, binaryMessenger: flutterbinaryMessenger)
navigationChannel.setMethodCallHandler(handleNavigationethodCall)
}

func handleNavigationethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
// Handle your method calls here
// The 'call' contains the method name and arguments
// The 'result' can be used to send back the data to Flutter
switch call.method {
case "yourMethod":
// handle yourMethod
break
default:
result(FlutterMethodNotImplemented)
}
}

}
//import Flutter
//import Foundation
//
//class NavigationModel {
// let navigationMethodChannel = "lantern_method_channel"
//
// var flutterbinaryMessenger: FlutterBinaryMessenger
//
// init(flutterBinary: FlutterBinaryMessenger) {
// self.flutterbinaryMessenger = flutterBinary
// prepareNavigationChannel()
// }
//
// private func prepareNavigationChannel() {
//
// // Navigation Channel
// let navigationChannel = FlutterMethodChannel(
// name: navigationMethodChannel, binaryMessenger: flutterbinaryMessenger)
// navigationChannel.setMethodCallHandler(handleNavigationethodCall)
// }
//
// func handleNavigationethodCall(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
// // Handle your method calls here
// // The 'call' contains the method name and arguments
// // The 'result' can be used to send back the data to Flutter
// switch call.method {
// case "yourMethod":
// // handle yourMethod
// break
// default:
// result(FlutterMethodNotImplemented)
// }
// }
//
//}
4 changes: 3 additions & 1 deletion ios/Runner/Lantern/Models/SessionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ class SessionModel: BaseModel<InternalsdkSessionModel> {
throw error!
}
try super.init(flutterBinary, model)
startService()
DispatchQueue.global(qos: .userInitiated).async {
self.startService()
}
// getBandwidth()
}

Expand Down

0 comments on commit 22d73a1

Please sign in to comment.