skip restart if existing veilidcore instance is running

This commit is contained in:
Brandon Vandegrift 2025-04-09 01:01:54 -04:00
parent 2344184620
commit 3640d32e02

View File

@ -46,42 +46,41 @@ class ProcessorRepository {
Stream<VeilidUpdate> 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<void> shutdown() async {