Desktop: notifications, tray, auto-update, installer; web: sliding sync, voice messages, notifications
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
CI / Admin panel (push) Canceled after 0s
CI / Web client (push) Canceled after 0s
CI / Desktop client (ubuntu-24.04) (push) Canceled after 0s
CI / Desktop client (windows-latest) (push) Canceled after 0s
CI / Test (ubuntu-latest) (push) Canceled after 0s
CI / Test (windows-latest) (push) Canceled after 0s
CI / Storage tests on PostgreSQL (push) Canceled after 0s
CI / Complement (federation off) (push) Canceled after 0s
CI / golangci-lint (push) Canceled after 0s
CI / Smoke test the binary (push) Canceled after 0s
CI / Admin panel (push) Canceled after 0s
CI / Web client (push) Canceled after 0s
CI / Desktop client (ubuntu-24.04) (push) Canceled after 0s
CI / Desktop client (windows-latest) (push) Canceled after 0s
Web client (also what the desktop app runs): - Simplified Sliding Sync (MSC4186) when the homeserver advertises org.matrix.simplified_msc3575. src/matrix/sliding.ts answers the SDK's GET /sync with a sliding sync request and rewrites the response into the /sync shape, as the Android app does; the SDK's own sliding sync mode doesn't sort thread replies into threads. 20 rooms first, then every room (up to 1000); to_device, e2ee, account data, receipts and typing extensions; M_UNKNOWN_POS starts a new connection. The SDK's /members?at=<sync token> drops the token, which here is ours. Settings can switch back to /sync. - Notifications for new messages and incoming calls while Warp isn't in front, by the account's push rules, evaluated after decryption. The browser's Notification API once turned on in Settings, or the desktop app's bridge (window.warpDesktop). One per room; a click opens it. - Voice messages: record from the composer, sent as m.audio with MSC3245's voice marker and MSC1767's duration and waveform (encrypted in encrypted rooms); a waveform player in the timeline. - @warp/ui: a slot for extra composer buttons; bell-off, play and pause icons. Desktop app: - System notifications through Wails' notifications service, fed by /_desktop/bridge.js (/_desktop/notify, JSON only); clicking one shows the window and opens the room. - Tray icon with Open and Quit; closing the window hides it (a one-time notification says so), File > Quit ends it. The page title goes to the window and the tray tooltip, the unread count to the taskbar or Dock badge. - Auto-update from a Wails update manifest at DESKTOP_UPDATE_URL: a quiet check a minute after start and every six hours, a notification when a newer version exists, Help > Check for updates opens the update window. Optional signature key (DESKTOP_UPDATE_KEY). Linux package installs leave updates to the package manager. build/manifest writes the manifest. - Per-user NSIS installer (make desktop-windows-installer), the macOS bundle zipped for the updater, a desktop CI job, and a Desktop release workflow that builds all three platforms and the manifest. Tested on Windows against a local homeserver: sliding sync with E2EE, threads and a server restart; notifications (toast history), close to tray, relaunch restoring the window; voice messages recorded, sent and played, encrypted too; the update check finding a newer version. Not tested: installing an update, the NSIS installer, CI, macOS and Linux. Code signing needs certificates and isn't done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8ff2730676
commit
829b236efe
33 files changed
+2067
-51
No files matched your search
@@ -0,0 +1,211 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
"github.com/wailsapp/wails/v3/pkg/services/dock"
|
||||
"github.com/wailsapp/wails/v3/pkg/services/notifications"
|
||||
|
||||
"github.com/dariuszjaniak/warp/apps/desktop/internal/shell"
|
||||
)
|
||||
|
||||
// desktop is what the app adds around the window: system notifications,
|
||||
// the tray icon, the unread count on the taskbar or Dock, and closing to
|
||||
// the tray. A chat app that quits when its window closes misses the
|
||||
// messages it was meant to tell you about.
|
||||
type desktop struct {
|
||||
app *application.App
|
||||
window *application.WebviewWindow
|
||||
tray *application.SystemTray
|
||||
notes *notifications.NotificationService
|
||||
dock *dock.DockService
|
||||
store *shell.Store
|
||||
logger *slog.Logger
|
||||
|
||||
quitting atomic.Bool
|
||||
// onUpdate installs an update: an update notification was clicked.
|
||||
onUpdate func()
|
||||
|
||||
mu sync.Mutex
|
||||
title string
|
||||
unread int
|
||||
}
|
||||
|
||||
func newDesktop(store *shell.Store, logger *slog.Logger) *desktop {
|
||||
return &desktop{
|
||||
notes: notifications.New(),
|
||||
dock: dock.New(),
|
||||
store: store,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
// services are registered with the app; they start and stop with it.
|
||||
func (d *desktop) services() []application.Service {
|
||||
return []application.Service{application.NewService(d.notes), application.NewService(d.dock)}
|
||||
}
|
||||
|
||||
// shouldQuit is the app's ShouldQuit: every way of quitting (the menus,
|
||||
// Cmd+Q, signing out of the OS) passes here, and from then on closing the
|
||||
// window closes it.
|
||||
func (d *desktop) shouldQuit() bool {
|
||||
d.quitting.Store(true)
|
||||
return true
|
||||
}
|
||||
|
||||
func (d *desktop) quit() {
|
||||
d.quitting.Store(true)
|
||||
d.app.Quit()
|
||||
}
|
||||
|
||||
// attach sets up the tray and window behaviour, once both exist.
|
||||
func (d *desktop) attach(app *application.App, window *application.WebviewWindow, icon []byte) {
|
||||
d.app = app
|
||||
d.window = window
|
||||
|
||||
menu := app.NewMenu()
|
||||
menu.Add("Open Warp").OnClick(func(*application.Context) { d.show() })
|
||||
menu.AddSeparator()
|
||||
menu.Add("Quit Warp").OnClick(func(*application.Context) { d.quit() })
|
||||
d.tray = app.SystemTray.New().SetIcon(icon).SetMenu(menu).OnClick(d.show)
|
||||
d.tray.SetTooltip("Warp")
|
||||
|
||||
window.RegisterHook(events.Common.WindowClosing, func(e *application.WindowEvent) {
|
||||
if d.quitting.Load() {
|
||||
return
|
||||
}
|
||||
e.Cancel()
|
||||
window.Hide()
|
||||
d.hintOnce()
|
||||
})
|
||||
// The Dock icon of a running app whose window is hidden.
|
||||
app.Event.OnApplicationEvent(events.Mac.ApplicationShouldHandleReopen, func(*application.ApplicationEvent) { d.show() })
|
||||
|
||||
d.notes.OnNotificationResponse(d.onNotificationResponse)
|
||||
}
|
||||
|
||||
func (d *desktop) show() {
|
||||
d.window.Show()
|
||||
d.window.Restore()
|
||||
d.window.Focus()
|
||||
}
|
||||
|
||||
// hintOnce says, the first time the window is closed, where the app went.
|
||||
func (d *desktop) hintOnce() {
|
||||
st, err := d.store.Load()
|
||||
if err != nil || st.TrayHintShown {
|
||||
return
|
||||
}
|
||||
st.TrayHintShown = true
|
||||
if err := d.store.Save(st); err != nil {
|
||||
d.logger.Warn("can't save the settings", "err", err)
|
||||
}
|
||||
err = d.notes.SendNotification(notifications.NotificationOptions{
|
||||
ID: "warp-tray-hint",
|
||||
Title: "Warp is still running",
|
||||
Body: "It keeps checking for messages. Open it or quit from the tray icon.",
|
||||
Sound: ¬ifications.NotificationSound{Silent: true},
|
||||
})
|
||||
if err != nil {
|
||||
d.logger.Warn("can't show a notification", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// notify is the shell's Notify: one notification per room, replacing the
|
||||
// room's last one where the system can. No ThreadID: Windows shows it as a
|
||||
// header, and a room ID is no title.
|
||||
func (d *desktop) notify(n shell.Notification) error {
|
||||
return d.notes.SendNotification(notifications.NotificationOptions{
|
||||
ID: n.ID,
|
||||
Title: n.Title,
|
||||
Body: n.Body,
|
||||
Data: map[string]any{"roomId": n.RoomID},
|
||||
})
|
||||
}
|
||||
|
||||
// onNotificationResponse brings the window forward and opens the room of
|
||||
// the notification that was clicked.
|
||||
func (d *desktop) onNotificationResponse(r notifications.NotificationResult) {
|
||||
if r.Error != nil {
|
||||
d.logger.Warn("notification response", "err", r.Error)
|
||||
return
|
||||
}
|
||||
if action, _ := r.Response.UserInfo["action"].(string); action == "update" && d.onUpdate != nil {
|
||||
d.onUpdate()
|
||||
return
|
||||
}
|
||||
d.show()
|
||||
roomID, _ := r.Response.UserInfo["roomId"].(string)
|
||||
if roomID == "" {
|
||||
return
|
||||
}
|
||||
detail, _ := json.Marshal(roomID)
|
||||
d.window.ExecJS(fmt.Sprintf(`window.dispatchEvent(new CustomEvent('warp-desktop:open-room', { detail: %s }))`, detail))
|
||||
}
|
||||
|
||||
// notifyUpdate says that a newer version is ready to install.
|
||||
func (d *desktop) notifyUpdate(version string) {
|
||||
err := d.notes.SendNotification(notifications.NotificationOptions{
|
||||
ID: "warp-update",
|
||||
Title: "Warp " + version + " is available",
|
||||
Body: "Click to install it, or use Help → Check for updates.",
|
||||
Data: map[string]any{"action": "update"},
|
||||
})
|
||||
if err != nil {
|
||||
d.logger.Warn("can't show a notification", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
// unreadPrefix is how the client's page title counts unread rooms: "(3) Room · Warp".
|
||||
var unreadPrefix = regexp.MustCompile(`^\((\d+)\) `)
|
||||
|
||||
// unreadIn returns the unread count in a page title, 0 when it has none.
|
||||
func unreadIn(title string) int {
|
||||
m := unreadPrefix.FindStringSubmatch(title)
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
n, _ := strconv.Atoi(m[1])
|
||||
return n
|
||||
}
|
||||
|
||||
// setTitle is the shell's SetTitle: the page's title goes to the window
|
||||
// and the tray, its unread count to the taskbar or Dock.
|
||||
func (d *desktop) setTitle(title string) {
|
||||
if title == "" {
|
||||
title = "Warp"
|
||||
}
|
||||
n := unreadIn(title)
|
||||
d.mu.Lock()
|
||||
changed, countChanged := title != d.title, n != d.unread
|
||||
d.title, d.unread = title, n
|
||||
d.mu.Unlock()
|
||||
if changed {
|
||||
d.window.SetTitle(title)
|
||||
d.tray.SetTooltip(title)
|
||||
}
|
||||
if !countChanged {
|
||||
return
|
||||
}
|
||||
var err error
|
||||
if n == 0 {
|
||||
err = d.dock.RemoveBadge()
|
||||
} else {
|
||||
label := strconv.Itoa(n)
|
||||
if n > 99 {
|
||||
label = "99+"
|
||||
}
|
||||
err = d.dock.SetBadge(label)
|
||||
}
|
||||
if err != nil {
|
||||
d.logger.Debug("can't set the badge", "err", err)
|
||||
}
|
||||
}
|
||||
@@ -61,14 +61,18 @@ func run() error {
|
||||
files = nil
|
||||
}
|
||||
|
||||
store := shell.NewStore(filepath.Join(dirs.config, "desktop.json"))
|
||||
d := newDesktop(store, logger)
|
||||
var app *application.App
|
||||
sh, err := shell.New(shell.Options{
|
||||
Store: shell.NewStore(filepath.Join(dirs.config, "desktop.json")),
|
||||
Store: store,
|
||||
Homeserver: *homeserver,
|
||||
Client: files,
|
||||
Version: version,
|
||||
Logger: logger,
|
||||
OpenURL: func(u string) error { return app.Browser.OpenURL(u) },
|
||||
Notify: d.notify,
|
||||
SetTitle: d.setTitle,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -81,6 +85,8 @@ func run() error {
|
||||
Icon: icon,
|
||||
Logger: logger,
|
||||
Assets: application.AssetOptions{Handler: sh},
|
||||
Services: d.services(),
|
||||
ShouldQuit: d.shouldQuit,
|
||||
// The client's sessions and encryption keys are in the webview's
|
||||
// storage; two instances on one store would both sync and both
|
||||
// use the same one-time keys.
|
||||
@@ -113,12 +119,18 @@ func run() error {
|
||||
URL: "/",
|
||||
})
|
||||
|
||||
app.Menu.SetApplicationMenu(appMenu(app, window))
|
||||
d.attach(app, window, icon)
|
||||
updates := setupUpdates(app, logger)
|
||||
if updates {
|
||||
d.onUpdate = func() { checkForUpdates(app, logger) }
|
||||
watchUpdates(app, d, logger)
|
||||
}
|
||||
app.Menu.SetApplicationMenu(appMenu(app, window, d, updates, logger))
|
||||
|
||||
return app.Run()
|
||||
}
|
||||
|
||||
func appMenu(app *application.App, window *application.WebviewWindow) *application.Menu {
|
||||
func appMenu(app *application.App, window *application.WebviewWindow, d *desktop, updates bool, logger *slog.Logger) *application.Menu {
|
||||
menu := app.NewMenu()
|
||||
if runtime.GOOS == "darwin" {
|
||||
menu.AddRole(application.AppMenu)
|
||||
@@ -131,11 +143,16 @@ func appMenu(app *application.App, window *application.WebviewWindow) *applicati
|
||||
if runtime.GOOS == "darwin" {
|
||||
file.AddRole(application.CloseWindow)
|
||||
} else {
|
||||
file.AddRole(application.Quit)
|
||||
// Closing the window keeps the app in the tray; this ends it.
|
||||
file.Add("Quit").SetAccelerator("CmdOrCtrl+Q").OnClick(func(*application.Context) { d.quit() })
|
||||
}
|
||||
menu.AddRole(application.EditMenu)
|
||||
menu.AddRole(application.ViewMenu)
|
||||
menu.AddRole(application.WindowMenu)
|
||||
if updates {
|
||||
help := menu.AddSubmenu("Help")
|
||||
help.Add("Check for updates…").OnClick(func(*application.Context) { checkForUpdates(app, logger) })
|
||||
}
|
||||
return menu
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/updater"
|
||||
"github.com/wailsapp/wails/v3/pkg/updater/providers/endpoint"
|
||||
)
|
||||
|
||||
// Updates come from a Wails update manifest (the endpoint provider): one
|
||||
// JSON document listing the latest version and a binary per platform,
|
||||
// each with its SHA-256. `make desktop-manifest` writes it next to the
|
||||
// binaries; any static web server can host the lot.
|
||||
//
|
||||
// A build checks for updates only when it is told where to look, with
|
||||
// -ldflags "-X main.updateURL=https://…/warp-desktop.json -X main.appVersion=1.2.3"
|
||||
// (the Makefile's DESKTOP_UPDATE_URL and DESKTOP_VERSION). updateKey, when
|
||||
// set, is the PEM public key that release signatures must verify against;
|
||||
// without one a release is checked by its digest only.
|
||||
var (
|
||||
updateURL string
|
||||
appVersion string
|
||||
updateKey string
|
||||
)
|
||||
|
||||
// A running app checks a minute after it starts, then this often.
|
||||
const (
|
||||
updateDelay = time.Minute
|
||||
updateInterval = 6 * time.Hour
|
||||
)
|
||||
|
||||
// setupUpdates configures app.Updater; false when this build has no update
|
||||
// source, and there is nothing to check.
|
||||
func setupUpdates(app *application.App, logger *slog.Logger) bool {
|
||||
if updateURL == "" || appVersion == "" {
|
||||
return false
|
||||
}
|
||||
// A Linux package's binary is the package manager's to replace.
|
||||
if exe, err := os.Executable(); err == nil && runtime.GOOS == "linux" && strings.HasPrefix(exe, "/usr/") {
|
||||
logger.Info("updates come from the package manager", "path", exe)
|
||||
return false
|
||||
}
|
||||
p, err := endpoint.New(endpoint.Config{URL: updateURL})
|
||||
if err != nil {
|
||||
logger.Warn("updates are off", "err", err)
|
||||
return false
|
||||
}
|
||||
// No CheckInterval: the updater's own polling opens its window on every
|
||||
// check, up to date or not. watchUpdates checks quietly instead.
|
||||
cfg := updater.Config{
|
||||
CurrentVersion: appVersion,
|
||||
Providers: []updater.Provider{p},
|
||||
}
|
||||
if updateKey != "" {
|
||||
cfg.PublicKey = []byte(updateKey)
|
||||
}
|
||||
if err := app.Updater.Init(cfg); err != nil {
|
||||
logger.Warn("updates are off", "err", err)
|
||||
return false
|
||||
}
|
||||
app.Event.On(updater.EventError, func(e *application.CustomEvent) {
|
||||
logger.Warn("update", "err", e.Data)
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
// checkForUpdates is the menu's "Check for updates…": the updater's own
|
||||
// window says whether there is one and installs it.
|
||||
func checkForUpdates(app *application.App, logger *slog.Logger) {
|
||||
go func() {
|
||||
if err := app.Updater.CheckAndInstall(context.Background()); err != nil {
|
||||
logger.Warn("update", "err", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// watchUpdates checks for a newer version in the background, and says so
|
||||
// with a notification once per version; clicking it starts the install.
|
||||
func watchUpdates(app *application.App, d *desktop, logger *slog.Logger) {
|
||||
go func() {
|
||||
time.Sleep(updateDelay)
|
||||
told := ""
|
||||
for {
|
||||
rel, err := app.Updater.Check(context.Background())
|
||||
if err != nil {
|
||||
logger.Warn("can't check for updates", "err", err)
|
||||
} else if rel != nil && rel.Version != told {
|
||||
told = rel.Version
|
||||
d.notifyUpdate(rel.Version)
|
||||
}
|
||||
time.Sleep(updateInterval)
|
||||
}
|
||||
}()
|
||||
}
|
||||
Reference in new issue
Block a user