new: use browser to upgrade

This commit is contained in:
lollipopkit
2024-04-21 00:20:49 +08:00
parent 0f226b3620
commit 9d1df94f89
2 changed files with 59 additions and 56 deletions

View File

@@ -86,10 +86,25 @@ Future<void> _doUpdate(AppUpdate update, BuildContext context) async {
} }
if (isAndroid) { if (isAndroid) {
final useBrowser = await _openUrlUpdate(context);
final _ = switch (useBrowser) {
1 => await RUpgrade.upgrade(url, fileName: url.split('/').last),
2 => await openUrl(url),
_ => null,
};
} else if (isIOS) {
await RUpgrade.upgradeFromAppStore('1586449703');
} else {
await openUrl(url);
}
}
Future<int?> _openUrlUpdate(BuildContext context) async {
final inAppUpdate = Stores.setting.inAppUpdate; final inAppUpdate = Stores.setting.inAppUpdate;
final val = inAppUpdate.fetch();
if (val == 0) {
var remember = true; var remember = true;
if (inAppUpdate.fetch() == 0) { final selection = await context.showRoundDialog<int>(
final cancel = await context.showRoundDialog(
title: Text(l10n.attention), title: Text(l10n.attention),
child: StatefulBuilder(builder: (_, setState) { child: StatefulBuilder(builder: (_, setState) {
return Column( return Column(
@@ -108,13 +123,15 @@ Future<void> _doUpdate(AppUpdate update, BuildContext context) async {
}), }),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => context.pop(true), child: Text(l10n.cancel)), onPressed: () => context.pop(0),
child: Text(l10n.cancel),
),
TextButton( TextButton(
onPressed: () { onPressed: () {
if (remember) { if (remember) {
inAppUpdate.put(1); inAppUpdate.put(1);
} }
context.pop(); context.pop(1);
}, },
child: const Text('App'), child: const Text('App'),
), ),
@@ -123,27 +140,15 @@ Future<void> _doUpdate(AppUpdate update, BuildContext context) async {
if (remember) { if (remember) {
inAppUpdate.put(2); inAppUpdate.put(2);
} }
context.pop(); context.pop(2);
}, },
child: Text(l10n.browser), child: Text(l10n.browser),
), ),
], ],
); );
if (cancel != false) { return selection;
return;
}
}
if (inAppUpdate.fetch() == 2) {
await openUrl(url);
return;
}
final fileName = url.split('/').last;
await RUpgrade.upgrade(url, fileName: fileName);
} else if (isIOS) {
await RUpgrade.upgradeFromAppStore('1586449703');
} else {
await openUrl(url);
} }
return val;
} }
// rmdir Download // rmdir Download

View File

@@ -167,9 +167,7 @@ class _EditorPageState extends State<EditorPage> {
Widget _buildBody() { Widget _buildBody() {
return SingleChildScrollView( return SingleChildScrollView(
child: CodeTheme( child: CodeTheme(
data: CodeThemeData( data: CodeThemeData(styles: _codeTheme),
styles: _codeTheme,
),
child: CodeField( child: CodeField(
wrap: Stores.setting.editorSoftWrap.fetch(), wrap: Stores.setting.editorSoftWrap.fetch(),
focusNode: _focusNode, focusNode: _focusNode,