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