From 4c7bd601c4df4d03536e97e18e4b88d858330ad9 Mon Sep 17 00:00:00 2001 From: nea Date: Fri, 26 Aug 2022 01:08:13 +0200 Subject: Translations and DBUS???? for some reason. also make the whole thing not buildable for anyone aside from me lol --- .../moe/nea/notenoughupdates/NotEnoughUpdates.kt | 8 +++++++- .../nea/notenoughupdates/dbus/NEUDbusInterface.kt | 11 +++++++++++ .../moe/nea/notenoughupdates/dbus/NEUDbusObject.kt | 21 +++++++++++++++++++++ .../moe/nea/notenoughupdates/repo/RepoManager.kt | 3 +++ .../assets/notenoughupdates/lang/en_us.json | 9 +++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusInterface.kt create mode 100644 src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusObject.kt create mode 100644 src/main/resources/assets/notenoughupdates/lang/en_us.json (limited to 'src/main') diff --git a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt index bede38a..125bc86 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/NotEnoughUpdates.kt @@ -9,6 +9,7 @@ import io.ktor.client.plugins.contentnegotiation.* import io.ktor.serialization.kotlinx.json.* import kotlinx.coroutines.* import kotlinx.serialization.json.Json +import moe.nea.notenoughupdates.dbus.NEUDbusObject import moe.nea.notenoughupdates.gui.repoGui import moe.nea.notenoughupdates.repo.RepoManager import moe.nea.notenoughupdates.util.ConfigHolder @@ -25,6 +26,7 @@ import net.fabricmc.loader.api.metadata.ModMetadata import net.minecraft.commands.CommandBuildContext import net.minecraft.network.chat.Component import org.apache.logging.log4j.LogManager +import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder import java.nio.file.Files import java.nio.file.Path import kotlin.coroutines.EmptyCoroutineContext @@ -57,6 +59,8 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer { } val globalJob = Job() + val dbusConnection = DBusConnectionBuilder.forSessionBus() + .build() val coroutineScope = CoroutineScope(EmptyCoroutineContext + CoroutineName("NotEnoughUpdates")) + SupervisorJob(globalJob) val coroutineScopeIo = coroutineScope + Dispatchers.IO + SupervisorJob(globalJob) @@ -73,7 +77,7 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer { Command.SINGLE_SUCCESS }) .executes { - it.source.sendFeedback(Component.literal("Reloading repository from disk. This may lag a bit.")) + it.source.sendFeedback(Component.translatable("notenoughupdates.repo.reload.disk")) RepoManager.reload() Command.SINGLE_SUCCESS }) @@ -87,6 +91,8 @@ object NotEnoughUpdates : ModInitializer, ClientModInitializer { } override fun onInitialize() { + dbusConnection.requestBusName("moe.nea.notenoughupdates") + dbusConnection.exportObject(NEUDbusObject) RepoManager.initialize() ConfigHolder.registerEvents() ClientCommandRegistrationCallback.EVENT.register(this::registerCommands) diff --git a/src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusInterface.kt b/src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusInterface.kt new file mode 100644 index 0000000..28ff370 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusInterface.kt @@ -0,0 +1,11 @@ +package moe.nea.notenoughupdates.dbus + +import org.freedesktop.dbus.annotations.DBusInterfaceName +import org.freedesktop.dbus.interfaces.DBusInterface + +@DBusInterfaceName("moe.nea.NotEnoughUpdates") +interface NEUDbusInterface : DBusInterface { + fun sayHello(): String + fun getCurrentRepoCommit(): String + fun requestRepoReDownload() +} diff --git a/src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusObject.kt b/src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusObject.kt new file mode 100644 index 0000000..4e3d362 --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/dbus/NEUDbusObject.kt @@ -0,0 +1,21 @@ +package moe.nea.notenoughupdates.dbus + +import moe.nea.notenoughupdates.repo.RepoManager + +object NEUDbusObject : NEUDbusInterface { + override fun sayHello(): String { + return "Hello from NEU" + } + + override fun getCurrentRepoCommit(): String { + return RepoManager.currentDownloadedSha ?: "none" + } + + override fun requestRepoReDownload() { + RepoManager.launchAsyncUpdate() + } + + override fun getObjectPath(): String { + return "/moe/nea/NotEnoughUpdates" + } +} diff --git a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt index c515ff7..2c0b4ec 100644 --- a/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt +++ b/src/main/kotlin/moe/nea/notenoughupdates/repo/RepoManager.kt @@ -24,6 +24,8 @@ object RepoManager : ConfigHolder(serializer(), "repo", ::Co var branch: String = "dangerous", ) + val currentDownloadedSha by RepoDownloadManager::latestSavedVersionHash + var recentlyFailedToUpdateItemList = false val progressBar = ProgressBar("", null, 0).also { @@ -72,6 +74,7 @@ object RepoManager : ConfigHolder(serializer(), "repo", ::Co Minecraft.getInstance().player?.sendSystemMessage( Component.literal("Failed to reload repository. This will result in some mod features not working.") ) + CottonHud.remove(progressBar) exc.printStackTrace() } } diff --git a/src/main/resources/assets/notenoughupdates/lang/en_us.json b/src/main/resources/assets/notenoughupdates/lang/en_us.json new file mode 100644 index 0000000..4654199 --- /dev/null +++ b/src/main/resources/assets/notenoughupdates/lang/en_us.json @@ -0,0 +1,9 @@ +{ + "notenoughupdates": { + "repo": { + "reload": { + "disk": "Reloading repository from disk. This may lag a bit." + } + } + } +} -- cgit