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.
This commit is contained in:
1 parent
2fb4a8ea79
commit
6c0ee61750
2538 files changed
+675779
-4792
No files matched your search
Vendored
+78
@@ -0,0 +1,78 @@
|
||||
package mygo
|
||||
|
||||
import "github.com/egoist/mygo/internal/platform"
|
||||
|
||||
// PDFOptions configures Page.PrintToPDF. The zero value prints Letter
|
||||
// pages in portrait orientation with margins of 0.4 inch and without
|
||||
// backgrounds, like a browser's print dialog.
|
||||
type PDFOptions struct {
|
||||
// PageSize is the size of the paper; the zero value is PageLetter.
|
||||
PageSize PageSize
|
||||
Landscape bool
|
||||
// Margins surround the content of every page; nil means 0.4 inch on
|
||||
// every side, &Margins{} none.
|
||||
Margins *Margins
|
||||
// Background prints background colors and images, which printing
|
||||
// leaves out by default.
|
||||
Background bool
|
||||
}
|
||||
|
||||
// PageSize is the size of a sheet of paper in inches, in portrait
|
||||
// orientation.
|
||||
type PageSize struct{ Width, Height float64 }
|
||||
|
||||
// Paper sizes.
|
||||
var (
|
||||
PageLetter = PageSize{8.5, 11}
|
||||
PageLegal = PageSize{8.5, 14}
|
||||
PageTabloid = PageSize{11, 17}
|
||||
PageA3 = PageSize{11.69, 16.54}
|
||||
PageA4 = PageSize{8.27, 11.69}
|
||||
PageA5 = PageSize{5.83, 8.27}
|
||||
)
|
||||
|
||||
// Margins are page margins in inches.
|
||||
type Margins struct{ Top, Right, Bottom, Left float64 }
|
||||
|
||||
// PrintToPDF renders the page as a PDF document, laid out for printing
|
||||
// (the page's print style sheets apply) on pages of the given size:
|
||||
//
|
||||
// pdf, err := win.Page().PrintToPDF(mygo.PDFOptions{PageSize: mygo.PageA4, Background: true})
|
||||
//
|
||||
// The PDF's text copies and searches as the page's: on macOS, where the
|
||||
// PDFs WebKit prints name radicals for many Chinese characters, as ⼈
|
||||
// (U+2F08) for 人, PrintToPDF puts back the characters the fonts draw.
|
||||
func (p *Page) PrintToPDF(opts PDFOptions) ([]byte, error) {
|
||||
if p.w.content {
|
||||
return nil, errNoPage
|
||||
}
|
||||
size := opts.PageSize
|
||||
if size.Width <= 0 || size.Height <= 0 {
|
||||
size = PageLetter
|
||||
}
|
||||
m := Margins{0.4, 0.4, 0.4, 0.4}
|
||||
if opts.Margins != nil {
|
||||
m = *opts.Margins
|
||||
}
|
||||
pdfOpts := platform.PDFOptions{
|
||||
Landscape: opts.Landscape, PageWidth: size.Width, PageHeight: size.Height,
|
||||
MarginTop: m.Top, MarginRight: m.Right, MarginBottom: m.Bottom, MarginLeft: m.Left,
|
||||
Background: opts.Background,
|
||||
}
|
||||
type result struct {
|
||||
pdf []byte
|
||||
err error
|
||||
}
|
||||
ch := make(chan result, 1)
|
||||
p.w.do(func(n platform.Window) {
|
||||
n.PrintToPDF(pdfOpts, func(pdf []byte, err error) { deliver(ch, result{pdf, err}) })
|
||||
})
|
||||
if p.w.IsDestroyed() {
|
||||
return nil, errDestroyed
|
||||
}
|
||||
r := await(ch)
|
||||
if r.err != nil {
|
||||
return nil, r.err
|
||||
}
|
||||
return fixPrintedPDF(r.pdf), nil
|
||||
}
|
||||
Reference in new issue
Block a user