修复启动器在部分 Linux 发行版上无法正确识别用户地区的问题 (#3921)
This commit is contained in:
@@ -50,7 +50,7 @@ import org.jackhuang.hmcl.util.platform.windows.WinConstants;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.setting.ConfigHolder.globalConfig;
|
import static org.jackhuang.hmcl.setting.ConfigHolder.globalConfig;
|
||||||
@@ -63,18 +63,27 @@ public final class AccountListPage extends DecoratorAnimatedPage implements Deco
|
|||||||
static final BooleanProperty RESTRICTED = new SimpleBooleanProperty(true);
|
static final BooleanProperty RESTRICTED = new SimpleBooleanProperty(true);
|
||||||
|
|
||||||
private static boolean isExemptedRegion() {
|
private static boolean isExemptedRegion() {
|
||||||
if ("Asia/Shanghai".equals(ZoneId.systemDefault().getId()))
|
String zoneId = ZoneId.systemDefault().getId();
|
||||||
|
if (Arrays.asList(
|
||||||
|
"Asia/Shanghai",
|
||||||
|
// Although Asia/Beijing is not a legal name, Deepin uses it
|
||||||
|
"Asia/Beijing",
|
||||||
|
"Asia/Chongqing",
|
||||||
|
"Asia/Chungking",
|
||||||
|
"Asia/Harbin"
|
||||||
|
).contains(zoneId))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS
|
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS && NativeUtils.USE_JNA) {
|
||||||
&& NativeUtils.USE_JNA
|
|
||||||
&& ZonedDateTime.now().getOffset().getTotalSeconds() == 8 * 3600) { // GMT+8
|
|
||||||
Kernel32 kernel32 = Kernel32.INSTANCE;
|
Kernel32 kernel32 = Kernel32.INSTANCE;
|
||||||
|
|
||||||
// https://learn.microsoft.com/windows/win32/intl/table-of-geographical-locations
|
// https://learn.microsoft.com/windows/win32/intl/table-of-geographical-locations
|
||||||
if (kernel32 != null && kernel32.GetUserGeoID(WinConstants.GEOCLASS_NATION) == 45)
|
if (kernel32 != null && kernel32.GetUserGeoID(WinConstants.GEOCLASS_NATION) == 45) // China
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.LINUX && "GMT+08:00".equals(zoneId))
|
||||||
|
// Some Linux distributions may use invalid time zone ids (e.g., Asia/Beijing)
|
||||||
|
// Java may not be able to resolve this name and use GMT+08:00 instead.
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user