[core] Handle UnsupportedOperationException on EncryptService initialize & add special signals

This commit is contained in:
Karlatemp 2023-07-03 20:33:19 +08:00
parent 96e93e670e
commit 685fb2d3d9
No known key found for this signature in database
GPG Key ID: BA173CA2B9956C59
2 changed files with 23 additions and 10 deletions

View File

@ -45,17 +45,27 @@ internal class EncryptServiceHolderImpl(
init {
EncryptService.factory?.let { globalService ->
service0 = globalService.createForBot(
EncryptServiceContext(bot.id, buildTypeSafeMap {
set(EncryptServiceContext.KEY_BOT_PROTOCOL, bot.configuration.protocol)
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
}),
try {
service0 = globalService.createForBot(
EncryptServiceContext(bot.id, buildTypeSafeMap {
set(EncryptServiceContext.KEY_BOT_PROTOCOL, bot.configuration.protocol)
set(EncryptServiceContext.KEY_DEVICE_INFO, ssoProcessorContext.device)
set(EncryptServiceContext.KEY_BOT_WORKING_DIR, bot.configuration.workingDirPath)
set(EncryptServiceContext.KEY_BOT_CACHING_DIR, bot.configuration.actualCacheDir().absolutePath)
}),
bot.childScope(name = "Encrypt Service"),
)
isAvailable = true
bot.childScope(name = "Encrypt Service"),
)
isAvailable = true
} catch (error: UnsupportedOperationException) {
bot.logger.warning("$globalService is not yet supported EncryptService with bot $bot", error)
isAvailable = false
service0 = null
} catch (_: EncryptService.SignalServiceNotAvailable) {
isAvailable = false
service0 = null
} /* catch (error: Throwable) { throw error } */ // crash bot initialize
}
}
}

View File

@ -122,4 +122,7 @@ public interface EncryptService {
return loader.service
}
}
// special error: no service used
public object SignalServiceNotAvailable : RuntimeException()
}