Skip to content

Commit

Permalink
WizardRoute.onLoad to get updated SubscriptionInfo
Browse files Browse the repository at this point in the history
SubscriptionStatusPage is sensitive to the current SubscriptionInfo
coming from the background agent.
WizardRoute.onLoad is a natural place to get this kind of information.
Everytime the wizard loads this route, a gRPC call is done
to fetch the latest information.
As a side effect the buildStartup local function becomes simpler.
  • Loading branch information
CarlosNihelton committed Nov 21, 2023
1 parent 50790bb commit 35f819a
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions gui/packages/ubuntupro/lib/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,26 @@ class Pro4WindowsApp extends StatelessWidget {
onGenerateTitle: (context) => AppLocalizations.of(context).appTitle,
home: Builder(
builder: (context) {
return const Wizard(
return Wizard(
routes: {
Routes.startup: WizardRoute(builder: buildStartup),
Routes.startup: const WizardRoute(builder: buildStartup),
Routes.subscriptionStatus: WizardRoute(
builder: SubscriptionStatusPage.create,
onLoad: (_) async {
final client = getService<AgentApiClient>();
final subscriptionInfo =
context.read<ValueNotifier<SubscriptionInfo>>();
// TODO: Remove this try-catch once the agent stop crashing due lack of MS Store access
try {
subscriptionInfo.value =
await client.subscriptionInfo();
} on GrpcError catch (err) {
debugPrint('$err');
debugPrintStack(maxFrames: 20);
}
// never skip this page.
return true;
},
),
},
);
Expand All @@ -56,18 +71,7 @@ Widget buildStartup(BuildContext context) {
addrFileName: kAddrFileName,
agentLauncher: launch,
clientFactory: defaultClient,
onClient: (client) async {
registerServiceInstance<AgentApiClient>(client);
final subscriptionInfo =
context.read<ValueNotifier<SubscriptionInfo>>();
// TODO: Remove this try-catch once the agent stop crashing due lack of MS Store access
try {
subscriptionInfo.value = await client.subscriptionInfo();
} on GrpcError catch (err) {
debugPrint('$err');
debugPrintStack(maxFrames: 20);
}
},
onClient: registerServiceInstance<AgentApiClient>,
),
child: const StartupPage(),
);
Expand Down

0 comments on commit 35f819a

Please sign in to comment.