refactor(proxy): 切换代理逻辑调整
- 将 `ClashUtil.switchProxyGroup` 调用替换为 `ClashUtil.switchProxyWithPort(CountryCode.switchCountry())` - 移除了 `MainActivity` 中的 `executeSingleLogic` 方法,相关逻辑已在 `LoadDeviceWorker` 中处理 - 在 `LoadDeviceWorker` 和 `MainActivity` 的 `startProxyVpn` 方法中,使用 `TAG` 记录日志,并更新了代理切换逻辑。
This commit is contained in:
parent
20eaac8e12
commit
2b60f10351
|
@ -193,16 +193,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
public static final LinkedBlockingQueue<String> scriptResultQueue = new LinkedBlockingQueue<>();
|
||||
|
||||
|
||||
public void executeSingleLogic() {
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Proxy not active, starting VPN", null);
|
||||
startProxyVpn(this);
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Changing device info", null);
|
||||
ChangeDeviceInfoUtil.changeDeviceInfo(getPackageName(), this,armClient);
|
||||
LogFileUtil.logAndWrite(Log.INFO, "MainActivity", "executeSingleLogic: Running AutoJs script", null);
|
||||
AutoJsUtil.runAutojsScript(this);
|
||||
}
|
||||
|
||||
|
||||
private void startProxyVpn(Context context) {
|
||||
if (!isNetworkAvailable(context)) {
|
||||
Toast.makeText(context, "Network is not available", Toast.LENGTH_SHORT).show();
|
||||
|
@ -217,11 +207,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
|
||||
try {
|
||||
ClashUtil.startProxy(context); // 在主线程中调用
|
||||
ClashUtil.switchProxyGroup("GLOBAL", "us", "http://127.0.0.1:6170");
|
||||
ClashUtil.startProxy(context);
|
||||
ClashUtil.switchProxyWithPort(CountryCode.switchCountry());
|
||||
// ClashUtil.switchProxyGroup("PROXY", "my-socks5-proxy", "http://127.0.0.1:6170");
|
||||
} catch (Exception e) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Failed to start VPN", e);
|
||||
Toast.makeText(context, "Failed to start VPN: " + (e.getMessage() != null ? e.getMessage() : "Unknown error"), Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, TAG, "startProxyVpn: Failed to start VPN", e);
|
||||
Toast.makeText(context, "Failed to start VPN: " +
|
||||
(e.getMessage() != null ? e.getMessage() : "Unknown error"),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,10 @@ import java.util.UUID;
|
|||
import kotlin.coroutines.Continuation;
|
||||
|
||||
public class LoadDeviceWorker extends CoroutineWorker {
|
||||
|
||||
private String androidId = "FyZqWrStUvOpKlMn";
|
||||
private Context context;
|
||||
|
||||
public LoadDeviceWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
|
||||
super(context, workerParams);
|
||||
this.context = context;
|
||||
|
@ -73,11 +75,14 @@ public class LoadDeviceWorker extends CoroutineWorker {
|
|||
// return;
|
||||
// }
|
||||
try {
|
||||
ClashUtil.startProxy(context); // 在主线程中调用
|
||||
ClashUtil.switchProxyGroup("GLOBAL", "us", "http://127.0.0.1:6170");
|
||||
ClashUtil.startProxy(context);
|
||||
ClashUtil.switchProxyWithPort(CountryCode.switchCountry());
|
||||
// ClashUtil.switchProxyGroup("PROXY", "my-socks5-proxy", "http://127.0.0.1:6170");
|
||||
} catch (Exception e) {
|
||||
LogFileUtil.logAndWrite(Log.ERROR, "MainActivity", "startProxyVpn: Failed to start VPN",e);
|
||||
Toast.makeText(context, "Failed to start VPN: " + (e.getMessage() != null ? e.getMessage() : "Unknown error"), Toast.LENGTH_SHORT).show();
|
||||
LogFileUtil.logAndWrite(Log.ERROR, TAG, "startProxyVpn: Failed to start VPN", e);
|
||||
Toast.makeText(context, "Failed to start VPN: " +
|
||||
(e.getMessage() != null ? e.getMessage() : "Unknown error"),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue