Skip to content

Commit

Permalink
client,webserver: Make log downloads work in a webview.
Browse files Browse the repository at this point in the history
	* Make distinct log file names with a timestamp

	* Explicitly set browser context to '_self' for
	  a webview.
  • Loading branch information
dev-warrior777 authored and JoeGruffins committed Jan 30, 2025
1 parent 09f7fc8 commit c4de82b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions client/webserver/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2045,9 +2045,14 @@ func (s *WebServer) apiTakeAction(w http.ResponseWriter, r *http.Request) {
writeJSON(w, simpleAck())
}

// apiExportAppLogs zips the application log and sends it back to the browser.
// apiExportAppLogs time stamps the application log, zips it and sends it back to
// the browser or webview as an attachment. Logfile names need to be distinct as
// webview will not overwite an existing file.
func (s *WebServer) apiExportAppLogs(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Disposition", "attachment; filename=bwlog.zip")
timeStamp := time.Now().UnixMilli()
zipAttachment := fmt.Sprintf("attachment; filename=bwlog_%d.zip", timeStamp)

w.Header().Set("Content-Disposition", zipAttachment)
w.Header().Set("Content-Type", "application/octet-stream; type=zip")
w.WriteHeader(http.StatusOK)

Expand Down
8 changes: 7 additions & 1 deletion client/webserver/site/src/js/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,10 +475,16 @@ export default class SettingsPage extends BasePage {
Doc.show(form)
}

/* exportLogs zips the main app log and sends it back as an attachment */
async exportLogs () {
const url = new URL(window.location.href)
url.pathname = '/api/exportapplog'
window.open(url.toString())
const target = '_self'
if (window.isWebview !== undefined) {
window.open(url.toString(), target) // explicit
} else {
window.open(url.toString())
}
}

async submitGameCode () {
Expand Down

0 comments on commit c4de82b

Please sign in to comment.