From 3640d32e028a28ed888ab3ce8610416cf9b6e76f Mon Sep 17 00:00:00 2001 From: Brandon Vandegrift <798832-bmv437@users.noreply.gitlab.com> Date: Wed, 9 Apr 2025 01:01:54 -0400 Subject: [PATCH] skip restart if existing veilidcore instance is running --- .../repository/processor_repository.dart | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/veilid_processor/repository/processor_repository.dart b/lib/veilid_processor/repository/processor_repository.dart index a92347c..9d5f39f 100644 --- a/lib/veilid_processor/repository/processor_repository.dart +++ b/lib/veilid_processor/repository/processor_repository.dart @@ -46,42 +46,41 @@ class ProcessorRepository { Stream updateStream; - try { + if (await Veilid.instance.isShutdown()) { log.debug('Starting VeilidCore'); updateStream = await Veilid.instance .startupVeilidCore(await getVeilidConfig(kIsWeb, VeilidChatApp.name)); - } on VeilidAPIExceptionAlreadyInitialized catch (_) { - log.debug( - 'VeilidCore is already started, shutting down and restarting...'); + + _updateSubscription = updateStream.listen((update) { + if (update is VeilidLog) { + processLog(update); + } else if (update is VeilidUpdateAttachment) { + processUpdateAttachment(update); + } else if (update is VeilidUpdateConfig) { + processUpdateConfig(update); + } else if (update is VeilidUpdateNetwork) { + processUpdateNetwork(update); + } else if (update is VeilidAppMessage) { + processAppMessage(update); + } else if (update is VeilidAppCall) { + log.info('AppCall: ${update.toJson()}'); + } else if (update is VeilidUpdateValueChange) { + processUpdateValueChange(update); + } else { + log.trace('Update: ${update.toJson()}'); + } + }); + startedUp = true; - await shutdown(); - updateStream = await Veilid.instance - .startupVeilidCore(await getVeilidConfig(kIsWeb, VeilidChatApp.name)); + + await Veilid.instance.attach(); + } else { + log.debug('VeilidCore is already started, skipping startup'); + startedUp = true; + // TODO: Need a way to get the updateStream and add a listener after it's already started. + // Without this, the app starts up, but things that depend on update stream never get notified. + // Example being the attachment state always shows the detached icon. } - - _updateSubscription = updateStream.listen((update) { - if (update is VeilidLog) { - processLog(update); - } else if (update is VeilidUpdateAttachment) { - processUpdateAttachment(update); - } else if (update is VeilidUpdateConfig) { - processUpdateConfig(update); - } else if (update is VeilidUpdateNetwork) { - processUpdateNetwork(update); - } else if (update is VeilidAppMessage) { - processAppMessage(update); - } else if (update is VeilidAppCall) { - log.info('AppCall: ${update.toJson()}'); - } else if (update is VeilidUpdateValueChange) { - processUpdateValueChange(update); - } else { - log.trace('Update: ${update.toJson()}'); - } - }); - - startedUp = true; - - await Veilid.instance.attach(); } Future shutdown() async {