Skip to content

Commit

Permalink
fix: load proxy settings when app start
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Feb 25, 2024
1 parent b8d8583 commit 156c806
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1426,24 +1426,18 @@ public static void setDistanceSystemType(int type) {
LocaleController.resetImperialSystemType();
}

public static boolean proxyEnabled;

public static void setProxyEnable(boolean enable) {
if (enable && currentProxy == null) {
enable = false;
}

proxyEnabled = enable;

SharedPreferences preferences = MessagesController.getGlobalMainSettings();

preferences.edit().putBoolean("proxy_enabled", enable).apply();

ProxyInfo finalInfo = currentProxy;

boolean finalEnable = enable;
UIUtil.runOnIoDispatcher(() -> {

if (proxyEnabled) {
if (finalEnable) {
ConnectionsManager.setProxySettings(true, finalInfo.address, finalInfo.port, finalInfo.username, finalInfo.password, finalInfo.secret);
} else {
ConnectionsManager.setProxySettings(false, "", 0, "", "", "");
Expand Down Expand Up @@ -1600,6 +1594,7 @@ public static ProxyInfo addProxy(ProxyInfo proxyInfo) {
}

public static boolean isProxyEnabled() {
loadProxyList();
return MessagesController.getGlobalMainSettings().getBoolean("proxy_enabled", false) && currentProxy != null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,7 @@ public void init(int version, int layer, int apiId, String deviceModel, String s
native_init(currentAccount, version, layer, apiId, deviceModel, systemVersion, appVersion, langCode, systemLangCode, configPath, logPath, regId, cFingerprint, installer, packageId, timezoneOffset, userId, userPremium, enablePushConnection, ApplicationLoader.isNetworkOnline(), ApplicationLoader.getCurrentNetworkType(), SharedConfig.measureDevicePerformanceClass());

Utilities.stageQueue.postRunnable(() -> {

SharedConfig.loadProxyList();

if (SharedConfig.proxyEnabled && SharedConfig.currentProxy != null) {
if (SharedConfig.isProxyEnabled()) {
native_setProxySettings(currentAccount, SharedConfig.currentProxy.address, SharedConfig.currentProxy.port, SharedConfig.currentProxy.username, SharedConfig.currentProxy.password, SharedConfig.currentProxy.secret);
}
checkConnection();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ private void resetItems() {
items.add(new Item(11, LocaleController.getString("SavedMessages", R.string.SavedMessages), savedIcon));
items.add(new Item(8, LocaleController.getString("Settings", R.string.Settings), settingsIcon));
items.add(new Item(10, LocaleController.getString("Calls", R.string.Calls), callsIcon));
if (NekoConfig.useProxyItem.Bool() && (!NekoConfig.hideProxyByDefault.Bool() || SharedConfig.proxyEnabled)) {
items.add(new CheckItem(13, LocaleController.getString("Proxy", R.string.Proxy), R.drawable.menu_policy, () -> SharedConfig.proxyEnabled, () -> {
SharedConfig.setProxyEnable(!SharedConfig.proxyEnabled);
if (NekoConfig.useProxyItem.Bool() && (!NekoConfig.hideProxyByDefault.Bool() || SharedConfig.isProxyEnabled())) {
items.add(new CheckItem(13, LocaleController.getString("Proxy", R.string.Proxy), R.drawable.menu_policy, SharedConfig::isProxyEnabled, () -> {
SharedConfig.setProxyEnable(!SharedConfig.isProxyEnabled());
return true;
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6209,7 +6209,7 @@ protected void onResume() {
}

if (NaConfig.INSTANCE.getDisableProxyWhenVpnEnabled().Bool()) {
if (SharedConfig.proxyEnabled && ProxyUtil.isVPNEnabled()) {
if (SharedConfig.isProxyEnabled() && ProxyUtil.isVPNEnabled()) {
SharedConfig.setProxyEnable(false);
} else if (!ProxyUtil.isVPNEnabled()) {
SharedConfig.setProxyEnable(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object ProxyUtil {
}
}
}
if ((SharedConfig.proxyEnabled && vpn) || (!SharedConfig.proxyEnabled && !vpn)) {
if ((SharedConfig.isProxyEnabled() && vpn) || (!SharedConfig.isProxyEnabled() && !vpn)) {
SharedConfig.setProxyEnable(!vpn)
UIUtil.runOnUIThread(Runnable {
NotificationCenter.getGlobalInstance()
Expand Down

0 comments on commit 156c806

Please sign in to comment.