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();
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user