feat: show warning when logging in Microsoft account if app is released as snapshot version.

This commit is contained in:
huanghongxun
2021-09-20 19:36:11 +08:00
parent 37cee9cebd
commit 271fb4ce87
6 changed files with 16 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ import org.jackhuang.hmcl.auth.AuthenticationException;
import org.jackhuang.hmcl.auth.microsoft.MicrosoftService;
import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.util.Logging;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.io.IOUtils;
import org.jackhuang.hmcl.util.io.JarUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils;
@@ -74,7 +75,7 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi
String html;
try {
html = IOUtils.readFullyAsString(MicrosoftAuthenticationServer.class.getResourceAsStream("/assets/microsoft_auth.html"), StandardCharsets.UTF_8)
.replace("%close-page%", i18n("account.methods.microsoft.close_page"));
.replace("%close-page%", i18n("account.methods.microsoft.close_page"));
} catch (IOException e) {
Logging.LOG.log(Level.SEVERE, "Failed to load html");
return newFixedLengthResponse(Response.Status.INTERNAL_ERROR, MIME_HTML, "");
@@ -93,7 +94,11 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi
public static class Factory implements MicrosoftService.OAuthCallback {
@Override
public MicrosoftService.OAuthSession startServer() throws IOException {
public MicrosoftService.OAuthSession startServer() throws IOException, AuthenticationException {
if (StringUtils.isBlank(getClientId())) {
throw new MicrosoftAuthenticationNotSupportedException();
}
IOException exception = null;
for (int port : new int[]{29111, 29112, 29113, 29114, 29115}) {
try {
@@ -126,4 +131,7 @@ public final class MicrosoftAuthenticationServer extends NanoHTTPD implements Mi
}
}
public static class MicrosoftAuthenticationNotSupportedException extends AuthenticationException {
}
}

View File

@@ -378,6 +378,8 @@ public final class Accounts {
return i18n("account.methods.microsoft.error.no_character");
} else if (exception instanceof MicrosoftService.NoXuiException) {
return i18n("account.methods.microsoft.error.add_family_probably");
} else if (exception instanceof MicrosoftAuthenticationServer.MicrosoftAuthenticationNotSupportedException) {
return i18n("account.methods.microsoft.snapshot");
} else if (exception.getClass() == AuthenticationException.class) {
return exception.getLocalizedMessage();
} else {

View File

@@ -91,6 +91,7 @@ account.methods.microsoft.logging_in=Logging in...
account.methods.microsoft.hint=You should click "login" button and continue login process in newly opened browser window.
account.methods.microsoft.manual=After clicking "login" button, you should finish authorization in the newly opened browser window. If the browser window failed to show, you can click here to copy the URL, and manually open it in your browser.
account.methods.microsoft.profile=Account Profile...
account.methods.microsoft.snapshot=HMCL Snapshot version does not support Microsoft login.
account.methods.microsoft.waiting_browser=Waiting for authorization in opened browser window...
account.methods.offline=Offline
account.methods.offline.uuid=UUID

View File

@@ -91,6 +91,7 @@ account.methods.microsoft.logging_in=登入中...
account.methods.microsoft.hint=您需要點擊登入按鈕,並在新打開的瀏覽器窗口中完成登入。
account.methods.microsoft.manual=若登入頁面未能打開,您可以點擊此處複製連結,並手動在瀏覽器中打開網頁。
account.methods.microsoft.profile=帳戶設置頁
account.methods.microsoft.snapshot=HMCL 快照版不支持微软登录
account.methods.microsoft.waiting_browser=等待在新打開的瀏覽器窗口中完成登入...
account.methods.offline=離線模式
account.methods.offline.uuid=UUID

View File

@@ -91,6 +91,7 @@ account.methods.microsoft.logging_in=登录中...
account.methods.microsoft.hint=您需要点击登录按钮,并在新打开的浏览器窗口中完成登录。
account.methods.microsoft.manual=若登录页面未能打开,您可以点击此处复制链接,并手动在浏览器中打开网页。
account.methods.microsoft.profile=帐户设置页
account.methods.microsoft.snapshot=HMCL 快照版不支持微软登录
account.methods.microsoft.waiting_browser=等待在新打开的浏览器窗口中完成登录...
account.methods.offline=离线模式
account.methods.offline.uuid=UUID

View File

@@ -504,7 +504,7 @@ public class MicrosoftService {
*
* @throws IOException if an I/O error occurred.
*/
OAuthSession startServer() throws IOException;
OAuthSession startServer() throws IOException, AuthenticationException;
/**
* Open browser