diff --git a/lib/globals.dart b/lib/globals.dart index 61f8e99..1d26a24 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -106,3 +106,5 @@ EHApi get api { final AuthInfo auth = AuthInfo(); final Path platformPath = Path(); +final GlobalKey rootScaffoldMessengerKey = + GlobalKey(); diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index f0ff564..ab3c381 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -6,5 +6,8 @@ "password": "Password", "save": "Save", "login": "Login", - "titleBar": "EH Downloader" + "titleBar": "EH Downloader", + "incorrectUserPassword": "Incorrect username or password.", + "networkError": "Network error.", + "internalError": "Some internal error occurred. Please send the log file to the developer." } diff --git a/lib/l10n/app_zh.arb b/lib/l10n/app_zh.arb index 4f75f38..48e9d1f 100644 --- a/lib/l10n/app_zh.arb +++ b/lib/l10n/app_zh.arb @@ -6,5 +6,8 @@ "password": "密码", "save": "保存", "login": "登录", - "titleBar": "EH 下载器" + "titleBar": "EH 下载器", + "incorrectUserPassword": "不正确的用户名或密码。", + "networkError": "网络错误。", + "internalError": "出现了内部错误,请将日志发送给开发者。" } diff --git a/lib/login.dart b/lib/login.dart index 21fb997..9bd41c4 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -70,7 +70,9 @@ class _LoginPageState extends State { setCookie: true, httpOnly: true, secure: u.scheme == 'https'); - return re.ok; + if (re.ok) return true; + if (re.status == 4) return false; + throw re.unwrapErr(); } void _checkStatus(BuildContext build) { @@ -147,12 +149,27 @@ class _LoginPageState extends State { if (re) { context.go("/"); } else { + final snackBar = SnackBar( + content: Text( + AppLocalizations.of(context)! + .incorrectUserPassword)); + ScaffoldMessenger.of(context) + .showSnackBar(snackBar); setState(() { _isLogin = false; }); } }).catchError((e) { _log.severe("Failed to login:", e); + final isNetworkError = e is! (int, String); + final snackBar = SnackBar( + content: Text(isNetworkError + ? AppLocalizations.of(context)! + .networkError + : AppLocalizations.of(context)! + .internalError)); + ScaffoldMessenger.of(context) + .showSnackBar(snackBar); setState(() { _isLogin = false; }); diff --git a/lib/main.dart b/lib/main.dart index 2c4582f..e5fe8b5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -123,6 +123,7 @@ class _MainApp extends State { theme: _themeData, darkTheme: _darkThemeData, themeMode: _themeMode, + scaffoldMessengerKey: rootScaffoldMessengerKey, ); }