Skip to content

Commit 9828811

Browse files
committed
feat: option to auto-launch game for prism launcher users
1 parent 4ab2577 commit 9828811

5 files changed

Lines changed: 78 additions & 7 deletions

File tree

app.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"os"
10+
"os/exec"
1011
"path/filepath"
1112
"sort"
1213
"strconv"
@@ -42,6 +43,7 @@ type App struct {
4243
ProjectFilePath string
4344
ProjectModified bool
4445
SyncCancelled bool
46+
AutoLaunchGame bool
4547
testResultChan chan bool
4648
closeConfirmChan chan string
4749
mu sync.Mutex
@@ -938,19 +940,33 @@ func (a *App) GetTheme() string {
938940

939941
// --- Debug Control ---
940942

941-
func (a *App) StartDebug(mode string, selectedMods []string) error {
943+
func findPrismLauncher() (string, error) {
944+
if path, err := exec.LookPath("prismlauncher"); err == nil {
945+
return path, nil
946+
}
947+
return "", fmt.Errorf("Prism Launcher not found. Install it or turn off Auto Launch Game.")
948+
}
949+
950+
func (a *App) StartDebug(mode string, selectedMods []string, autoLaunch bool) error {
942951
a.mu.Lock()
943952
if a.ActiveScan {
944953
a.mu.Unlock()
945954
return fmt.Errorf("a debug session is already in progress")
946955
}
956+
a.AutoLaunchGame = autoLaunch
947957
modsDir := a.ProjectData.ModsDir
948958
a.mu.Unlock()
949959

950960
if modsDir == "" {
951961
return fmt.Errorf("please select a mod folder first")
952962
}
953963

964+
if autoLaunch {
965+
if _, err := findPrismLauncher(); err != nil {
966+
return fmt.Errorf("Failed to start debug session, Prism Launcher is not installed. Please install Prism Launcher or turn off Auto Launch Game.")
967+
}
968+
}
969+
954970
entries, err := os.ReadDir(modsDir)
955971
if err != nil {
956972
return fmt.Errorf("mod folder does not exist")

debug.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"fmt"
55
"io"
66
"os"
7+
"os/exec"
78
"path/filepath"
89
"sort"
10+
"time"
911

1012
wailsRuntime "github.com/wailsapp/wails/v2/pkg/runtime"
1113
)
@@ -318,11 +320,46 @@ func (a *App) testGroup(mods []string) bool {
318320
}
319321

320322
func (a *App) waitForTestResult(modCount int) bool {
321-
wailsRuntime.EventsEmit(a.ctx, "test-group-prompt", map[string]int{"count": modCount})
323+
if a.AutoLaunchGame {
324+
prismPath, err := findPrismLauncher()
325+
if err != nil {
326+
a.emitLog(fmt.Sprintf("Failed to launch Prism Launcher: %v", err), LogError)
327+
wailsRuntime.EventsEmit(a.ctx, "test-group-prompt", map[string]interface{}{
328+
"count": modCount,
329+
"auto_launch": false,
330+
})
331+
result := <-a.testResultChan
332+
return result
333+
}
334+
instanceName := a.getInstanceName()
335+
cmd := exec.Command(prismPath, "-l", instanceName)
336+
if err := cmd.Start(); err != nil {
337+
a.emitLog(fmt.Sprintf("Failed to launch Prism Launcher: %v", err), LogError)
338+
wailsRuntime.EventsEmit(a.ctx, "test-group-prompt", map[string]interface{}{
339+
"count": modCount,
340+
"auto_launch": false,
341+
})
342+
result := <-a.testResultChan
343+
return result
344+
}
345+
defer func() {
346+
cmd.Process.Kill()
347+
time.Sleep(500 * time.Millisecond)
348+
}()
349+
}
350+
351+
wailsRuntime.EventsEmit(a.ctx, "test-group-prompt", map[string]interface{}{
352+
"count": modCount,
353+
"auto_launch": a.AutoLaunchGame,
354+
})
322355
result := <-a.testResultChan
323356
return result
324357
}
325358

359+
func (a *App) getInstanceName() string {
360+
return filepath.Base(filepath.Dir(filepath.Dir(a.ProjectData.ModsDir)))
361+
}
362+
326363
func readDirNames(dir string) []string {
327364
entries, err := os.ReadDir(dir)
328365
if err != nil {

frontend/dist/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ <h3 class="panel-title">Debug Mode</h3>
6262
Mode 2: Specific New Mods
6363
</label>
6464
</div>
65+
<label class="checkbox-label" style="margin-top: 8px; margin-bottom: 8px; display: flex; align-items: center; font-size: 12px; gap: 6px;">
66+
<input type="checkbox" id="auto-launch-checkbox"/>
67+
Auto Launch Game <span style="color: var(--text-secondary);">(Only Works for Prism Launcher)</span>
68+
</label>
6569
<button class="btn btn-primary" id="start-debug-btn">Start Debug</button>
6670
</div>
6771

frontend/dist/src/main.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ window.runtime.EventsOn("log", function(data) {
125125
});
126126

127127
window.runtime.EventsOn("test-group-prompt", function(data) {
128-
showTestDialog(data.count);
128+
showTestDialog(data.count, data.auto_launch);
129129
});
130130

131131
window.runtime.EventsOn("debug-complete", function(culprit) {
@@ -178,12 +178,16 @@ window.runtime.EventsOn("close-confirm", function() {
178178
);
179179
});
180180

181-
function showTestDialog(count) {
181+
function showTestDialog(count, autoLaunch) {
182182
testDialogActive = true;
183+
var launchText = autoLaunch
184+
? "The game has been launched, please wait and see if Minecraft loads properly"
185+
: "Launch Minecraft now and test if it loads properly";
183186
showModal("Test Launch",
184187
'<div class="test-dialog-main">' +
185188
'<h2>Testing ' + count + ' mods</h2>' +
186-
'<p>Launch Minecraft now and test if it loads properly.</p>' +
189+
'<p>' + launchText + '</p>' +
190+
'<p style="font-weight: bold; color: var(--log-error);">MAKE SURE TO CLOSE THE GAME BEFORE SELECTING AN OPTION.</p>' +
187191
'<p style="color: var(--text-secondary); font-size: 12px;">Only the selected mods are in your mods folder.</p>' +
188192
'</div>',
189193
'<button class="btn btn-danger" onclick="cancelDebug()">Cancel Debug</button>' +
@@ -397,7 +401,8 @@ async function startDebugWithSelection(mods, checkId) {
397401
}
398402
closeModal();
399403
try {
400-
await window.go.main.App.StartDebug("specific", selected);
404+
const autoLaunch = document.getElementById("auto-launch-checkbox").checked;
405+
await window.go.main.App.StartDebug("specific", selected, autoLaunch);
401406
await updateUI();
402407
} catch (err) {
403408
await showError("Error", err);
@@ -715,9 +720,11 @@ document.getElementById("start-debug-btn").addEventListener("click", async funct
715720
const mode = document.querySelector('input[name="mode"]:checked');
716721
if (!mode) return;
717722

723+
const autoLaunch = document.getElementById("auto-launch-checkbox").checked;
724+
718725
try {
719726
if (mode.value === "all") {
720-
await window.go.main.App.StartDebug("all", null);
727+
await window.go.main.App.StartDebug("all", null, autoLaunch);
721728
} else {
722729
const savedMods = await window.go.main.App.GetSavedNewMods();
723730
if (!savedMods || savedMods.length === 0) {

frontend/dist/src/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,13 @@ html, body {
561561
font-size: 13px;
562562
}
563563

564+
#auto-launch-checkbox {
565+
accent-color: var(--accent);
566+
width: 15px;
567+
height: 15px;
568+
cursor: pointer;
569+
}
570+
564571
.checkbox-item input[type="checkbox"],
565572
.checkbox-item input[type="radio"] {
566573
accent-color: var(--accent);

0 commit comments

Comments
 (0)