Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ Cutting a release: [docs/RELEASE.md](docs/RELEASE.md).

### Added

- **Feedback, from inside the window.** Saying something about Pylon meant
knowing the project had a tracker, finding it, and having an account — which
selects for contributors and against exactly the users worth hearing from.
Hakkında now has a category, a box and a Send button, and what comes out is
an issue on the project page.

Pylon has no server of its own, so there are two ways it gets there and the
reply says which happened: with the GitHub token already in the vault it
files the issue and hands back its URL, and with no token — or one that
cannot open issues — it opens the prefilled page in the browser instead. It
falls back rather than failing, because a token's permissions are not
something the user can fix from that screen, and it invents no identity to
post under.

Nothing is sent that the user has not seen: the diagnostics are one short
line — version, OS, desktop, language — shown under the box before Send, and
built once so what is on screen and what is in the issue cannot drift apart.
No log, no config, nothing read off disk.

- **Updating from the window, and a Hakkında tab to do it in.** `pylon update`
existed and nothing in the GUI reached it, so the only way to install a
release was to know there was a terminal command for it. The new tab shows
Expand Down
100 changes: 100 additions & 0 deletions cmd/pylon/feedback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package main

import (
"context"
"fmt"
"os"
"runtime"
"strings"
"time"

"github.com/YCistak/pylon/internal/config"
"github.com/YCistak/pylon/internal/daemon"
"github.com/YCistak/pylon/internal/feedback"
"github.com/YCistak/pylon/internal/i18n"
"github.com/YCistak/pylon/internal/ipc"
)

// feedbackEnv gathers the facts attached to a report. It reads only what is
// already in this process — the version it was built with, the platform it is
// running on, the language it is speaking — and nothing off disk. The form
// shows the user this exact line before sending, so the list has to stay short
// enough to read.
func feedbackEnv() feedback.Env {
desktop := ""
if runtime.GOOS == "linux" {
// The raw value, not a normalised one: "Hyprland" and "hyprland:wlroots"
// mean different things to whoever reads the issue, and flattening them
// throws away the distinction at exactly the wrong moment.
desktop = strings.TrimSpace(os.Getenv("XDG_CURRENT_DESKTOP"))
}
return feedback.Env{
Version: version,
OS: runtime.GOOS,
Desktop: desktop,
Language: i18n.Language(),
}
}

