mirror of https://github.com/NekoX-Dev/NekoX.git
customPublicProxyIP
This commit is contained in:
parent
de5573c5ad
commit
c2bc81ac5a
|
@ -3,9 +3,13 @@ package tw.nekomimi.nekogram
|
|||
import android.os.Build
|
||||
import androidx.annotation.RequiresApi
|
||||
import cn.hutool.core.codec.Base64
|
||||
import cn.hutool.core.util.StrUtil
|
||||
import okhttp3.Dns
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||
import tw.nekomimi.nekogram.tcp2ws.Tcp2wsServer
|
||||
import tw.nekomimi.nkmr.NekomuraConfig
|
||||
import java.net.InetAddress
|
||||
|
||||
class WsLoader {
|
||||
|
||||
|
@ -69,4 +73,21 @@ class WsLoader {
|
|||
}
|
||||
}
|
||||
|
||||
// For OKHttp in ProxyHandler.java
|
||||
class CustomDns : Dns {
|
||||
override fun lookup(hostname: String): List<InetAddress> {
|
||||
val list = ArrayList<InetAddress>()
|
||||
val ip = NekomuraConfig.customPublicProxyIP.String()
|
||||
if (StrUtil.isBlank(ip)) {
|
||||
return Dns.SYSTEM.lookup(hostname)
|
||||
}
|
||||
return try {
|
||||
list.add(InetAddress.getByName(ip))
|
||||
list
|
||||
} catch (e: Exception) {
|
||||
Dns.SYSTEM.lookup(hostname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -93,6 +93,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
private final NekomuraTGCell hideProxyByDefaultRow = addNekomuraTGCell(nkmrCells.new NekomuraTGTextCheck(NekomuraConfig.hideProxyByDefault));
|
||||
private final NekomuraTGCell useSystemDNSRow = addNekomuraTGCell(nkmrCells.new NekomuraTGTextCheck(NekomuraConfig.useSystemDNS));
|
||||
private final NekomuraTGCell customDoHRow = addNekomuraTGCell(nkmrCells.new NekomuraTGTextInput(null, NekomuraConfig.customDoH, "https://1.0.0.1/dns-query", null));
|
||||
private final NekomuraTGCell customPublicProxyIPRow = addNekomuraTGCell(nkmrCells.new NekomuraTGTextInput(null, NekomuraConfig.customPublicProxyIP, "", null));
|
||||
private final NekomuraTGCell divider1 = addNekomuraTGCell(nkmrCells.new NekomuraTGDivider());
|
||||
|
||||
private final NekomuraTGCell header2 = addNekomuraTGCell(nkmrCells.new NekomuraTGHeader(LocaleController.getString("Translate")));
|
||||
|
|
|
@ -145,7 +145,7 @@ public class ProxyHandler implements Runnable {
|
|||
}
|
||||
|
||||
if (okhttpClient == null) {
|
||||
okhttpClient = new OkHttpClient();
|
||||
okhttpClient = new OkHttpClient.Builder().dns(new WsLoader.CustomDns()).build();
|
||||
}
|
||||
|
||||
((OkHttpClient) okhttpClient)
|
||||
|
|
|
@ -166,6 +166,7 @@ public class NekomuraConfig {
|
|||
public static ConfigItem migrate = addConfig("NekoConfigMigrate", configTypeBool, false);
|
||||
public static ConfigItem largeAvatarInDrawer = addConfig("AvatarAsBackground", configTypeInt, 0); // 0:TG Default 1:NekoX Default 2:Large Avatar
|
||||
public static ConfigItem unreadBadgeOnBackButton = addConfig("unreadBadgeOnBackButton", configTypeBool, false);
|
||||
public static ConfigItem customPublicProxyIP = addConfig("customPublicProxyIP", configTypeString, "");
|
||||
|
||||
// From NekoConfig
|
||||
// TODO sort
|
||||
|
|
|
@ -2,7 +2,10 @@
|
|||
<resources>
|
||||
<string name="largeAvatarInDrawer">Large avatar in drawer</string>
|
||||
<string name="unreadBadgeOnBackButton">Unread badge on back button</string>
|
||||
<string name="customPublicProxyIP">Set IP of public proxy</string>
|
||||
|
||||
<string name="valuesLargeAvatarInDrawer">Telegram Default\nAvatar as background\nBig avatar as background</string>
|
||||
|
||||
<string name="DeleteDownloadedFileConfirm">Delete this file from local cache?</string>
|
||||
<string name="DeleteDownloadedFileSuccessed">Deleted</string>
|
||||
<string name="DeleteDownloadedFileExternal">External file is skipped.</string>
|
||||
|
|
Loading…
Reference in New Issue