From adaa1ed678d946af8cca669becc03f3ea3d1cafc Mon Sep 17 00:00:00 2001 From: mylxsw Date: Tue, 16 Jan 2024 15:31:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E7=AB=AF=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E8=AF=8A=E6=96=AD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/helper/env.dart | 18 +++++++++--------- lib/main.dart | 20 ++++++++++++-------- lib/page/setting/setting_screen.dart | 27 ++++++++++++++++----------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/lib/helper/env.dart b/lib/helper/env.dart index 67b6c17c..953bbfee 100644 --- a/lib/helper/env.dart +++ b/lib/helper/env.dart @@ -1,5 +1,7 @@ import 'dart:io' show Platform; +import 'package:askaide/helper/platform.dart'; + /// 默认 API 服务器地址 /// 注意:当你使用自己的服务器时,请修改该地址为你自己的服务器地址 const defaultAPIServerURL = 'https://ai-api.aicode.cc'; @@ -20,14 +22,12 @@ String get apiServerURL { } String get getDbBasePath { - String home=''; Map envVars = Platform.environment; - if (Platform.isMacOS) { - home = envVars['HOME']!; - } else if (Platform.isLinux) { - home = envVars['HOME']!; - } else if (Platform.isWindows) { - home = envVars['UserProfile']!; + if (PlatformTool.isMacOS() || PlatformTool.isLinux()) { + return envVars['HOME'] ?? ''; + } else if (PlatformTool.isWindows()) { + return envVars['UserProfile'] ?? ''; } - return home; -} \ No newline at end of file + + return ''; +} diff --git a/lib/main.dart b/lib/main.dart index 468ebf36..3307aa1e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -111,15 +111,19 @@ void main() async { MediaKit.ensureInitialized(); httpx.HttpClient.init(); - // FlutterError.onError = (FlutterErrorDetails details) { - // if (details.library == 'rendering library' || - // details.library == 'image resource service') { - // return; - // } + FlutterError.onError = (FlutterErrorDetails details) { + if (details.library == 'rendering library' || + details.library == 'image resource service') { + return; + } - // Logger.instance.e(details.summary, details.exception, details.stack); - // print(details.stack); - // }; + Logger.instance.e( + details.summary, + error: details.exception, + stackTrace: details.stack, + ); + print(details.stack); + }; if (kIsWeb) { databaseFactory = databaseFactoryFfiWeb; diff --git a/lib/page/setting/setting_screen.dart b/lib/page/setting/setting_screen.dart index ffff7049..7cf4a4a5 100644 --- a/lib/page/setting/setting_screen.dart +++ b/lib/page/setting/setting_screen.dart @@ -186,6 +186,8 @@ class _SettingScreenState extends State { final databasePath = await databaseFactory.getDatabasesPath(); + Logger.instance.d('databasePath: $databasePath'); + // 删除数据库目录 await Directory(databasePath).delete( recursive: true, @@ -209,17 +211,20 @@ class _SettingScreenState extends State { }, ), // 诊断 - // SettingsTile( - // title: Text(AppLocale.diagnostic.getString(context)), - // trailing: Icon( - // CupertinoIcons.chevron_forward, - // size: MediaQuery.of(context).textScaleFactor * 18, - // color: Colors.grey, - // ), - // onPressed: (context) { - // context.push('/diagnosis'); - // }, - // ), + if (PlatformTool.isMacOS() || + PlatformTool.isLinux() || + PlatformTool.isWindows()) + SettingsTile( + title: Text(AppLocale.diagnostic.getString(context)), + trailing: Icon( + CupertinoIcons.chevron_forward, + size: MediaQuery.of(context).textScaleFactor * 18, + color: Colors.grey, + ), + onPressed: (context) { + context.push('/diagnosis'); + }, + ), // 检查更新 if (!PlatformTool.isIOS()) SettingsTile(