Skip to content

Commit db490d1

Browse files
committed
feat: add manual path input modal for mod folder selection
1 parent 9828811 commit db490d1

2 files changed

Lines changed: 54 additions & 15 deletions

File tree

app.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,30 +379,45 @@ func (a *App) LoadProject() error {
379379
// --- Mod Folder ---
380380

381381
func (a *App) SelectModFolder() (string, error) {
382+
dir, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
383+
Title: "Select Mod Folder",
384+
})
385+
if err != nil {
386+
return "", err
387+
}
388+
return dir, nil
389+
}
390+
391+
func (a *App) SetModFolderPath(path string) error {
382392
a.mu.Lock()
383393
if a.ActiveScan {
384394
a.mu.Unlock()
385-
return "", fmt.Errorf("cannot change mod folder while a debug scan is in progress")
395+
return fmt.Errorf("cannot change mod folder while a debug scan is in progress")
386396
}
387397
a.mu.Unlock()
388398

389-
dir, err := wailsRuntime.OpenDirectoryDialog(a.ctx, wailsRuntime.OpenDialogOptions{
390-
Title: "Select Mod Folder",
391-
})
399+
if path == "" {
400+
return fmt.Errorf("path cannot be empty")
401+
}
402+
403+
info, err := os.Stat(path)
392404
if err != nil {
393-
return "", err
405+
if os.IsNotExist(err) {
406+
return fmt.Errorf("path does not exist: %s", path)
407+
}
408+
return fmt.Errorf("cannot access path: %v", err)
394409
}
395-
if dir == "" {
396-
return "", nil
410+
if !info.IsDir() {
411+
return fmt.Errorf("path is not a directory: %s", path)
397412
}
398413

399414
a.mu.Lock()
400-
a.ProjectData.ModsDir = dir
415+
a.ProjectData.ModsDir = path
401416
a.ProjectModified = true
402417
a.mu.Unlock()
403418

404-
a.emitLog(fmt.Sprintf("Mod folder set: %s", dir), LogSuccess)
405-
return dir, nil
419+
a.emitLog(fmt.Sprintf("Mod folder set: %s", path), LogSuccess)
420+
return nil
406421
}
407422

408423
func (a *App) GetAvailableMods() []string {

frontend/dist/src/main.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,15 +278,39 @@ document.getElementById("save-as-btn").addEventListener("click", async function(
278278

279279
// Mod Folder
280280
document.getElementById("select-folder-btn").addEventListener("click", async function() {
281-
try {
281+
const currentPath = document.getElementById("folder-label").textContent;
282+
const pathInputId = "folder-path-input";
283+
284+
showModal("Select Mod Folder",
285+
'<div style="display: flex; flex-direction: column; gap: 8px;">' +
286+
'<label for="' + pathInputId + '" style="font-size: 13px; color: var(--text-secondary);">Mod Folder Path</label>' +
287+
'<div style="display: flex; gap: 6px;">' +
288+
'<input type="text" id="' + pathInputId + '" value="' + escapeHtml(currentPath) + '" placeholder="/path/to/mods" style="flex: 1; padding: 6px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-secondary); color: var(--text-primary); font-size: 13px;"/>' +
289+
'<button class="btn" id="browse-folder-btn">Browse</button>' +
290+
'</div>' +
291+
'</div>',
292+
'<button class="btn" onclick="closeModal()">Cancel</button>' +
293+
'<button class="btn btn-primary" id="confirm-folder-btn">OK</button>'
294+
);
295+
296+
document.getElementById("browse-folder-btn").addEventListener("click", async function() {
282297
const dir = await window.go.main.App.SelectModFolder();
283298
if (dir) {
284-
document.getElementById("folder-label").textContent = dir;
299+
document.getElementById(pathInputId).value = dir;
300+
}
301+
});
302+
303+
document.getElementById("confirm-folder-btn").addEventListener("click", async function() {
304+
const path = document.getElementById(pathInputId).value.trim();
305+
try {
306+
await window.go.main.App.SetModFolderPath(path);
307+
document.getElementById("folder-label").textContent = path;
308+
closeModal();
285309
await updateUI();
310+
} catch (err) {
311+
await showError("Error", err);
286312
}
287-
} catch (err) {
288-
await showError("Error", err);
289-
}
313+
});
290314
});
291315

292316
// Snapshot

0 commit comments

Comments
 (0)