-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create VPN model and implemented store version logic for IOS
- Loading branch information
Showing
9 changed files
with
209 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package internalsdk | ||
|
||
import ( | ||
"github.com/getlantern/pathdb" | ||
"github.com/getlantern/pathdb/minisql" | ||
) | ||
|
||
// Custom Model implemnation | ||
// VPNModel is a custom model derived from the baseModel. | ||
type VpnModel struct { | ||
*baseModel | ||
} | ||
|
||
const PATH_VPN_STATUS = "/vpn_status" | ||
const PATH_SERVER_INFO = "/server_info" | ||
const PATH_BANDWIDTH = "/bandwidth" | ||
|
||
// NewSessionModel initializes a new SessionModel instance. | ||
func NewVpnModel(schema string, mdb minisql.DB) (*VpnModel, error) { | ||
base, err := newModel(schema, mdb) | ||
if err != nil { | ||
return nil, err | ||
} | ||
initVpnModel(base.(*baseModel)) | ||
model := &VpnModel{base.(*baseModel)} | ||
return model, nil | ||
} | ||
|
||
func initVpnModel(m *baseModel) error { | ||
pathdb.Mutate(m.db, func(tx pathdb.TX) error { | ||
rawStatus, err := tx.Get(PATH_VPN_STATUS) | ||
panicIfNecessary(err) | ||
status := string(rawStatus) | ||
if status != "" { | ||
pathdb.Put[string](tx, PATH_VPN_STATUS, status, "") | ||
} else { | ||
pathdb.Put[string](tx, PATH_VPN_STATUS, "disconnected", "") | ||
} | ||
return nil | ||
}) | ||
return nil | ||
} | ||
|
||
func (s *VpnModel) InvokeMethod(method string, arguments minisql.Values) (*minisql.Value, error) { | ||
switch method { | ||
case "Hello": | ||
return minisql.NewValueString("Hello"), nil | ||
default: | ||
return s.baseModel.InvokeMethod(method, arguments) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// VpnModel.swift | ||
// Runner | ||
// | ||
// Created by jigar fumakiya on 01/09/23. | ||
// | ||
|
||
|
||
import Foundation | ||
import Internalsdk | ||
import Flutter | ||
|
||
|
||
class VpnModel : BaseModel<InternalsdkVpnModel> { | ||
|
||
var flutterbinaryMessenger:FlutterBinaryMessenger | ||
|
||
init(flutterBinary:FlutterBinaryMessenger) { | ||
self.flutterbinaryMessenger=flutterBinary | ||
super.init(type: .vpnModel , flutterBinary: self.flutterbinaryMessenger) | ||
initializeVpnModel() | ||
} | ||
|
||
func initializeVpnModel() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// RunningEnv.swift | ||
// Runner | ||
// | ||
// Created by jigar fumakiya on 01/09/23. | ||
|
||
import Foundation | ||
|
||
|
||
func isRunningFromAppStore() -> Bool { | ||
let file = "\(NSHomeDirectory())/iTunesMetadata.plist" | ||
if FileManager.default.fileExists(atPath: file) { | ||
// The app is running from the App Store | ||
return true | ||
} else { | ||
// The app is not running from the App Store | ||
return false | ||
} | ||
} | ||
|
||
|
||
func isRunningInTestFlightEnvironment() -> Bool{ | ||
if isSimulator() { | ||
return false | ||
} else { | ||
if isAppStoreReceiptSandbox() && !hasEmbeddedMobileProvision() { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
} | ||
|
||
|
||
private func hasEmbeddedMobileProvision() -> Bool{ | ||
if let _ = Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
|
||
func isAppStoreReceiptSandbox() -> Bool { | ||
if isSimulator() { | ||
return false | ||
} else { | ||
if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL { | ||
if appStoreReceiptURL.lastPathComponent == "sandboxReceipt" { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
|
||
|
||
|
||
private func isSimulator() -> Bool { | ||
#if arch(i386) || arch(x86_64) | ||
return true | ||
#else | ||
return false | ||
#endif | ||
} |