fix: load proxy settings when app start
This commit is contained in:
parent
16c2ba3202
commit
b303179efb
@ -1428,24 +1428,18 @@ public class SharedConfig {
|
||||
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, "", "", "");
|
||||
@ -1602,6 +1596,7 @@ public class SharedConfig {
|
||||
}
|
||||
|
||||
public static boolean isProxyEnabled() {
|
||||
loadProxyList();
|
||||
return MessagesController.getGlobalMainSettings().getBoolean("proxy_enabled", false) && currentProxy != null;
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
||||
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();
|
||||
|
@ -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(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;
|
||||
}));
|
||||
}
|
||||
|
@ -6227,7 +6227,7 @@ public class LaunchActivity extends BasePermissionsActivity implements INavigati
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user