Compare commits
No commits in common. "b9721f93c7fb0fa85b2800a73da95abd8d579c50" and "3d1729f630c37281a6ea37893e9a57906adb5705" have entirely different histories.
b9721f93c7
...
3d1729f630
|
|
@ -311,7 +311,6 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
autoDownload: true,
|
||||
autoInstall: false,
|
||||
installTimeout: 60,
|
||||
requireInstallPermission: false, // 不需要权限
|
||||
customToast: (message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
|
|
@ -322,25 +321,12 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
},
|
||||
));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('已配置自定义设置(无权限模式)')),
|
||||
const SnackBar(content: Text('已配置自定义设置')),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.settings),
|
||||
label: const Text('自定义配置'),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: _isLoading
|
||||
? null
|
||||
: () {
|
||||
AppUpgradeSimple.instance.configure(UpgradeConfig.withPermission);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('已启用权限模式')),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.security),
|
||||
label: const Text('启用权限模式'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -124,9 +124,6 @@ class UpgradeConfig {
|
|||
/// 自定义Toast显示函数
|
||||
final void Function(String message)? customToast;
|
||||
|
||||
/// 是否需要获取安装未知应用权限(默认false,直接安装)
|
||||
final bool requireInstallPermission;
|
||||
|
||||
const UpgradeConfig({
|
||||
this.showNoUpdateToast = true,
|
||||
this.autoDownload = false,
|
||||
|
|
@ -136,21 +133,18 @@ class UpgradeConfig {
|
|||
this.installTimeout = 45,
|
||||
this.enableDebugLog = true,
|
||||
this.customToast,
|
||||
this.requireInstallPermission = false, // 默认不需要权限
|
||||
});
|
||||
|
||||
/// 快速配置:自动更新(不需要权限)
|
||||
/// 快速配置:自动更新
|
||||
static const UpgradeConfig auto = UpgradeConfig(
|
||||
autoDownload: true,
|
||||
autoInstall: true,
|
||||
requireInstallPermission: false,
|
||||
);
|
||||
|
||||
/// 快速配置:静默检查
|
||||
static const UpgradeConfig silent = UpgradeConfig(
|
||||
showNoUpdateToast: false,
|
||||
enableDebugLog: false,
|
||||
requireInstallPermission: false,
|
||||
);
|
||||
|
||||
/// 快速配置:开发模式(详细日志 + 较短超时)
|
||||
|
|
@ -158,7 +152,6 @@ class UpgradeConfig {
|
|||
enableDebugLog: true,
|
||||
installTimeout: 30,
|
||||
connectionTimeout: 10,
|
||||
requireInstallPermission: false,
|
||||
);
|
||||
|
||||
/// 快速配置:生产模式(静默 + 较长超时)
|
||||
|
|
@ -167,12 +160,6 @@ class UpgradeConfig {
|
|||
enableDebugLog: false,
|
||||
installTimeout: 60,
|
||||
connectionTimeout: 30,
|
||||
requireInstallPermission: false,
|
||||
);
|
||||
|
||||
/// 快速配置:需要权限模式(传统方式)
|
||||
static const UpgradeConfig withPermission = UpgradeConfig(
|
||||
requireInstallPermission: true,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -604,22 +591,16 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
_statusText = '准备安装...';
|
||||
});
|
||||
|
||||
// 根据配置决定是否需要检查权限
|
||||
if (config.requireInstallPermission) {
|
||||
debugPrint('🔐 检查安装权限(配置要求)');
|
||||
final hasPermission = await PermissionHelper.checkAndRequestInstallPermission(context: context);
|
||||
if (!hasPermission) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isInstalling = false;
|
||||
_statusText = '权限被拒绝';
|
||||
});
|
||||
showToast('未授予安装权限,无法完成更新');
|
||||
}
|
||||
return;
|
||||
final hasPermission = await PermissionHelper.checkAndRequestInstallPermission(context: context);
|
||||
if (!hasPermission) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isInstalling = false;
|
||||
_statusText = '权限被拒绝';
|
||||
});
|
||||
showToast('未授予安装权限,无法完成更新');
|
||||
}
|
||||
} else {
|
||||
debugPrint('🚀 跳过权限检查,直接安装(配置默认)');
|
||||
return;
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
|
|
@ -638,7 +619,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
_isWaitingForInstallation = true;
|
||||
_statusText = '请完成安装';
|
||||
});
|
||||
showToast('请在系统弹窗中完成安装');
|
||||
showToast('请在系统弹窗中完成安装,完成后点击下方确认按钮');
|
||||
|
||||
// 启动定时检测(备用方案)
|
||||
_startInstallationTimeoutCheck();
|
||||
|
|
@ -767,8 +748,8 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
return;
|
||||
}
|
||||
|
||||
// 如果是权限被拒绝,且配置要求权限,先尝试重新请求权限
|
||||
if (_statusText == '权限被拒绝' && config.requireInstallPermission) {
|
||||
// 如果是权限被拒绝,先尝试重新请求权限
|
||||
if (_statusText == '权限被拒绝') {
|
||||
final hasPermission = await PermissionHelper.checkAndRequestInstallPermission(context: context);
|
||||
if (!hasPermission) {
|
||||
showToast('仍未获得安装权限,请在设置中手动开启');
|
||||
|
|
@ -1413,7 +1394,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
|
||||
/// 获取重试按钮图标
|
||||
IconData _getRetryButtonIcon() {
|
||||
if (_statusText == '权限被拒绝' && config.requireInstallPermission) {
|
||||
if (_statusText == '权限被拒绝') {
|
||||
return Icons.settings;
|
||||
} else if (_statusText == '安装失败' ||
|
||||
_statusText == '安装异常' ||
|
||||
|
|
@ -1433,7 +1414,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
|
||||
/// 获取重试按钮文本
|
||||
String _getRetryButtonText() {
|
||||
if (_statusText == '权限被拒绝' && config.requireInstallPermission) {
|
||||
if (_statusText == '权限被拒绝') {
|
||||
return '设置';
|
||||
} else if (_statusText == '安装失败' ||
|
||||
_statusText == '安装异常' ||
|
||||
|
|
@ -1471,7 +1452,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
return _statusText == '安装被取消' ||
|
||||
_statusText == '安装失败' ||
|
||||
_statusText == '安装异常' ||
|
||||
(_statusText == '权限被拒绝' && config.requireInstallPermission) ||
|
||||
_statusText == '权限被拒绝' ||
|
||||
_statusText == '安装超时' ||
|
||||
_statusText == '检测失败' ||
|
||||
_statusText == '等待安装中' ||
|
||||
|
|
@ -1499,7 +1480,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
case '安装被取消':
|
||||
return '点击重新安装';
|
||||
case '权限被拒绝':
|
||||
return config.requireInstallPermission ? '点击打开设置' : '点击重试';
|
||||
return '点击打开设置';
|
||||
case '安装超时':
|
||||
return '点击重新尝试';
|
||||
default:
|
||||
|
|
|
|||
Loading…
Reference in New Issue