Skip to content

Commit dfa412a

Browse files
THCFreebeanbag44Avanatiker
authored
Feat: Add auto updater wizard (#233)
### Description Adds Auto Updater module which installs Lambda loader which automatically loads latest version of lambda client depending on the selected release channel also uninstalls the loader and replaces it with the latest version of lambda for the current version when disabled. The module prompts the user trough a modal before installing / uninstalling since the process requires a client restart --------- Co-authored-by: beanbag44 <107891830+beanbag44@users.noreply.github.com> Co-authored-by: Constructor <fractalminds@protonmail.com>
1 parent 28b0d77 commit dfa412a

File tree

4 files changed

+399
-10
lines changed

4 files changed

+399
-10
lines changed

src/main/java/com/lambda/mixin/render/ScreenMixin.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.mixin.render;
1919

2020
import com.lambda.gui.components.QuickSearch;
21+
import com.lambda.module.modules.client.AutoUpdater;
2122
import com.lambda.module.modules.render.ContainerPreview;
2223
import com.lambda.module.modules.render.NoRender;
2324
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
@@ -37,9 +38,19 @@
3738
public class ScreenMixin {
3839
@Inject(method = "keyPressed", at = @At("HEAD"), cancellable = true)
3940
private void onKeyPressed(KeyInput input, CallbackInfoReturnable<Boolean> cir) {
40-
if (input.key() == GLFW.GLFW_KEY_ESCAPE && QuickSearch.INSTANCE.isOpen()) {
41-
QuickSearch.INSTANCE.close();
42-
cir.setReturnValue(true);
41+
if (input.key() == GLFW.GLFW_KEY_ESCAPE) {
42+
if (QuickSearch.INSTANCE.isOpen()) {
43+
QuickSearch.INSTANCE.close();
44+
cir.setReturnValue(true);
45+
} else if (AutoUpdater.getShowInstallModal()) {
46+
AutoUpdater.INSTANCE.disable();
47+
AutoUpdater.setShowInstallModal(false);
48+
cir.setReturnValue(true);
49+
} else if (AutoUpdater.getShowUninstallModal()) {
50+
AutoUpdater.INSTANCE.enable();
51+
AutoUpdater.setShowUninstallModal(false);
52+
cir.setReturnValue(true);
53+
}
4354
}
4455
}
4556

src/main/kotlin/com/lambda/gui/components/QuickSearch.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.lambda.gui.dsl.ImGuiBuilder
3131
import com.lambda.module.HudModule
3232
import com.lambda.module.Module
3333
import com.lambda.module.ModuleRegistry
34+
import com.lambda.module.modules.client.AutoUpdater
3435
import com.lambda.util.KeyCode
3536
import com.lambda.util.StringUtils.capitalize
3637
import com.lambda.util.StringUtils.levenshteinDistance
@@ -54,12 +55,13 @@ object QuickSearch {
5455

5556
private const val DOUBLE_SHIFT_WINDOW_MS = 500L
5657
private const val MAX_RESULTS = 50
57-
private const val WINDOW_FLAGS = ImGuiWindowFlags.AlwaysAutoResize or
58-
ImGuiWindowFlags.NoTitleBar or
59-
ImGuiWindowFlags.NoMove or
60-
ImGuiWindowFlags.NoResize or
61-
ImGuiWindowFlags.NoScrollbar or
62-
ImGuiWindowFlags.NoScrollWithMouse
58+
const val WINDOW_FLAGS =
59+
ImGuiWindowFlags.AlwaysAutoResize or
60+
ImGuiWindowFlags.NoTitleBar or
61+
ImGuiWindowFlags.NoMove or
62+
ImGuiWindowFlags.NoResize or
63+
ImGuiWindowFlags.NoScrollbar or
64+
ImGuiWindowFlags.NoScrollWithMouse
6365

6466
init {
6567
listenUnsafe<ButtonEvent.Keyboard.Press> { event ->
@@ -303,6 +305,7 @@ object QuickSearch {
303305
}
304306

305307
private fun handleKeyPress(event: ButtonEvent.Keyboard.Press) {
308+
if (AutoUpdater.showInstallModal || AutoUpdater.showUninstallModal) return
306309
if ((!event.isPressed || event.isRepeated) ||
307310
!(event.keyCode == KeyCode.LeftShift.code || event.keyCode == KeyCode.RightShift.code)) return
308311

src/main/kotlin/com/lambda/gui/components/SettingsWidget.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import com.lambda.config.configurations.UserAutomationConfigs
2626
import com.lambda.gui.dsl.ImGuiBuilder
2727
import com.lambda.module.HudModule
2828
import com.lambda.module.Module
29+
import com.lambda.module.modules.client.AutoUpdater
2930
import com.lambda.util.NamedEnum
3031
import imgui.ImGui
3132
import imgui.flag.ImGuiPopupFlags
@@ -37,7 +38,7 @@ object SettingsWidget {
3738
*/
3839
fun ImGuiBuilder.buildConfigSettingsContext(config: Configurable) {
3940
group {
40-
if (config is Module) {
41+
if (config is Module && config != AutoUpdater) {
4142
button("Module Settings") {
4243
ImGui.openPopup("##module-settings-popup-${config.name}")
4344
}

0 commit comments

Comments
 (0)