feat: download dirs, file transfer resume, Wails desktop app, PWA, CI

Daemon:
- Per-network download directories (-download-dir flag, set_download_dir IPC)
- File transfer resume after disconnection: .tmp.meta sidecars survive
  interruption; resume_offset in file-accept lets sender seek and continue
- set_download_dir IPC command; download_dir reported in state_snapshot

Protocol:
- PeerMessage.ResumeOffset (EXT-006) for file transfer resume
- IpcMessage.ShareNetworks json tag changed from "networks" to "network_ids"
  to fix duplicate json tag collision with Networks []NetworkInfo

Desktop app (cmd/app):
- Wails v2 shell embedding daemon logic directly (no subprocess)
- System tray on Linux/Windows via getlantern/systray; macOS hides to Dock
- OS notifications for message_received and file_complete via Wails events
- notray build tag for headless/CI builds without GTK tray headers
- build-app.sh: builds web frontend, copies dist, runs wails build

Web / PWA:
- manifest.json + Apple touch icon meta tags for mobile "Add to Home Screen"
- PNG icons (192px, 512px, 180px) generated from SVG
- Wails EventsOn("notify") hook in App.tsx for native OS notifications

CI:
- .gitea/workflows/build.yml: server binaries cross-compiled for 5 platforms,
  desktop app for Linux amd64, release artifacts published on v* tags

Docs:
- README: download dir, file transfer resume, desktop app, PWA, CI sections
- EXTENSIONS.md: EXT-004 daemon mode marked shipped; EXT-006 resume added
- FUTURE.md: roadmap updated

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-28 21:38:28 +02:00
parent d233f4d79e
commit 0789cf8840
29 changed files with 951 additions and 58 deletions

130
cmd/app/app.go Normal file
View File

@@ -0,0 +1,130 @@
package main
import (
"context"
"log"
"os"
"path/filepath"
"github.com/wailsapp/wails/v2/pkg/runtime"
"github.com/waste-go/internal/crypto"
"github.com/waste-go/internal/ipc"
"github.com/waste-go/internal/netmgr"
"github.com/waste-go/internal/proto"
)
const wsPort = 17338
// App is the Wails application backend.
// It embeds the daemon directly — no subprocess needed.
// The React frontend connects to the daemon's WebSocket IPC at ws://127.0.0.1:17338,
// exactly as it does in browser-daemon mode.
type App struct {
ctx context.Context
mgr *netmgr.Manager
}
func newApp() *App {
return &App{}
}
// startup is called when the Wails window is ready. It initialises the daemon,
// starts the WebSocket IPC listener, sets up the system tray, and begins
// forwarding message/file events to the webview as OS notifications.
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
dir := dataDir()
id, err := crypto.LoadOrCreate(dir, "")
if err != nil {
log.Printf("app: identity: %v", err)
runtime.MessageDialog(ctx, runtime.MessageDialogOptions{
Type: runtime.ErrorDialog,
Title: "waste — startup error",
Message: "Failed to load identity: " + err.Error(),
})
return
}
log.Printf("app: peer id: %s alias: %s", id.PeerID().Short(), id.Alias)
a.mgr = netmgr.New(netmgr.Config{
MasterIdentity: id,
StoreDir: dir,
})
// Forward daemon events to the webview and generate OS notifications.
go a.watchEvents()
// Start the WebSocket IPC server; the webview connects here (daemon mode).
go func() {
if err := ipc.RunWS(a.mgr, wsPort); err != nil {
log.Printf("app: IPC: %v", err)
}
}()
log.Printf("app: WebSocket IPC listening on 127.0.0.1:%d", wsPort)
// System tray (Linux/Windows; no-op on macOS — see tray_darwin.go).
a.startTray()
}
// shutdown is called when the Wails app exits.
func (a *App) shutdown(ctx context.Context) {
if a.mgr != nil {
a.mgr.LeaveAll()
}
}
// watchEvents subscribes to all daemon events and emits OS notifications for
// incoming messages and completed file transfers. The "notify" event is received
// by the frontend via Wails EventsOn and displayed using the browser Notification API.
func (a *App) watchEvents() {
if a.mgr == nil {
return
}
events := a.mgr.Subscribe()
defer a.mgr.Unsubscribe(events)
for evt := range events {
switch evt.Type {
case proto.EvtMessageReceived:
if evt.Message == nil {
continue
}
// Don't notify for messages sent by the local peer.
if a.mgr.MasterIdentity() != nil && evt.Message.From == a.mgr.MasterIdentity().PeerID() {
continue
}
runtime.EventsEmit(a.ctx, "notify", map[string]string{
"title": "waste — new message",
"body": evt.Message.Text,
})
case proto.EvtFileComplete:
runtime.EventsEmit(a.ctx, "notify", map[string]string{
"title": "waste — file received",
"body": filepath.Base(evt.Path),
})
}
}
}
// dataDir returns the OS-appropriate config directory for identity and stores.
// macOS: ~/Library/Application Support/waste
// Linux: ~/.config/waste
// Windows: %APPDATA%\waste
func dataDir() string {
base, err := os.UserConfigDir()
if err != nil {
if home, err := os.UserHomeDir(); err == nil {
return filepath.Join(home, ".waste")
}
return ".waste"
}
dir := filepath.Join(base, "waste")
if err := os.MkdirAll(dir, 0o700); err != nil {
log.Printf("app: mkdir %s: %v", dir, err)
}
return dir
}

