-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathmanage_app_actions.dart
More file actions
executable file
Β·179 lines (168 loc) Β· 5.85 KB
/
manage_app_actions.dart
File metadata and controls
executable file
Β·179 lines (168 loc) Β· 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import 'package:app_center/constants.dart';
import 'package:app_center/l10n.dart';
import 'package:app_center/layout.dart';
import 'package:app_center/manage/app_providers.dart';
import 'package:app_center/manage/local_deb_providers.dart';
import 'package:app_center/manage/local_deb_updates_model.dart';
import 'package:app_center/manage/manage_app_data.dart';
import 'package:app_center/manage/quit_to_update_notice.dart';
import 'package:app_center/snapd/snapd.dart';
import 'package:app_center/widgets/active_change_content.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:snapd/snapd.dart';
import 'package:yaru/yaru.dart';
/// Renders the action buttons (open, update, remove, cancel) for a manage page
/// tile. Dispatches to snap- or deb-specific layouts based on the [app] type.
///
/// When [showOnlyUpdate] is true, only the update button is shown (used in the
/// updates section). Otherwise the full set of actions is displayed (used in the
/// installed section).
class ManageAppActions extends ConsumerWidget {
const ManageAppActions({
required this.app,
this.showOnlyUpdate = false,
super.key,
});
final ManageAppData app;
final bool showOnlyUpdate;
@override
Widget build(BuildContext context, WidgetRef ref) {
final l10n = AppLocalizations.of(context);
return app.map(
snap: (snapData) => _buildSnapActions(
context,
ref,
l10n,
snapData.snap,
snapData.updateVersion,
),
localDeb: (debData) =>
_buildDebActions(context, ref, l10n, debData.debInfo),
);
}
/// Builds snap action buttons. Uses data from [snap] directly for display
/// decisions to avoid creating per-snap [SnapModel] instances on each tile.
/// Only creates a [SnapModel] when an action is actually performed.
Widget _buildSnapActions(
BuildContext context,
WidgetRef ref,
AppLocalizations l10n,
Snap snap,
String? updateVersion,
) {
final currentlyInstalling = ref.watch(currentlyInstallingModelProvider);
final activeChangeData = currentlyInstalling[snap.name];
final hasActiveChange = activeChangeData?.activeChangeId != null;
if (hasActiveChange) {
return ActiveChangeStatus(
snapName: snap.name,
activeChangeId: activeChangeData!.activeChangeId!,
);
}
final shouldQuitToUpdate = snap.refreshInhibit != null;
final canOpen = snap.apps.isNotEmpty;
final hasUpdate = updateVersion != null;
return Row(
mainAxisSize: MainAxisSize.min,
children: [
if (shouldQuitToUpdate) ...[
const QuitToUpdateNotice(),
const SizedBox(width: kSpacing),
],
if (showOnlyUpdate)
OutlinedButton(
onPressed: () => ref
.read(snapModelProvider(snap.name).notifier)
.refresh()
.then((_) {}),
child: Text(SnapAction.update.label(l10n)),
),
if (!showOnlyUpdate) ...[
OutlinedButton(
onPressed: canOpen
? () {
final launcher = ref.read(launchProvider(snap));
if (launcher.isLaunchable) launcher.open();
}
: null,
child: Text(SnapAction.open.label(l10n)),
),
const SizedBox(width: kSpacing),
OutlinedButton(
onPressed: () =>
ref.read(snapModelProvider(snap.name).notifier).remove(),
child: Text(SnapAction.remove.label(l10n)),
),
],
],
);
}
/// Builds deb action buttons. Shows a progress indicator with a cancel button
/// when a PackageKit transaction is active, or update/remove buttons otherwise.
///
/// Cancel and update/remove are routed to [LocalDebUpdatesModel] (updates section)
/// or [InstalledApps] (installed section) depending on [showOnlyUpdate].
Widget _buildDebActions(
BuildContext context,
WidgetRef ref,
AppLocalizations l10n,
LocalDebInfo debInfo,
) {
final hasActiveTransaction = debInfo.activeTransactionId != null;
if (hasActiveTransaction) {
final progress = ref
.watch(debTransactionProgressProvider(debInfo.activeTransactionId));
return Row(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox.square(
dimension: kLoaderHeight,
child: YaruCircularProgressIndicator(
value: progress,
strokeWidth: 2,
),
),
const SizedBox(width: kSpacingSmall),
Text(
showOnlyUpdate
? l10n.snapActionUpdatingLabel
: l10n.snapActionRemovingLabel,
style: Theme.of(context).textTheme.bodyMedium,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(width: kSpacing),
OutlinedButton(
onPressed: () => showOnlyUpdate
? ref
.read(localDebUpdatesModelProvider.notifier)
.cancelTransaction(debInfo.id)
: ref
.read(installedAppsProvider.notifier)
.cancelDebTransaction(debInfo.id),
child: Text(l10n.snapActionCancelLabel),
),
],
);
}
return Row(
mainAxisSize: MainAxisSize.min,
children: [
if (showOnlyUpdate)
OutlinedButton(
onPressed: () => ref
.read(localDebUpdatesModelProvider.notifier)
.updateDeb(debInfo.id),
child: Text(l10n.snapActionUpdateLabel),
),
if (!showOnlyUpdate)
OutlinedButton(
onPressed: () =>
ref.read(installedAppsProvider.notifier).removeDeb(debInfo.id),
child: Text(l10n.snapActionRemoveLabel),
),
],
);
}
}