Skip to content

Commit bb64081

Browse files
committed
Add option to copy link to clipboard
1 parent 729639e commit bb64081

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/main/kotlin/xyz/bluspring/unitytranslate/client/gui/OpenBrowserScreen.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import net.minecraft.client.resources.language.I18n
88
import net.minecraft.network.chat.Component
99
import net.minecraft.network.chat.FormattedText
1010
import xyz.bluspring.unitytranslate.UnityTranslate
11+
import xyz.bluspring.unitytranslate.config.UnityTranslateConfig
1112

1213
class OpenBrowserScreen(val address: String) : Screen(Component.empty()) {
1314
override fun init() {
@@ -16,14 +17,23 @@ class OpenBrowserScreen(val address: String) : Screen(Component.empty()) {
1617
addRenderableWidget(
1718
Button.builder(Component.translatable("unitytranslate.do_not_show_again")) {
1819
Util.getPlatform().openUri(address)
19-
UnityTranslate.config.client.openBrowserWithoutPrompt = true
20+
UnityTranslate.config.client.openBrowserWithoutPrompt = UnityTranslateConfig.TriState.TRUE
2021
UnityTranslate.saveConfig()
2122
this.onClose()
2223
}
2324
.pos(this.width / 2 - (Button.DEFAULT_WIDTH / 2), this.height - 20 - Button.DEFAULT_HEIGHT - 5 - Button.DEFAULT_HEIGHT - 15)
2425
.build()
2526
)
2627

28+
addRenderableWidget(
29+
Button.builder(Component.translatable("gui.copy_link_to_clipboard")) {
30+
this.minecraft!!.keyboardHandler.clipboard = address
31+
this.onClose()
32+
}
33+
.pos(this.width / 2 - (Button.DEFAULT_WIDTH / 2), this.height - 20 - Button.DEFAULT_HEIGHT - 5 - Button.DEFAULT_HEIGHT - 5 - Button.DEFAULT_HEIGHT - 15)
34+
.build()
35+
)
36+
2737
addRenderableWidget(
2838
Button.builder(Component.translatable("unitytranslate.open_browser.open_in_browser")) {
2939
Util.getPlatform().openUri(address)

src/main/kotlin/xyz/bluspring/unitytranslate/client/transcribers/browser/BrowserSpeechTranscriber.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import xyz.bluspring.unitytranslate.client.gui.OpenBrowserScreen
1919
import xyz.bluspring.unitytranslate.client.gui.RequestDownloadScreen
2020
import xyz.bluspring.unitytranslate.client.transcribers.SpeechTranscriber
2121
import xyz.bluspring.unitytranslate.client.transcribers.TranscriberType
22+
import xyz.bluspring.unitytranslate.config.UnityTranslateConfig
2223
import java.net.InetSocketAddress
2324

2425
class BrowserSpeechTranscriber(language: Language) : SpeechTranscriber(language) {
@@ -49,9 +50,9 @@ class BrowserSpeechTranscriber(language: Language) : SpeechTranscriber(language)
4950
val mc = Minecraft.getInstance()
5051

5152
if (socket.totalConnections <= 0 && UnityTranslate.config.client.enabled) {
52-
if (UnityTranslate.config.client.openBrowserWithoutPrompt) {
53+
if (UnityTranslate.config.client.openBrowserWithoutPrompt == UnityTranslateConfig.TriState.TRUE) {
5354
Util.getPlatform().openUri("http://127.0.0.1:$serverPort")
54-
} else {
55+
} else if (UnityTranslate.config.client.openBrowserWithoutPrompt == UnityTranslateConfig.TriState.DEFAULT) {
5556
Minecraft.getInstance().execute {
5657
if (mc.screen is RequestDownloadScreen) {
5758
(mc.screen as RequestDownloadScreen).parent = OpenBrowserScreen("http://127.0.0.1:$serverPort")

src/main/kotlin/xyz/bluspring/unitytranslate/config/UnityTranslateConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ data class UnityTranslateConfig(
1313
@Serializable
1414
data class ClientConfig(
1515
var enabled: Boolean = true,
16-
var openBrowserWithoutPrompt: Boolean = false,
16+
var openBrowserWithoutPrompt: TriState = TriState.DEFAULT,
1717
var muteTranscriptWhenVoiceChatMuted: Boolean = true,
1818

1919
@get:IntRange(from = 10, to = 300, increment = 10)

0 commit comments

Comments
 (0)