Skip to content

Commit

Permalink
Merge pull request #138 from mylxsw/v2.x
Browse files Browse the repository at this point in the history
update
  • Loading branch information
mylxsw authored Feb 15, 2025
2 parents cfd6657 + c8378e6 commit d0e2b1b
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 106 deletions.
3 changes: 3 additions & 0 deletions lib/helper/constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ const qiniuImageTypeThumbMedium = 'thumb_500';
// 缓存相关的 Keys
// 最后一次使用的模型
const cacheKeyLastModel = 'last-model';

// 数据存储目录
const homePathDirName = '.aidea-dev';
22 changes: 9 additions & 13 deletions lib/helper/path.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:io' show Directory, Platform;
import 'package:askaide/helper/constant.dart';
import 'package:askaide/helper/logger.dart';
import 'package:askaide/helper/platform.dart';
import 'package:path_provider/path_provider.dart';
Expand All @@ -10,22 +11,19 @@ class PathHelper {

init() async {
try {
cachePath =
(await getApplicationCacheDirectory()).path.replaceAll('\\', '/');
cachePath = (await getApplicationCacheDirectory()).path.replaceAll('\\', '/');
} catch (e) {
cachePath = '';
}

try {
documentsPath =
(await getApplicationDocumentsDirectory()).path.replaceAll('\\', '/');
documentsPath = (await getApplicationDocumentsDirectory()).path.replaceAll('\\', '/');
} catch (e) {
documentsPath = '';
}

try {
supportPath =
(await getApplicationSupportDirectory()).path.replaceAll('\\', '/');
supportPath = (await getApplicationSupportDirectory()).path.replaceAll('\\', '/');
} catch (e) {
supportPath = '';
}
Expand All @@ -34,22 +32,20 @@ class PathHelper {
try {
Directory(getHomePath).create(recursive: true);
} catch (e) {
Logger.instance.e('创建 $getHomePath 目录失败: $e');
Logger.instance.e('Create $getHomePath directory failed: $e');
}
}

String get getHomePath {
if (PlatformTool.isMacOS() || PlatformTool.isLinux()) {
return '${Platform.environment['HOME'] ?? ''}/.aidea'
.replaceAll('\\', '/');
return '${Platform.environment['HOME'] ?? ''}/$homePathDirName'.replaceAll('\\', '/');
} else if (PlatformTool.isWindows()) {
return '${Platform.environment['UserProfile'] ?? ''}/.aidea'
.replaceAll('\\', '/');
return '${Platform.environment['UserProfile'] ?? ''}/$homePathDirName'.replaceAll('\\', '/');
} else if (PlatformTool.isAndroid() || PlatformTool.isIOS()) {
return '$documentsPath/.aidea'.replaceAll('\\', '/');
return '$documentsPath/$homePathDirName'.replaceAll('\\', '/');
}

return '.aidea';
return homePathDirName;
}

String get getLogfilePath {
Expand Down
55 changes: 49 additions & 6 deletions lib/lang/lang.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mixin AppLocale {
static const String required = 'required';
static const String wechat = 'wechat';
static const String systemInfo = 'system_info';
static const String appName = 'app_name';
static const String homeTitle = 'home_title';
Expand All @@ -20,6 +21,7 @@ mixin AppLocale {
static const String userTerms = 'user_terms';
static const String privacyPolicy = 'privacy_policy';
static const String signIn = 'sign_in';
static const String signInAccount = 'sign_in_account';
static const String signOut = 'sign_out';
static const String signUp = 'sign_up';
static const String password = 'password';
Expand Down Expand Up @@ -200,6 +202,7 @@ mixin AppLocale {
static const String passwordFormatError = 'password-format-error';
static const String accountCreated = 'account-created';
static const String sendVerifyCode = 'send-verify-code';
static const String verify = 'verify';
static const String verifyCode = 'verify-code';
static const String verifyCodeInputTips = 'verify-code-input-tips';
static const String retryInSeconds = 'retry-in-seconds';
Expand All @@ -209,12 +212,14 @@ mixin AppLocale {
static const String verifyCodeFormatError = 'verify-code-format-error';
static const String phone = 'phone';
static const String email = 'email';
static const String directSignin = 'direct-signin';
static const String directSigninDueHasAccount = 'direct-signin-due-has-account';
static const String directSignin = 'direct-signin-due-no-account';
static const String passwordResetOK = 'password-reset-ok';
static const String resetPassword = 'reset-password';
static const String bindPhone = 'bind-phone';
static const String bind = 'bind';
static const String bound = 'bond';
static const String bindExAccount = 'bind-ex-account';
static const String unbind = 'unbind';
static const String inviteCode = 'invite-code';
static const String inviteCodeInputTips = 'invite-code-input-tips';
Expand Down Expand Up @@ -327,8 +332,18 @@ mixin AppLocale {
static const String longTimeAgo = 'long-time-ago';

static const String modelNeedSignIn = 'model-need-sign-in';
static const String wechatBindConfirm = 'wechat-bind-confirm';
static const String accountWillBeCreateAutomatically = 'account-will-be-create-automatically';
static const String installWechatFirst = 'install-wechat-first';
static const String otherLoginMethods = 'other-login-methods';
static const String verifyAccount = 'verify-account';
static const String enterPasswordToSignin = 'enter-password-to-signin';
static const String verifyCodeLogin = 'verify-code-login';
static const String verifyCodeLoginTips = 'verify-code-login-tips';
static const String usePasswordToSignin = 'use-password-to-signin';

static const Map<String, dynamic> zh = {
wechat: '微信',
required: '必填',
systemInfo: '系统信息',
save: '保存',
Expand Down Expand Up @@ -386,6 +401,7 @@ mixin AppLocale {
userTerms: '用户协议',
privacyPolicy: '隐私政策',
signIn: '登录',
signInAccount: '登录解锁完整功能',
signOut: '退出登录',
signUp: '注册',
password: '密码',
Expand Down Expand Up @@ -521,6 +537,7 @@ mixin AppLocale {
passwordFormatError: '密码格式有误\n必须为8-20位字母、数字、特殊符号组合',
accountCreated: '账号创建成功',
sendVerifyCode: '发送',
verify: '验证',
verifyCode: '验证码',
verifyCodeInputTips: '输入验证码',
retryInSeconds: '秒后重试',
Expand All @@ -530,12 +547,14 @@ mixin AppLocale {
verifyCodeFormatError: '验证码格式有误',
phone: '手机',
email: '邮箱',
directSignin: '已有账号?直接登录',
directSigninDueHasAccount: '已有账号?直接登录',
directSignin: '直接登录',
passwordResetOK: '密码已重置,请重新登录',
resetPassword: '重置密码',
bindPhone: '绑定手机',
bind: '绑定',
bound: '已绑定',
bindExAccount: '绑定已有账号',
unbind: '解绑',
inviteCode: '邀请码',
inviteCodeInputTips: '输入好友邀请码,获额外奖励(非必填)',
Expand Down Expand Up @@ -638,10 +657,20 @@ mixin AppLocale {
lastYear: '去年',
longTimeAgo: '很久以前',
modelNeedSignIn: '该模型需要登录后使用',
wechatBindConfirm: '该微信未绑定任何账号,是否直接登录?\n(自动创建账号)',
accountWillBeCreateAutomatically: '未注册的账号验证成功后将自动注册',
installWechatFirst: '请先安装微信后再使用该功能',
otherLoginMethods: '其它登录方式',
verifyAccount: '验证账号',
enterPasswordToSignin: '请输入密码完成登录。',
verifyCodeLogin: '验证码登录',
verifyCodeLoginTips: '请输入验证码以完成操作。',
usePasswordToSignin: '使用密码登录',
};

static const Map<String, dynamic> en = {
required: 'Required',
wechat: 'WeChat',
systemInfo: 'System',
save: 'Save',
ok: 'OK',
Expand Down Expand Up @@ -698,6 +727,7 @@ mixin AppLocale {
userTerms: 'User Terms',
privacyPolicy: 'Privacy Policy',
signIn: 'Sign In',
signInAccount: 'Unlock Full Features',
signOut: 'Sign Out',
signUp: 'Sign Up',
password: 'Password',
Expand Down Expand Up @@ -824,9 +854,9 @@ mixin AppLocale {
signInWithApple: 'Sign in with Apple',
readAndAgree: 'Read and agree',
andWord: 'and',
accountInputTips: 'Enter your phone number or email',
phoneInputTips: 'Enter your phone number',
passwordInputTips: 'Enter your password',
accountInputTips: 'Phone number or email',
phoneInputTips: 'Phone number',
passwordInputTips: 'Password',
pleaseReadAgreeProtocol: 'Please read and agree to the user agreement and privacy policy first',
signInSuccess: 'Sign in success',
signInFailed: 'Sign in failed',
Expand All @@ -837,6 +867,7 @@ mixin AppLocale {
passwordFormatError: 'Password format error\nMust be 8-20 digits, letters, special characters',
accountCreated: 'Account created',
sendVerifyCode: 'Send',
verify: 'Verify',
verifyCode: 'Verify code',
verifyCodeInputTips: 'Enter verify code',
retryInSeconds: 'Retry in',
Expand All @@ -846,12 +877,14 @@ mixin AppLocale {
verifyCodeFormatError: 'Verification code format error',
phone: 'Phone',
email: 'Email',
directSignin: 'Already have an account? Sign in directly',
directSigninDueHasAccount: 'Already have an account? Sign in directly',
directSignin: 'Sign in directly',
passwordResetOK: 'Password has been reset, please log in again',
resetPassword: 'Reset password',
bindPhone: 'Bind phone',
bind: 'Bind',
bound: 'Bound',
bindExAccount: 'Bind existing account',
unbind: 'Unbind',
inviteCode: 'Invite code',
inviteCodeInputTips: 'Enter friend invite code, get extra rewards (optional)',
Expand Down Expand Up @@ -954,6 +987,16 @@ mixin AppLocale {
longTimeAgo: 'Long Time Ago',
weeksAgo: 'Weeks Ago',
modelNeedSignIn: 'The model needs to be signed in to use',
wechatBindConfirm:
'The WeChat is not bound to any account, whether to sign in directly?\n(Automatically create an account)',
accountWillBeCreateAutomatically: 'Account will be created automatically',
installWechatFirst: 'Please install WeChat first',
otherLoginMethods: 'Other Login Methods',
verifyAccount: 'Verify Account',
enterPasswordToSignin: 'Please enter the password to sign in.',
verifyCodeLogin: 'Use Verify Code',
verifyCodeLoginTips: 'Please enter the verify code to complete the operation.',
usePasswordToSignin: 'Use Password',
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ void main() async {
try {
await migrate(db, oldVersion, newVersion);
} catch (e) {
Logger.instance.e('数据库升级失败', error: e);
Logger.instance.e('Database upgrade failure', error: e);
}
},
onCreate: initDatabase,
onOpen: (db) {
Logger.instance.i('数据库存储路径:${db.path}');
Logger.instance.i('Database storage path: ${db.path}');
},
),
);
Expand Down Expand Up @@ -217,7 +217,7 @@ void main() async {
final capabilities = await APIServer().capabilities(cache: false);
Ability().init(settingRepo, capabilities);
} catch (e) {
Logger.instance.e('获取客户端能力清单失败', error: e);
Logger.instance.e('Failed to get the client capability manifest', error: e);
Ability().init(
settingRepo,
Capabilities(
Expand Down
14 changes: 7 additions & 7 deletions lib/page/auth/signin_or_signup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ class _SigninOrSignupScreenState extends State<SigninOrSignupScreen> {
appBar: AppBar(
toolbarHeight: CustomSize.toolbarHeight,
backgroundColor: Colors.transparent,
title: const Text(
'验证账号',
style: TextStyle(fontSize: CustomSize.appBarTitleSize),
title: Text(
AppLocale.verifyAccount.getString(context),
style: const TextStyle(fontSize: CustomSize.appBarTitleSize),
),
centerTitle: true,
leading: IconButton(
Expand Down Expand Up @@ -112,7 +112,7 @@ class _SigninOrSignupScreenState extends State<SigninOrSignupScreen> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20),
child: Text(
'请使用 ${widget.username} 的密码进行登录。',
AppLocale.enterPasswordToSignin.getString(context),
style: TextStyle(
color: customColors.weakTextColor?.withAlpha(200),
fontSize: 15,
Expand Down Expand Up @@ -189,7 +189,7 @@ class _SigninOrSignupScreenState extends State<SigninOrSignupScreen> {
});
},
child: Text(
'验证码登录',
AppLocale.verifyCodeLogin.getString(context),
style: TextStyle(
color: customColors.weakLinkColor?.withAlpha(120),
fontSize: 14,
Expand Down Expand Up @@ -226,7 +226,7 @@ class _SigninOrSignupScreenState extends State<SigninOrSignupScreen> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 20),
child: Text(
'请发送验证码至 ${widget.username} 以完成操作。',
AppLocale.verifyCodeLoginTips.getString(context),
style: TextStyle(
color: customColors.weakTextColor,
fontSize: 15,
Expand Down Expand Up @@ -313,7 +313,7 @@ class _SigninOrSignupScreenState extends State<SigninOrSignupScreen> {
});
},
child: Text(
'使用密码登录',
AppLocale.usePasswordToSignin.getString(context),
style: TextStyle(
color: customColors.weakLinkColor?.withAlpha(120),
fontSize: 14,
Expand Down
25 changes: 11 additions & 14 deletions lib/page/auth/signin_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,16 @@ class _SignInScreenState extends State<SignInScreen> {
await showBeautyDialog(
context,
type: QuickAlertType.confirm,
title: '提示',
text: '该微信未绑定任何账号,是否直接登录?\n(自动创建账号)',
confirmBtnText: '直接登录',
title: AppLocale.tips.getString(context),
text: AppLocale.wechatBindConfirm.getString(context),
confirmBtnText: AppLocale.directSignin.getString(context),
onConfirmBtnTap: () async {
await confirmWeChatSignin(tryRes.token);
// ignore: use_build_context_synchronously
context.pop();
},
showCancelBtn: true,
cancelBtnText: '绑定已有账号',
cancelBtnText: AppLocale.bindExAccount.getString(context),
onCancelBtnTap: () {
setState(() {
wechatBindToken = tryRes.token;
Expand Down Expand Up @@ -213,9 +213,6 @@ class _SignInScreenState extends State<SignInScreen> {
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: customColors.linkColor ?? Colors.green),
),
floatingLabelStyle: TextStyle(
color: customColors.linkColor ?? Colors.green,
),
isDense: true,
floatingLabelBehavior: FloatingLabelBehavior.always,
labelText: AppLocale.account.getString(context),
Expand All @@ -234,7 +231,7 @@ class _SignInScreenState extends State<SignInScreen> {
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Text(
'未注册的账号验证成功后将自动注册',
AppLocale.accountWillBeCreateAutomatically.getString(context),
style: TextStyle(
color: customColors.weakTextColor?.withAlpha(80),
fontSize: 14,
Expand All @@ -250,9 +247,9 @@ class _SignInScreenState extends State<SignInScreen> {
decoration: BoxDecoration(color: customColors.linkColor, borderRadius: CustomSize.borderRadius),
child: TextButton(
onPressed: onSigninSubmit,
child: const Text(
'验证',
style: TextStyle(color: Colors.white, fontSize: 18),
child: Text(
AppLocale.verify.getString(context),
style: const TextStyle(color: Colors.white, fontSize: 18),
),
),
),
Expand Down Expand Up @@ -426,11 +423,11 @@ class _SignInScreenState extends State<SignInScreen> {

final ok = await sendWeChatAuth(scope: "snsapi_userinfo", state: "wechat_sdk_demo_test");
if (!ok) {
showErrorMessage('请先安装微信后再使用该功能');
showErrorMessage(AppLocale.installWechatFirst.getString(context));
}
},
backgroundColor: Colors.green,
text: '微信',
text: AppLocale.wechat.getString(context),
icon: Icons.wechat,
));
}
Expand All @@ -443,7 +440,7 @@ class _SignInScreenState extends State<SignInScreen> {
return Column(
children: [
Text(
'其它登录方式',
AppLocale.otherLoginMethods.getString(context),
style: TextStyle(
fontSize: 13,
color: customColors.weakTextColor?.withAlpha(80),
Expand Down
2 changes: 1 addition & 1 deletion lib/page/auth/signup_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class _SignupScreenState extends State<SignupScreen> {
}
},
child: Text(
AppLocale.directSignin.getString(context),
AppLocale.directSigninDueHasAccount.getString(context),
style: TextStyle(
color: customColors.linkColor,
fontSize: 14,
Expand Down
Loading

0 comments on commit d0e2b1b

Please sign in to comment.