Market page - Card grid that fills the width; cards show only icon, name, publisher (trust mark by color and icon), version and the action. - Paints from cache via the new PeekPluginMarket binding, then revalidates; cards reveal 24 at a time as the feed scrolls. - Category chips come from the index (MarketBrowseResult.kinds) instead of a fixed list; the alpha toggle and source badge are gone. - Installed/Market is a segmented control; refresh now shows feedback. - WordmarkLoader writes the Reims-Go wordmark stroke by stroke while the market loads (static pulse under reduced motion). Install and enable - reims:plugin-install events drive a progress bar on the card. - After install, a dialog offers to enable the plugin and lists what it can do in plain words (PluginInfo.risks / MarketCatalogItem.risks, derived from tier, permissions and contributions in risks.go). - Enabling a plugin that provides UI languages switches to the first one unless the current language is among them (PluginInfo.locales). Trust - A package installed from the project's own index, fetched over HTTPS in this session, inherits the index's trust level when its SHA-256 matches. Third-party indexes (REIMS_GO_PLUGIN_MARKET_URL) cannot vouch and show every entry as community. - Trust no longer waives review: official packages get the same scan, high-risk approval and L3 hash check as any other; only builtin and bundled plugins are pre-approved. First launch - When the OS language is not covered by zh-CN/en-US, the folder screen looks up a matching pack once (SuggestLanguagePack) and offers to install it; Continue installs and enables it so the UI follows the OS language. Before setup the market keeps its index in memory only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/Nwflower/reims-go/internal/i18n"
|
|
)
|
|
|
|
// MarketEntryLocales returns the canonical UI language tags a locale pack
|
|
// provides. An explicit Locales list is authoritative; otherwise the tags and
|
|
// the languages its name is translated into stand in for it (an index entry
|
|
// translates its own name into the language it ships).
|
|
func MarketEntryLocales(e MarketEntry) []string {
|
|
var raw []string
|
|
if len(e.Locales) > 0 {
|
|
raw = e.Locales
|
|
} else {
|
|
raw = append(raw, e.Tags...)
|
|
for k := range e.Name.Extra {
|
|
raw = append(raw, k)
|
|
}
|
|
}
|
|
seen := map[string]bool{}
|
|
var out []string
|
|
for _, r := range raw {
|
|
canon, ok := i18n.ParseLocale(r)
|
|
if !ok || seen[string(canon)] {
|
|
continue
|
|
}
|
|
seen[string(canon)] = true
|
|
out = append(out, string(canon))
|
|
}
|
|
return out
|
|
}
|
|
|
|
// localeMatch scores how well a pack providing have serves want: 2 for the
|
|
// same tag, 1 for the same language (except Chinese, where the script
|
|
// differs between regions), 0 for no match.
|
|
func localeMatch(have, want string) int {
|
|
if strings.EqualFold(have, want) {
|
|
return 2
|
|
}
|
|
hl, wl := primaryLanguage(have), primaryLanguage(want)
|
|
if hl == wl && wl != "zh" {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func primaryLanguage(tag string) string {
|
|
tag = strings.ToLower(tag)
|
|
if i := strings.IndexByte(tag, '-'); i >= 0 {
|
|
return tag[:i]
|
|
}
|
|
return tag
|
|
}
|
|
|
|
// SuggestLocalePack finds the market language pack that best serves tag:
|
|
// installable (compatible, not withdrawn, not installed), exact language
|
|
// first, then the most trusted. It returns nil when there is none or the
|
|
// market is unreachable.
|
|
func (c *MarketClient) SuggestLocalePack(ctx context.Context, installed []PluginInfo, tag string) *MarketCatalogItem {
|
|
want, ok := i18n.ParseLocale(tag)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
res := c.Browse(ctx, installed, MarketBrowseOptions{Kind: "locale"})
|
|
var best *MarketCatalogItem
|
|
bestScore := 0
|
|
// Items arrive most-trusted first, so a tie keeps the earlier one.
|
|
for i := range res.Items {
|
|
it := res.Items[i]
|
|
if it.Installed || it.Withdrawn != nil || !it.Compatible {
|
|
continue
|
|
}
|
|
score := 0
|
|
for _, have := range MarketEntryLocales(it.Entry) {
|
|
if s := localeMatch(have, string(want)); s > score {
|
|
score = s
|
|
}
|
|
}
|
|
if score > bestScore {
|
|
cp := it
|
|
best, bestScore = &cp, score
|
|
}
|
|
}
|
|
return best
|
|
}
|