Files
openchamber-android-native/third_party/mygo/jumplist.go
T
OpenChamber 6c0ee61750 feat: port the client to MyGo native UI (0.3.0)
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.
2026-11-18 13:22:59 +08:00

111 lines
3.3 KiB
Go

package mygo
import (
"errors"
"slices"
"sync"
"github.com/egoist/mygo/internal/platform"
)
// JumpList controls the app's jump list on Windows, the menu of its
// taskbar button: the documents the user opened recently (see
// App.AddRecentDocument) and tasks. Use App.JumpList. Its methods do
// nothing on other platforms.
//
// Windows replaces the whole list each time the app changes a part of it,
// so the JumpList keeps every part and commits them together.
type JumpList struct {
mu sync.Mutex
tasks []JumpListTask
}
// JumpListTask is an entry of the Tasks category of the app's jump list on
// Windows. It runs a program, the app itself by default, whether the app
// is running or not.
type JumpListTask struct {
// Title is the entry's label. It is required.
Title string
// Description is the entry's tooltip.
Description string
// Path is the program to run; empty is the app's own executable.
Path string
// Args are the program's arguments, each passed as it is: MyGo quotes
// them for the command line.
Args []string
// WorkingDir is the directory the program runs in; empty is the
// system's choice.
WorkingDir string
// IconPath and IconIndex choose the icon: the file holding it and the
// zero-based index of the icon in that file. An empty IconPath uses the
// program's own icon.
IconPath string
IconIndex int
}
// SetTasks sets the Tasks category of the jump list, like Electron's
// app.setUserTasks; no tasks removes them. Windows keeps the list after the
// app quits, so apps usually set it once at startup. A task that runs the
// app is best a URL of the app's own scheme, which reaches App.OnOpenURL
// whether it starts the app or, with App.RequestSingleInstanceLock, the
// running instance gets it:
//
// mygo.App.RegisterURLScheme("myapp") // or urlSchemes in mygo.config.ts
// mygo.App.OnOpenURL(func(u string) {
// if u == "myapp://new-note" { … }
// })
// if err := mygo.App.JumpList.SetTasks([]mygo.JumpListTask{
// {Title: "New note", Args: []string{"myapp://new-note"}},
// }); err != nil { … }
func (j *JumpList) SetTasks(tasks []JumpListTask) error {
needsApp("App.JumpList.SetTasks")
for _, t := range tasks {
if t.Title == "" {
return errors.New("mygo: App.JumpList.SetTasks: every task needs a title")
}
}
tasks = slices.Clone(tasks)
for i := range tasks {
tasks[i].Args = slices.Clone(tasks[i].Args)
}
return onMainValue(func() error {
// The main thread orders the calls, and commits what the last
// one set.
j.mu.Lock()
old := j.tasks
j.tasks = tasks
list := j.snapshot()
j.mu.Unlock()
err := backend().App().SetJumpList(list)
if err != nil {
j.mu.Lock()
j.tasks = old
j.mu.Unlock()
}
return err
})
}
// Tasks returns the tasks set with SetTasks.
func (j *JumpList) Tasks() []JumpListTask {
j.mu.Lock()
defer j.mu.Unlock()
tasks := slices.Clone(j.tasks)
for i := range tasks {
tasks[i].Args = slices.Clone(tasks[i].Args)
}
return tasks
}
// snapshot is the whole list for the backend. j.mu is held.
func (j *JumpList) snapshot() platform.JumpList {
var list platform.JumpList
for _, t := range j.tasks {
list.Tasks = append(list.Tasks, platform.JumpListTask{
Title: t.Title, Description: t.Description, Path: t.Path, Args: slices.Clone(t.Args),
WorkingDir: t.WorkingDir, IconPath: t.IconPath, IconIndex: t.IconIndex,
})
}
return list
}