// registerFeedback exposes the form's two questions over IPC.
//
// "feedback env" is what the form shows under the box before anything is sent,
// so nothing leaves the machine that the user has not already seen on screen.
//
// "feedback send <category> <body>" files it. The token is the user's own, the
// one already in the vault for the GitHub widget: Pylon has no server of its
// own and inventing an identity to post under would be worse than asking. With
// no token there is still somewhere to go — the reply carries a prefilled
// new-issue URL and the window opens it — because a Send button that dead-ends
// is worse than one that changes its mind about how.
func registerFeedback(d *daemon.Daemon, cfg config.Config) {
d.Handle("feedback", func(req ipc.Request) ipc.Response {
if len(req.Args) == 0 {
return ipc.Response{OK: false, Error: "usage: feedback <env|send> [category] [body]"}
}

switch req.Args[0] {
case "env":
return ipc.Response{OK: true, Text: feedbackEnv().Line()}

case "send":
if len(req.Args) < 3 {
return ipc.Response{OK: false, Error: "usage: feedback send <category> <body>"}
}
category, body := req.Args[1], req.Args[2]
if !feedback.Valid(category) {
return ipc.Response{OK: false, Error: "unknown category: " + category}
}
if strings.TrimSpace(body) == "" {
return ipc.Response{OK: false, Error: i18n.T("feedback.empty")}
}

r := feedback.Report{Category: category, Body: body, Env: feedbackEnv()}

// "<how>\t<url>": sent, and the issue to look at; or browser, and
// the page to open. The GUI has to act differently on the two, and
// telling them apart by matching on translated prose would break in
// six languages at once — the same reason "update check" answers in
// fields rather than a sentence.
token := resolveSecret(cfg.Services.GitHub.Token)
if strings.TrimSpace(token) == "" {
return ipc.Response{OK: true, Text: "browser\t" + r.BrowserURL()}
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

issue, err := feedback.Submit(ctx, token, r)
if err != nil {
// Falling back rather than failing: a token that cannot open
// issues is a permissions detail the user cannot fix from here,
// and their words are still worth delivering.
return ipc.Response{OK: true, Text: "browser\t" + r.BrowserURL()}
}
return ipc.Response{OK: true, Text: "sent\t" + issue}

default:
return ipc.Response{OK: false, Error: fmt.Sprintf("unknown operation: %s", req.Args[0])}
}
})
}
1 change: 1 addition & 0 deletions cmd/pylon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ func cmdStart() error {
registerSecrets(d)
registerAuth(d, cfg)
registerUpdate(d)
registerFeedback(d, cfg)
registerHotkey(d, cfg, database, log)
registerSTTServer(d, cfg, log)

Expand Down
34 changes: 33 additions & 1 deletion docs/UI.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ question:
| **Görünüm** | Widget instances (add/edit/remove via a dialog) and which pages are pinned to the dock |
| **Hesaplar** | `Accounts.svelte` (OAuth sign-in) and `ApiKeys.svelte` (vault keys) |
| **Ses** | `VoiceSettings.svelte` — the push-to-talk shortcut |
| **Hakkında** | `About.svelte` — what is installed, and the button that replaces it |
| **Hakkında** | `About.svelte` and `Feedback.svelte` — what is installed, updating it, and saying something about it |

Language is the first tab because it is the one setting you go looking for when
you cannot read any of the others.
Expand Down Expand Up @@ -181,6 +181,36 @@ project whose only tag is an alpha reaches it too. Left raw, that reads as
"github returned 404 Not Found" and sends the user looking for a fault on their
own machine.

### Feedback

A category, a box, and Send. It becomes an issue on the project's tracker.

The form is under Hakkında rather than behind a link, because a link is what was
there before: feedback arrived only from people who already knew the project had
a tracker, found it, and had an account — which selects for contributors and
against exactly the users worth hearing from.

Pylon has no server, so there are two ways it can be delivered and the reply
says which happened. With a GitHub token in the vault — the one already there
for the GitHub widget — it posts the issue directly and hands back its URL, so
the user can go and look at what they sent. With no token, or a token that
cannot open issues, it opens the prefilled new-issue page in the browser
instead. Falling back rather than failing: a token's permissions are not
something the user can fix from this screen, and their words are still worth
delivering. Nothing else is tried — Pylon does not invent an identity to post
under.

**Nothing is sent that the user has not seen.** The diagnostics are one short
line — version, OS, desktop, language — displayed under the box before Send is
pressed, and `internal/feedback` builds it once so the line on screen and the
line in the issue are the same string. No log is read, no config is attached,
nothing is collected off disk.

`feedback send` answers `<how>\t<url>`, the same shape as `update check` and for
the same reason: the window has to act differently on the two outcomes, and
telling them apart by matching on translated prose would break in six languages
at once.

## Widgets

A widget is an **instance**, not a toggle: you can have two GitHub cards showing
Expand Down Expand Up @@ -225,6 +255,8 @@ entry in the catalog so far: Docker.
| `CancelListen()` | stop the turn that is running (Escape, the stop button) |
| `Version()` / `GUIVersion()` | the daemon's version, and this window's |
| `UpdateCheck()` / `UpdateApply()` | what an update would install, and installing it |
| `FeedbackEnv()` / `SendFeedback(category, body)` | the diagnostics line shown before sending, and filing the report |
| `OpenURL(url)` | hand a link to the desktop's browser |
| `RestartDaemon()` | bounce the daemon so new config/credentials take effect |
| `Platform()` | which desktop this is (`hyprland`, `sway`, `gnome`, `kde`, `macos`, `windows`, …) |
| `Hotkey()` / `SetHotkey(combo)` | read and change the push-to-talk shortcut |
Expand Down
170 changes: 170 additions & 0 deletions internal/feedback/feedback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
// Package feedback turns something a user typed into a filed GitHub issue.
//
// It exists because the alternative shipped for a while: nothing. Feedback
// arrived only from people who already knew the project had a tracker, found
// it, and had an account — which selects for contributors and against exactly
// the users worth hearing from.
//
// Two things it deliberately does not do. It sends nothing the user has not
// been shown: the diagnostics are a fixed, short line the form displays under
// the box, not a log, a config dump, or anything read off disk. And it invents
// no identity — the issue is filed with the token already in the vault, under
// the account that owns it, or not at all.
package feedback

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"strings"
"time"
)

// repo is where feedback lands. Hard-coded for the same reason the update
// endpoint is: a configurable destination for a "send feedback" button is a
// way to get a user's words delivered somewhere they did not intend.
const repo = "YCistak/pylon"

// Categories are the kinds of feedback the form offers, in the order it offers
// them. They are ids, not labels — the interface translates them, and they end
// up as GitHub labels, which are not translated.
var Categories = []string{"bug", "idea", "question", "other"}

// Valid reports whether c is one of Categories. The GUI sends the id straight
// through, and an unknown one would become a label nobody is watching.
func Valid(c string) bool {
for _, known := range Categories {
if c == known {
return true
}
}
return false
}

// Env is the handful of facts attached to a report, and the whole of it. Enough
// to tell a Wayland bug from an X11 one without asking; not enough to identify
// anybody.
type Env struct {
Version string // the daemon's
OS string // runtime.GOOS
Desktop string // hyprland, gnome, windows…
Language string // what Pylon is speaking
}

// Line renders Env as the single line the form shows the user before they send.
// The form displays exactly this, so what is on screen is what is submitted.
func (e Env) Line() string {
parts := []string{}
for _, v := range []string{e.Version, e.OS, e.Desktop, e.Language} {
if v = strings.TrimSpace(v); v != "" {
parts = append(parts, v)
}
}
return strings.Join(parts, " · ")
}

// Report is one piece of feedback.
type Report struct {
Category string
Body string
Env Env
}

// maxTitle keeps the issue list readable. GitHub allows far more, but a title
// that is a whole paragraph is a title nobody can scan.
const maxTitle = 72

// Title is the issue title: the report's first line, trimmed, tagged with the
// category. A body with no usable first line still gets a title, because an
// issue called "" is worse than one called "bug".
func (r Report) Title() string {
first := strings.TrimSpace(strings.SplitN(strings.TrimSpace(r.Body), "\n", 2)[0])
if first == "" {
return "[" + r.Category + "]"
}
if len([]rune(first)) > maxTitle {
first = strings.TrimSpace(string([]rune(first)[:maxTitle])) + "…"
}
return "[" + r.Category + "] " + first
}

// Issue is the body as filed: what the user wrote, then the diagnostics, with a
// rule between so the two are never mistaken for each other.
func (r Report) Issue() string {
body := strings.TrimSpace(r.Body)
line := r.Env.Line()
if line == "" {
return body
}
return body + "\n\n---\n" + line
}

// BrowserURL is where to send someone whose vault holds no GitHub token: the
// new-issue form, prefilled. It is the fallback rather than the default because
// it drops the user into a login flow to say one sentence — but a button that
// dead-ends for everyone without a token would be worse than either.
func (r Report) BrowserURL() string {
q := url.Values{}
q.Set("title", r.Title())
q.Set("body", r.Issue())
q.Set("labels", r.Category)
return "https://github.com/" + repo + "/issues/new?" + q.Encode()
}

// Submit files the report and returns the URL of the issue it created.
//
// The token is the user's own, the one already in the vault for the GitHub
// widget, so the issue is filed under their account and is visible to them
// afterwards — which is why the URL comes back rather than a bare "sent".
func Submit(ctx context.Context, token string, r Report) (string, error) {
if strings.TrimSpace(token) == "" {
return "", fmt.Errorf("feedback: no github token")
}
if strings.TrimSpace(r.Body) == "" {
return "", fmt.Errorf("feedback: nothing written")
}

payload, err := json.Marshal(map[string]any{
"title": r.Title(),
"body": r.Issue(),
"labels": []string{r.Category},
})
if err != nil {
return "", err
}

req, err := http.NewRequestWithContext(ctx, http.MethodPost,
"https://api.github.com/repos/"+repo+"/issues", bytes.NewReader(payload))
if err != nil {
return "", err
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")
req.Header.Set("Content-Type", "application/json")

resp, err := (&http.Client{Timeout: 20 * time.Second}).Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
// The message matters here more than most: a token without issue
// permission and a repository with issues turned off both fail, and
// they need different things done about them.
body, _ := io.ReadAll(io.LimitReader(resp.Body, 512))
return "", fmt.Errorf("github API %d: %s", resp.StatusCode, strings.TrimSpace(string(body)))
}

var out struct {
HTMLURL string `json:"html_url"`
}
if err := json.NewDecoder(io.LimitReader(resp.Body, 1<<20)).Decode(&out); err != nil {
return "", err
}
return out.HTMLURL, nil
}
Loading
Loading