Skip to content

Commit d705d7c

Browse files
committed
feat: add export logs to text file button
1 parent caff04f commit d705d7c

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

app.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,29 @@ func (a *App) CancelScan() {
926926

927927
// --- Utility ---
928928

929+
func (a *App) ExportLogsToFile(logs string) error {
930+
filePath, err := wailsRuntime.SaveFileDialog(a.ctx, wailsRuntime.SaveDialogOptions{
931+
Title: "Export Logs",
932+
DefaultFilename: "log_export.txt",
933+
Filters: []wailsRuntime.FileFilter{
934+
{DisplayName: "Text Files", Pattern: "*.txt"},
935+
},
936+
})
937+
if err != nil {
938+
return err
939+
}
940+
if filePath == "" {
941+
return nil
942+
}
943+
944+
if err := os.WriteFile(filePath, []byte(logs), 0644); err != nil {
945+
return fmt.Errorf("error writing log file: %w", err)
946+
}
947+
948+
a.emitLog(fmt.Sprintf("Logs exported to %s", filepath.Base(filePath)), LogSuccess)
949+
return nil
950+
}
951+
929952
func (a *App) ShowMessageDialog(title, message, dialogType string) (string, error) {
930953
var msgType wailsRuntime.DialogType
931954
switch dialogType {

frontend/dist/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ <h3 class="panel-title">Debug Mode</h3>
6666
</div>
6767

6868
<div class="panel" id="log-panel">
69-
<h3 class="panel-title">Debug Log</h3>
69+
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;">
70+
<h3 class="panel-title" style="margin-bottom: 0;">Debug Log</h3>
71+
<button class="btn btn-sm" id="export-logs-btn">Export</button>
72+
</div>
7073
<div id="log-area"></div>
7174
</div>
7275
</section>

frontend/dist/src/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,21 @@ document.getElementById("start-debug-btn").addEventListener("click", async funct
713713
}
714714
});
715715

716+
// Export Logs
717+
document.getElementById("export-logs-btn").addEventListener("click", async function() {
718+
const entries = document.querySelectorAll("#log-area .log-entry");
719+
const text = Array.from(entries).map(function(e) { return e.textContent; }).join("\n");
720+
if (!text.trim()) {
721+
await showInfo("Info", "No logs to export.");
722+
return;
723+
}
724+
try {
725+
await window.go.main.App.ExportLogsToFile(text);
726+
} catch (err) {
727+
await showError("Error", err);
728+
}
729+
});
730+
716731
// Utility
717732
function escapeHtml(str) {
718733
if (!str) return "";

0 commit comments

Comments
 (0)