Skip to content

Commit

Permalink
refactor(client/ios): move fetching logic from TypeScript to Go
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Oct 22, 2024
1 parent 6a0b588 commit bb7962c
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions client/src/cordova/plugin/apple/src/OutlinePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import OutlineSentryLogger
import OutlineNotification
import OutlineTunnel

import Tun2socks

public enum TunnelStatus: Int {
case connected = 0
case disconnected = 1
Expand Down Expand Up @@ -142,6 +144,27 @@ class OutlinePlugin: CDVPlugin {
}
}

func fetchConfig(_ command: CDVInvokedUrlCommand) {
guard let url = command.argument(at: 0) as? String else {
return sendError("Missing URL", callbackId: command.callbackId)
}
DDLogInfo("Fetching dynamic config from \(url)")
Task {
guard let result = OutlineFetchDynamicKey(url) else {
return self.sendError("unexpected fetching result", callbackId: command.callbackId)
}
if result.error != nil {
var marshalErr: NSError?
var errorJson = PlaterrorsMarshalJSONString(result.error, &marshalErr)
if marshalErr != nil {
errorJson = "error code = \(result.error?.code ?? "?"), failed to fetch details"
}
return self.sendError(errorJson, callbackId: command.callbackId)
}
self.sendSuccess(result.key, callbackId: command.callbackId)
}
}

func onStatusChange(_ command: CDVInvokedUrlCommand) {
DDLogInfo("OutlinePlugin: registering status callback")
if let currentCallbackId = self.statusCallbackId {
Expand Down Expand Up @@ -276,9 +299,14 @@ class OutlinePlugin: CDVPlugin {

// MARK: - Callback helpers

private func sendSuccess(callbackId: String, keepCallback: Bool = false) {
let result = CDVPluginResult(status: CDVCommandStatus_OK)
send(pluginResult: result, callbackId: callbackId, keepCallback: keepCallback)
private func sendSuccess(callbackId: String, keepCallback: Bool = false) {
let result = CDVPluginResult(status: CDVCommandStatus_OK)
send(pluginResult: result, callbackId: callbackId, keepCallback: keepCallback)
}

private func sendSuccess(_ operationResult: String, callbackId: String, keepCallback: Bool = false) {
let result = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: operationResult)
send(pluginResult: result, callbackId: callbackId, keepCallback: keepCallback)
}

private func sendSuccess(_ operationResult: Bool, callbackId: String, keepCallback: Bool = false) {
Expand Down

0 comments on commit bb7962c

Please sign in to comment.