Switch from Asuka to MyGo, keeping the API client and the feature set: - servers: saved servers, passwordless and password login, proxy, self-signed certificates, per-server device tokens (Keystore), connect form, instance list sheet with switch/disconnect - sessions: virtualized list, search, new session, rename/archive/delete, running indicator, event stream keeps it live - chat: pushed window with system back bar, streaming Markdown via ui/markdown, reasoning and tool rows with image previews, footer menu (read aloud via a Kotlin TTS plugin, copy, fork), user message menu (copy, revert, fork), context usage ring and detail sheet, attachments (photos/files via the document picker), permissions - release builds allow plain http:// LAN servers (Go's net/http dials directly, no cleartext manifest needed) - a local fork of MyGo (third_party/mygo) lowers the Android host's minSdk to 24 (Android 7.0); Go 1.27.4 via mise Version 0.3.0.
68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
// Package push receives push notifications on phones: APNs on iOS, and Firebase
|
|
// Cloud Messaging on Android. It tells the token that the app's server sends to.
|
|
//
|
|
// iOS needs the Push Notifications capability in the app's provisioning
|
|
// profile. Android needs a Firebase project: give Configure its values, as in
|
|
// its google-services.json. Elsewhere its functions report
|
|
// errors.ErrUnsupported.
|
|
package push
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/egoist/mygo"
|
|
)
|
|
|
|
const pluginID = "push"
|
|
|
|
// Firebase is what Android's messaging needs of the app's Firebase project.
|
|
type Firebase struct {
|
|
ProjectID string `json:"projectId"`
|
|
AppID string `json:"appId"`
|
|
APIKey string `json:"apiKey"`
|
|
SenderID string `json:"senderId"`
|
|
}
|
|
|
|
// Configure sets up Firebase, on Android. Call it before Register. iOS ignores
|
|
// it.
|
|
func Configure(ctx context.Context, f Firebase) error {
|
|
return mygo.Native(pluginID).Call(ctx, "configure", f, nil)
|
|
}
|
|
|
|
// Register asks the user to allow notifications, and returns the token that
|
|
// the app's server sends them to, which may change: see OnToken. Call it off
|
|
// the main goroutine, as it waits for the user.
|
|
func Register(ctx context.Context) (string, error) {
|
|
var r struct {
|
|
Token string `json:"token"`
|
|
}
|
|
err := mygo.Native(pluginID).Call(ctx, "register", nil, &r)
|
|
return r.Token, err
|
|
}
|
|
|
|
// OnToken calls fn on the main thread as the token changes.
|
|
func OnToken(fn func(token string)) (off func()) {
|
|
return mygo.Native(pluginID).On("token", func(data []byte) {
|
|
var s string
|
|
if json.Unmarshal(data, &s) == nil {
|
|
fn(s)
|
|
}
|
|
})
|
|
}
|
|
|
|
// OnMessage calls fn on the main thread as a push arrives while the app runs,
|
|
// with what it carries, as JSON.
|
|
func OnMessage(fn func(data []byte)) (off func()) { return mygo.Native(pluginID).On("message", fn) }
|
|
|
|
// OnOpened calls fn on the main thread as the user taps a push's notification, with
|
|
// what it carries, as JSON: also the tap that launched the app, once this listens,
|
|
// so call it as the app is ready.
|
|
func OnOpened(fn func(data []byte)) (off func()) {
|
|
off = mygo.Native(pluginID).On("opened", fn)
|
|
mygo.App.WhenReady(func() {
|
|
go mygo.Native(pluginID).Call(context.Background(), "listenOpened", nil, nil)
|
|
})
|
|
return off
|
|
}
|