fix: load proxy settings when app start

This commit is contained in:
xtaodada 2024-02-25 20:31:58 +08:00
parent 16c2ba3202
commit b303179efb
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
5 changed files with 9 additions and 17 deletions

View File

@ -1428,24 +1428,18 @@ public class SharedConfig {
LocaleController.resetImperialSystemType(); LocaleController.resetImperialSystemType();
} }
public static boolean proxyEnabled;
public static void setProxyEnable(boolean enable) { public static void setProxyEnable(boolean enable) {
if (enable && currentProxy == null) { if (enable && currentProxy == null) {
enable = false; enable = false;
} }
proxyEnabled = enable;
SharedPreferences preferences = MessagesController.getGlobalMainSettings(); SharedPreferences preferences = MessagesController.getGlobalMainSettings();
preferences.edit().putBoolean("proxy_enabled", enable).apply(); preferences.edit().putBoolean("proxy_enabled", enable).apply();
ProxyInfo finalInfo = currentProxy; ProxyInfo finalInfo = currentProxy;
boolean finalEnable = enable;
UIUtil.runOnIoDispatcher(() -> { UIUtil.runOnIoDispatcher(() -> {
if (finalEnable) {
if (proxyEnabled) {
ConnectionsManager.setProxySettings(true, finalInfo.address, finalInfo.port, finalInfo.username, finalInfo.password, finalInfo.secret); ConnectionsManager.setProxySettings(true, finalInfo.address, finalInfo.port, finalInfo.username, finalInfo.password, finalInfo.secret);
} else { } else {
ConnectionsManager.setProxySettings(false, "", 0, "", "", ""); ConnectionsManager.setProxySettings(false, "", 0, "", "", "");
@ -1602,6 +1596,7 @@ public class SharedConfig {
} }
public static boolean isProxyEnabled() { public static boolean isProxyEnabled() {
loadProxyList();
return MessagesController.getGlobalMainSettings().getBoolean("proxy_enabled", false) && currentProxy != null; return MessagesController.getGlobalMainSettings().getBoolean("proxy_enabled", false) && currentProxy != null;
} }

View File

@ -495,10 +495,7 @@ SharedPreferences mainPreferences;
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()); 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(() -> { Utilities.stageQueue.postRunnable(() -> {
if (SharedConfig.isProxyEnabled()) {
SharedConfig.loadProxyList();
if (SharedConfig.proxyEnabled && SharedConfig.currentProxy != null) {
native_setProxySettings(currentAccount, SharedConfig.currentProxy.address, SharedConfig.currentProxy.port, SharedConfig.currentProxy.username, SharedConfig.currentProxy.password, SharedConfig.currentProxy.secret); native_setProxySettings(currentAccount, SharedConfig.currentProxy.address, SharedConfig.currentProxy.port, SharedConfig.currentProxy.username, SharedConfig.currentProxy.password, SharedConfig.currentProxy.secret);
} }
checkConnection(); checkConnection();

View File

@ -403,9 +403,9 @@ public class DrawerLayoutAdapter extends RecyclerListView.SelectionAdapter imple
items.add(new Item(11, LocaleController.getString("SavedMessages", R.string.SavedMessages), savedIcon)); 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(8, LocaleController.getString("Settings", R.string.Settings), settingsIcon));
items.add(new Item(10, LocaleController.getString("Calls", R.string.Calls), callsIcon)); items.add(new Item(10, LocaleController.getString("Calls", R.string.Calls), callsIcon));
if (NekoConfig.useProxyItem.Bool() && (!NekoConfig.hideProxyByDefault.Bool() || 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.proxyEnabled, () -> { items.add(new CheckItem(13, LocaleController.getString("Proxy", R.string.Proxy), R.drawable.menu_policy, SharedConfig::isProxyEnabled, () -> {
SharedConfig.setProxyEnable(!SharedConfig.proxyEnabled); SharedConfig.setProxyEnable(!SharedConfig.isProxyEnabled());
return true; return true;
})); }));
} }

View File

@ -6227,7 +6227,7 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
} }
if (NaConfig.INSTANCE.getDisableProxyWhenVpnEnabled().Bool()) { if (NaConfig.INSTANCE.getDisableProxyWhenVpnEnabled().Bool()) {
if (SharedConfig.proxyEnabled && ProxyUtil.isVPNEnabled()) { if (SharedConfig.isProxyEnabled() && ProxyUtil.isVPNEnabled()) {
SharedConfig.setProxyEnable(false); SharedConfig.setProxyEnable(false);
} else if (!ProxyUtil.isVPNEnabled()) { } else if (!ProxyUtil.isVPNEnabled()) {
SharedConfig.setProxyEnable(true); SharedConfig.setProxyEnable(true);

View File

@ -80,7 +80,7 @@ object ProxyUtil {
} }
} }
} }
if ((SharedConfig.proxyEnabled && vpn) || (!SharedConfig.proxyEnabled && !vpn)) { if ((SharedConfig.isProxyEnabled() && vpn) || (!SharedConfig.isProxyEnabled() && !vpn)) {
SharedConfig.setProxyEnable(!vpn) SharedConfig.setProxyEnable(!vpn)
UIUtil.runOnUIThread(Runnable { UIUtil.runOnUIThread(Runnable {
NotificationCenter.getGlobalInstance() NotificationCenter.getGlobalInstance()