From 9d1df94f8910a9624336d0ce98160a05ea271272 Mon Sep 17 00:00:00 2001 From: lollipopkit Date: Sun, 21 Apr 2024 00:20:49 +0800 Subject: [PATCH] new: use browser to upgrade --- lib/core/update.dart | 111 ++++++++++++++++++++------------------ lib/view/page/editor.dart | 4 +- 2 files changed, 59 insertions(+), 56 deletions(-) diff --git a/lib/core/update.dart b/lib/core/update.dart index 8b7351e3..96f16602 100644 --- a/lib/core/update.dart +++ b/lib/core/update.dart @@ -86,59 +86,12 @@ Future _doUpdate(AppUpdate update, BuildContext context) async { } if (isAndroid) { - final inAppUpdate = Stores.setting.inAppUpdate; - var remember = true; - if (inAppUpdate.fetch() == 0) { - final cancel = await context.showRoundDialog( - title: Text(l10n.attention), - child: StatefulBuilder(builder: (_, setState) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Text(l10n.inAppUpdate, style: UIs.text15Bold), - CheckboxListTile( - contentPadding: EdgeInsets.zero, - value: remember, - onChanged: (v) => setState(() => remember = v ?? true), - title: Text(l10n.rememberChoice), - ), - ], - ); - }), - actions: [ - TextButton( - onPressed: () => context.pop(true), child: Text(l10n.cancel)), - TextButton( - onPressed: () { - if (remember) { - inAppUpdate.put(1); - } - context.pop(); - }, - child: const Text('App'), - ), - TextButton( - onPressed: () { - if (remember) { - inAppUpdate.put(2); - } - context.pop(); - }, - child: Text(l10n.browser), - ), - ], - ); - if (cancel != false) { - return; - } - } - if (inAppUpdate.fetch() == 2) { - await openUrl(url); - return; - } - final fileName = url.split('/').last; - await RUpgrade.upgrade(url, fileName: fileName); + 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 { @@ -146,6 +99,58 @@ Future _doUpdate(AppUpdate update, BuildContext context) async { } } +Future _openUrlUpdate(BuildContext context) async { + final inAppUpdate = Stores.setting.inAppUpdate; + final val = inAppUpdate.fetch(); + if (val == 0) { + var remember = true; + final selection = await context.showRoundDialog( + title: Text(l10n.attention), + child: StatefulBuilder(builder: (_, setState) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text(l10n.inAppUpdate, style: UIs.text15Bold), + CheckboxListTile( + contentPadding: EdgeInsets.zero, + value: remember, + onChanged: (v) => setState(() => remember = v ?? true), + title: Text(l10n.rememberChoice), + ), + ], + ); + }), + actions: [ + TextButton( + onPressed: () => context.pop(0), + child: Text(l10n.cancel), + ), + TextButton( + onPressed: () { + if (remember) { + inAppUpdate.put(1); + } + context.pop(1); + }, + child: const Text('App'), + ), + TextButton( + onPressed: () { + if (remember) { + inAppUpdate.put(2); + } + context.pop(2); + }, + child: Text(l10n.browser), + ), + ], + ); + return selection; + } + return val; +} + // rmdir Download Future _rmDownloadApks() async { if (!isAndroid) return; diff --git a/lib/view/page/editor.dart b/lib/view/page/editor.dart index 69d67dee..c6265cca 100644 --- a/lib/view/page/editor.dart +++ b/lib/view/page/editor.dart @@ -167,9 +167,7 @@ class _EditorPageState extends State { Widget _buildBody() { return SingleChildScrollView( child: CodeTheme( - data: CodeThemeData( - styles: _codeTheme, - ), + data: CodeThemeData(styles: _codeTheme), child: CodeField( wrap: Stores.setting.editorSoftWrap.fetch(), focusNode: _focusNode,