mirror of
https://ghfast.top/https://github.com/StarCitizenToolBox/app.git
synced 2025-06-28 12:34:45 +08:00
re init
This commit is contained in:
14
lib/ui/settings/settings_ui.dart
Normal file
14
lib/ui/settings/settings_ui.dart
Normal file
@ -0,0 +1,14 @@
|
||||
import 'package:starcitizen_doctor/base/ui.dart';
|
||||
import 'package:starcitizen_doctor/ui/settings/settings_ui_model.dart';
|
||||
|
||||
class SettingUI extends BaseUI<SettingUIModel> {
|
||||
@override
|
||||
Widget? buildBody(BuildContext context, SettingUIModel model) {
|
||||
return const Center(
|
||||
child: Text("暂时没啥好设置的。"),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String getUITitle(BuildContext context, SettingUIModel model) => "SettingUI";
|
||||
}
|
5
lib/ui/settings/settings_ui_model.dart
Normal file
5
lib/ui/settings/settings_ui_model.dart
Normal file
@ -0,0 +1,5 @@
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
|
||||
class SettingUIModel extends BaseUIModel {
|
||||
|
||||
}
|
85
lib/ui/settings/upgrade_dialog_ui.dart
Normal file
85
lib/ui/settings/upgrade_dialog_ui.dart
Normal file
@ -0,0 +1,85 @@
|
||||
import 'package:flutter/material.dart' show Material;
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf.dart';
|
||||
|
||||
import 'upgrade_dialog_ui_model.dart';
|
||||
|
||||
class UpgradeDialogUI extends BaseUI<UpgradeDialogUIModel> {
|
||||
@override
|
||||
Widget? buildBody(BuildContext context, UpgradeDialogUIModel model) {
|
||||
return Material(
|
||||
child: ContentDialog(
|
||||
title: const Text("发现新版本"),
|
||||
constraints:
|
||||
BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .55),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 24, right: 24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (model.description == null) ...[
|
||||
const Center(
|
||||
child: Column(
|
||||
children: [
|
||||
ProgressRing(),
|
||||
SizedBox(height: 16),
|
||||
Text("正在获取新版本详情...")
|
||||
],
|
||||
),
|
||||
)
|
||||
] else
|
||||
...makeMarkdownView(model.description!),
|
||||
],
|
||||
),
|
||||
),
|
||||
)),
|
||||
if (model.isUpgrading) ...[
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
children: [
|
||||
Text(model.progress == 100
|
||||
? "正在安装: "
|
||||
: "正在下载: ${model.progress?.toStringAsFixed(2) ?? 0}% "),
|
||||
Expanded(
|
||||
child: ProgressBar(
|
||||
value: model.progress == 100 ? null : model.progress,
|
||||
)),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: model.isUpgrading
|
||||
? null
|
||||
: [
|
||||
if (model.downloadUrl.isNotEmpty)
|
||||
FilledButton(
|
||||
onPressed: model.doUpgrade,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 4, bottom: 4, left: 8, right: 8),
|
||||
child: Text("立即更新"),
|
||||
)),
|
||||
if (AppConf.appVersionCode <=
|
||||
(AppConf.networkVersionData?.minVersionCode ?? 0))
|
||||
Button(
|
||||
onPressed: model.doCancel,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: 4, bottom: 4, left: 8, right: 8),
|
||||
child: Text("下次吧"),
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String getUITitle(BuildContext context, UpgradeDialogUIModel model) => "";
|
||||
}
|
72
lib/ui/settings/upgrade_dialog_ui_model.dart
Normal file
72
lib/ui/settings/upgrade_dialog_ui_model.dart
Normal file
@ -0,0 +1,72 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:starcitizen_doctor/api/api.dart';
|
||||
import 'package:starcitizen_doctor/base/ui_model.dart';
|
||||
import 'package:starcitizen_doctor/common/conf.dart';
|
||||
|
||||
class UpgradeDialogUIModel extends BaseUIModel {
|
||||
String? description;
|
||||
String downloadUrl = "";
|
||||
|
||||
bool isUpgrading = false;
|
||||
|
||||
double? progress;
|
||||
|
||||
@override
|
||||
Future loadData() async {
|
||||
// get download url for gitlab release
|
||||
try {
|
||||
final r = await Api.getAppReleaseDataByVersionName(
|
||||
AppConf.networkVersionData!.lastVersion!);
|
||||
description = r["description"];
|
||||
final assetsLinks = List.of(r["assets"]?["links"] ?? []);
|
||||
for (var link in assetsLinks) {
|
||||
if (link["name"].toString().contains("SETUP.exe")) {
|
||||
downloadUrl = link["direct_asset_url"];
|
||||
break;
|
||||
}
|
||||
}
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
Navigator.pop(context!, false);
|
||||
}
|
||||
}
|
||||
|
||||
doUpgrade() async {
|
||||
isUpgrading = true;
|
||||
notifyListeners();
|
||||
final fileName = "${AppConf.getUpgradePath()}/next_SETUP.exe";
|
||||
try {
|
||||
await Dio().download(downloadUrl, fileName,
|
||||
onReceiveProgress: (int count, int total) {
|
||||
progress = (count / total) * 100;
|
||||
notifyListeners();
|
||||
});
|
||||
} catch (_) {
|
||||
isUpgrading = false;
|
||||
progress = null;
|
||||
showToast(context!, "下载失败,请尝试手动安装!");
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
try {
|
||||
final r =
|
||||
await (Process.run("powershell", ["start", fileName, "/SILENT"]));
|
||||
if (r.stderr.toString().isNotEmpty) {
|
||||
throw r.stderr;
|
||||
}
|
||||
exit(0);
|
||||
} catch (_) {
|
||||
isUpgrading = false;
|
||||
progress = null;
|
||||
showToast(context!, "运行失败,请尝试手动安装!");
|
||||
Process.run("powershell.exe", ["explorer.exe", "/select,\"$fileName\""]);
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void doCancel() {
|
||||
Navigator.pop(context!, true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user