这是indexloc提供的服务,不要输入任何密码
Skip to content

feat: confirm before exit Play #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/i18n/aria/aria.i18n.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ enableFederation: "Enable federation"
enablePredictiveBack: "Enable predictive back animations"
enableSpellCheck: "Enable spell check"
endpoint: "Endpoint"
exitPlayConfirm: "Are you sure you want to exit the Play?"
expandNote: "Expand note"
extraMentionsWarning: "This note includes mentions that are not included in the target note of reply"
fileNotFound: "File not found"
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/strings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// To regenerate, run: `dart run slang`
///
/// Locales: 31
/// Strings: 57344 (1849 per locale)
/// Strings: 57345 (1849 per locale)

// coverage:ignore-file
// ignore_for_file: type=lint, unused_import
Expand Down
1 change: 1 addition & 0 deletions lib/i18n/strings_en_US.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class TranslationsAriaEnUs {
String get enablePredictiveBack => 'Enable predictive back animations';
String get enableSpellCheck => 'Enable spell check';
String get endpoint => 'Endpoint';
String get exitPlayConfirm => 'Are you sure you want to exit the Play?';
String get expandNote => 'Expand note';
String get extraMentionsWarning => 'This note includes mentions that are not included in the target note of reply';
String get fileNotFound => 'File not found';
Expand Down
18 changes: 10 additions & 8 deletions lib/view/page/drive_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ class DrivePage extends HookConsumerWidget {

return PopScope(
canPop: currentFolder == null && (selectFolder || selectedFiles.isEmpty),
onPopInvokedWithResult: (_, _) {
if (!selectFolder && selectedFiles.isNotEmpty) {
ref.read(selectedDriveFilesNotifierProvider.notifier).removeAll();
} else if (currentFolder != null) {
hierarchyFolders.value = hierarchyFolders.value.sublist(
0,
hierarchyFolders.value.length - 1,
);
onPopInvokedWithResult: (didPop, _) {
if (!didPop) {
if (!selectFolder && selectedFiles.isNotEmpty) {
ref.read(selectedDriveFilesNotifierProvider.notifier).removeAll();
} else if (currentFolder != null) {
hierarchyFolders.value = hierarchyFolders.value.sublist(
0,
hierarchyFolders.value.length - 1,
);
}
}
},
child: Scaffold(
Expand Down
18 changes: 10 additions & 8 deletions lib/view/page/image_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,16 @@ class ImagePage extends HookConsumerWidget {

return PopScope(
canPop: image == backgroundLayer.value.data && overlayLayers.isEmpty,
onPopInvokedWithResult: (_, _) async {
final confirmed = await confirm(
context,
message: t.aria.discardChangesConfirm,
);
if (!context.mounted) return;
if (confirmed) {
context.pop();
onPopInvokedWithResult: (didPop, _) async {
if (!didPop) {
final confirmed = await confirm(
context,
message: t.aria.discardChangesConfirm,
);
if (!context.mounted) return;
if (confirmed) {
context.pop();
}
}
},
child: Scaffold(
Expand Down
222 changes: 122 additions & 100 deletions lib/view/widget/play_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import '../../util/copy_text.dart';
import '../../util/future_with_dialog.dart';
import '../../util/launch_url.dart';
import '../../util/nyaize.dart';
import '../dialog/confirmation_dialog.dart';
import '../dialog/error_message_dialog.dart';
import '../dialog/text_field_dialog.dart';
import 'account_preview.dart';
Expand Down Expand Up @@ -66,111 +67,130 @@ class PlayWidget extends HookConsumerWidget {
duration: Durations.medium1,
child:
started.value
? Column(
children: [
Card(
margin: const EdgeInsets.symmetric(vertical: 8.0),
elevation: 0.0,
color: colors.panel,
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(32.0),
child: AsUiWidget(
account: account,
host: host,
componentId: '___root___',
components: components.value,
? PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) async {
if (!didPop) {
final shouldPop = await confirm(
context,
message: t.aria.exitPlayConfirm,
);
if (!context.mounted) return;
if (shouldPop) {
try {
await aiscript.value?.abort();
} catch (_) {}
if (!context.mounted) return;
context.pop();
}
}
},
child: Column(
children: [
Card(
margin: const EdgeInsets.symmetric(vertical: 8.0),
elevation: 0.0,
color: colors.panel,
child: Container(
width: double.infinity,
padding: const EdgeInsets.all(32.0),
child: AsUiWidget(
account: account,
host: host,
componentId: '___root___',
components: components.value,
),
),
),
),
Card(
margin: const EdgeInsets.symmetric(vertical: 8.0),
elevation: 0.0,
color: colors.panel,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
IconButton(
tooltip: t.misskey.reload,
onPressed: () async {
await aiscript.value?.abort();
started.value = false;
},
icon: const Icon(Icons.refresh),
),
Row(
children: [
LikeButton(
isLiked: play.isLiked,
likedCount: play.likedCount ?? 0,
onTap:
!account.isGuest && account.host == host
? () => futureWithDialog(
context,
play.isLiked
? ref
.read(
playNotifierProvider(
account,
play.id,
).notifier,
)
.unlike()
: ref
.read(
playNotifierProvider(
account,
play.id,
).notifier,
)
.like(),
)
: null,
),
const Spacer(),
if (!account.isGuest)
Card(
margin: const EdgeInsets.symmetric(vertical: 8.0),
elevation: 0.0,
color: colors.panel,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
IconButton(
tooltip: t.misskey.reload,
onPressed: () async {
await aiscript.value?.abort();
started.value = false;
},
icon: const Icon(Icons.refresh),
),
Row(
children: [
LikeButton(
isLiked: play.isLiked,
likedCount: play.likedCount ?? 0,
onTap:
!account.isGuest && account.host == host
? () => futureWithDialog(
context,
play.isLiked
? ref
.read(
playNotifierProvider(
account,
play.id,
).notifier,
)
.unlike()
: ref
.read(
playNotifierProvider(
account,
play.id,
).notifier,
)
.like(),
)
: null,
),
const Spacer(),
if (!account.isGuest)
IconButton(
tooltip: t.misskey.shareWithNote,
onPressed: () {
ref
.read(
postNotifierProvider(
account,
).notifier,
)
.setText('${play.title} $url');
context.push('/$account/post');
},
icon: const Icon(Icons.repeat_rounded),
),
IconButton(
tooltip: t.misskey.shareWithNote,
onPressed: () {
ref
.read(
postNotifierProvider(
account,
).notifier,
)
.setText('${play.title} $url');
context.push('/$account/post');
},
icon: const Icon(Icons.repeat_rounded),
tooltip: t.misskey.copyLink,
onPressed:
() => copyToClipboard(
context,
url.toString(),
),
icon: const Icon(Icons.link),
),
IconButton(
tooltip: t.misskey.copyLink,
onPressed:
() => copyToClipboard(
context,
url.toString(),
),
icon: const Icon(Icons.link),
),
IconButton(
tooltip: t.aria.openInBrowser,
onPressed: () => launchUrl(ref, url),
icon: const Icon(Icons.open_in_browser),
),
IconButton(
tooltip: t.misskey.share,
onPressed:
() => Share.share('${play.title} $url'),
icon: const Icon(Icons.share),
),
],
),
],
IconButton(
tooltip: t.aria.openInBrowser,
onPressed: () => launchUrl(ref, url),
icon: const Icon(Icons.open_in_browser),
),
IconButton(
tooltip: t.misskey.share,
onPressed:
() => Share.share('${play.title} $url'),
icon: const Icon(Icons.share),
),
],
),
],
),
),
),
),
],
],
),
)
: Card(
margin: const EdgeInsets.symmetric(vertical: 8.0),
Expand Down Expand Up @@ -416,7 +436,9 @@ class PlayWidget extends HookConsumerWidget {
started.value = true;
await aiscript.value?.exec(input: play.script);
} catch (e, st) {
await aiscript.value?.abort();
try {
await aiscript.value?.abort();
} catch (_) {}
if (!context.mounted) return;
await showErrorMessageDialog(
context,
Expand Down
Loading