mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-10 04:16:02 -04:00
加载网络背景时设置超时 (#2856)
This commit is contained in:
parent
baf1d22bc4
commit
90cfe3d0b7
@ -50,6 +50,10 @@ import org.jackhuang.hmcl.ui.wizard.WizardProvider;
|
|||||||
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@ -168,8 +172,23 @@ public class DecoratorController {
|
|||||||
break;
|
break;
|
||||||
case NETWORK:
|
case NETWORK:
|
||||||
String backgroundImageUrl = config().getBackgroundImageUrl();
|
String backgroundImageUrl = config().getBackgroundImageUrl();
|
||||||
if (backgroundImageUrl != null && NetworkUtils.isURL(backgroundImageUrl))
|
if (backgroundImageUrl != null) {
|
||||||
image = tryLoadImage(backgroundImageUrl).orElse(null);
|
try {
|
||||||
|
URLConnection connection = NetworkUtils.createConnection(new URL(backgroundImageUrl));
|
||||||
|
if (connection instanceof HttpURLConnection) {
|
||||||
|
connection = NetworkUtils.resolveConnection((HttpURLConnection) connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
try (InputStream input = connection.getInputStream()) {
|
||||||
|
image = new Image(input);
|
||||||
|
if (image.isError()) {
|
||||||
|
throw image.getException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.log(WARNING, "Couldn't load background image", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CLASSIC:
|
case CLASSIC:
|
||||||
image = newBuiltinImage("/assets/img/background-classic.jpg");
|
image = newBuiltinImage("/assets/img/background-classic.jpg");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user