BIN
cmd/app/appicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

0
cmd/app/frontend/dist/.gitkeep vendored Normal file
View File

66
cmd/app/main.go Normal file
View File

@@ -0,0 +1,66 @@
// waste desktop app — Wails shell wrapping the daemon and React UI.
// In dev mode the UI is served from the Vite dev server (http://localhost:5173).
// In production the compiled frontend is embedded from frontend/dist/.
package main
import (
"embed"
"log"
"os"
"github.com/wailsapp/wails/v2"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/options"
"github.com/wailsapp/wails/v2/pkg/options/assetserver"
"github.com/wailsapp/wails/v2/pkg/options/linux"
"github.com/wailsapp/wails/v2/pkg/options/mac"
"github.com/wailsapp/wails/v2/pkg/options/windows"
)
//go:embed all:frontend/dist
var assets embed.FS
func main() {
app := newApp()
logLevel := logger.INFO
if os.Getenv("WASTE_DEBUG") != "" {
logLevel = logger.DEBUG
}
err := wails.Run(&options.App{
Title: "waste",
Width: 1200,
Height: 800,
MinWidth: 800,
MinHeight: 600,
DisableResize: false,
Fullscreen: false,
LogLevel: logLevel,
LogLevelProduction: logger.ERROR,
AssetServer: &assetserver.Options{
Assets: assets,
},
OnStartup: app.startup,
OnShutdown: app.shutdown,
Bind: []interface{}{app},
// Hide the window instead of quitting when the close button is clicked.
// The user can quit via the app menu or by stopping the process.
HideWindowOnClose: true,
Mac: &mac.Options{
TitleBar: mac.TitleBarHiddenInset(),
About: &mac.AboutInfo{
Title: "waste",
Message: "Decentralized friend-to-friend encrypted mesh networking.",
},
},
Windows: &windows.Options{
WebviewIsTransparent: false,
WindowIsTranslucent: false,
},
Linux: &linux.Options{},
})
if err != nil {
log.Fatal(err)
}
}

35
cmd/app/tray.go Normal file
View File

@@ -0,0 +1,35 @@
//go:build !darwin && !notray
package main
import (
_ "embed"
"github.com/getlantern/systray"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
//go:embed appicon.png
var trayIcon []byte
func (a *App) startTray() {
go systray.Run(func() {
systray.SetIcon(trayIcon)
systray.SetTooltip("waste")
mShow := systray.AddMenuItem("Open waste", "Show the waste window")
systray.AddSeparator()
mQuit := systray.AddMenuItem("Quit", "Quit waste")
for {
select {
case <-mShow.ClickedCh:
runtime.WindowShow(a.ctx)
case <-mQuit.ClickedCh:
systray.Quit()
runtime.Quit(a.ctx)
return
}
}
}, func() {})
}

14
cmd/app/tray_darwin.go Normal file
View File

@@ -0,0 +1,14 @@
//go:build darwin
package main
// On macOS, Cocoa requires the system tray to run on the main thread, which
// Wails already owns. Full menu-bar tray integration is future work and would
// require an NSStatusItem helper or a fork of systray that supports
// RunWithExternalLoop on macOS.
//
// For now the app hides to the Dock when the window is closed (HideWindowOnClose)
// and users can reopen it from the Dock or Cmd+Tab. The standard macOS Cmd+Q
// binding quits cleanly via Wails.
func (a *App) startTray() {}

8
cmd/app/tray_stub.go Normal file
View File

@@ -0,0 +1,8 @@
//go:build notray
package main
// Build with -tags notray to omit the system tray (no libayatana-appindicator3-dev needed).
// Used for headless builds and CI environments that haven't installed the GTK tray headers.
func (a *App) startTray() {}

12
cmd/app/wails.json Normal file
View File

@@ -0,0 +1,12 @@
{
"$schema": "https://wails.io/schemas/config.v2.json",
"name": "waste",
"outputfilename": "waste",
"frontend:install": "echo 'run: cd web && npm install'",
"frontend:build": "echo 'run: ./build-app.sh'",
"frontend:dev:watcher": "",
"frontend:dev:serverUrl": "http://localhost:5173",
"author": {
"name": "waste-go"
}
}

View File

@@ -21,6 +21,7 @@ func main() {
wsPort := flag.Int("ws-port", 0, "port for WebSocket IPC (web UI); 0 = disabled")
anchorURL := flag.String("anchor", "", "anchor WebSocket URL, e.g. ws://your-vps:17339/ws")
shareDir := flag.String("share-dir", "", "directory to share with peers on the network")
downloadDir := flag.String("download-dir", "", "base directory for received files; defaults to data-dir, split by network")
joinInvite := flag.String("join", "", "waste: invite string — sets anchor URL and auto-joins the network on startup")
turnURL := flag.String("turn-url", "", "TURN server URL, e.g. turn:your-vps:3478")
turnSecret := flag.String("turn-secret", "", "shared secret for coturn use-auth-secret HMAC credential")
@@ -76,6 +77,7 @@ func main() {
StoreDir: dir,
AnchorURL: *anchorURL,
ShareDir: expandHome(*shareDir),
DownloadDir: expandHome(*downloadDir),
TurnURL: *turnURL,
TurnSecret: *turnSecret,
})